Pull creds into license form if available via settings

This commit is contained in:
mabashian 2019-08-29 15:15:50 -04:00 committed by Ryan Petrello
parent 900fcbf87e
commit 2474a3a2ea
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
4 changed files with 74 additions and 37 deletions

View File

@ -183,3 +183,9 @@
white-space: nowrap;
overflow: hidden;
}
.License-label {
color: @field-label;
font-weight: 400;
margin-top: 10px;
}

View File

@ -7,11 +7,10 @@
import {N_} from "../i18n";
export default
['Wait', '$state', '$scope', '$rootScope',
'ProcessErrors', 'CheckLicense', 'moment','$window',
'ConfigService', 'pendoService', 'insightsEnablementService', 'i18n', 'config',
function(Wait, $state, $scope, $rootScope, ProcessErrors, CheckLicense, moment,
$window, ConfigService, pendoService, insightsEnablementService, i18n, config) {
['Wait', '$state', '$scope', '$rootScope', 'ProcessErrors', 'CheckLicense', 'moment', 'Rest',
'$window', 'ConfigService', 'pendoService', 'insightsEnablementService', 'i18n', 'config', 'GetBasePath',
function(Wait, $state, $scope, $rootScope, ProcessErrors, CheckLicense, moment, Rest,
$window, ConfigService, pendoService, insightsEnablementService, i18n, config, GetBasePath) {
const calcDaysRemaining = function(seconds) {
// calculate the number of days remaining on the license
@ -34,11 +33,10 @@ export default
const reset = function() {
document.getElementById('License-form').reset();
$scope.rhPassword = null;
$scope.rhUsername = null;
$scope.rhCreds = {};
};
const init = function(config) {
const initVars = (config) => {
// license/license.partial.html compares fileName
$scope.fileName = N_("No file selected.");
@ -59,8 +57,29 @@ export default
pendo: true,
insights: true
};
$scope.rhCreds = {};
};
const init = (config) => {
Rest.setUrl(`${GetBasePath('settings')}system/`);
Rest.get()
.then(({data}) => {
initVars(config);
if (data.REDHAT_USERNAME && data.REDHAT_USERNAME !== "") {
$scope.rhCreds.username = data.REDHAT_USERNAME;
}
if (data.REDHAT_PASSWORD && data.REDHAT_PASSWORD !== "") {
$scope.rhCreds.password = data.REDHAT_PASSWORD;
$scope.hasPasswordFromSettings = true;
}
}).catch(() => {
initVars(config);
});
};
init(config);
$scope.getKey = function(event) {
@ -89,7 +108,7 @@ export default
// HTML5 spec doesn't provide a way to customize file input css
// So we hide the default input, show our own, and simulate clicks to the hidden input
$scope.fakeClick = function() {
if($scope.user_is_superuser && (!$scope.rhUsername || $scope.rhUsername === '') && (!$scope.rhPassword || $scope.rhPassword === '')) {
if($scope.user_is_superuser && (!$scope.rhCreds.username || $scope.rhCreds.username === '') && (!$scope.rhCreds.password || $scope.rhCreds.password === '')) {
$('#License-file').click();
}
};
@ -104,10 +123,10 @@ export default
let payload = {};
if ($scope.newLicense.file) {
payload = $scope.newLicense.file;
} else if ($scope.rhUsername && $scope.rhPassword) {
} else if ($scope.rhCreds.username && $scope.rhCreds.password) {
payload = {
rh_password: $scope.rhPassword,
rh_username: $scope.rhUsername
rh_password: $scope.rhCreds.password,
rh_username: $scope.rhCreds.username
};
}
CheckLicense.post(payload, $scope.newLicense.eula)

View File

@ -8,7 +8,7 @@
<div class="License-field--label" translate>License</div>
<div class="License-field--content">
<span class="License-greenText" ng-show='compliant'><i class="fa fa-circle License-greenText"></i><translate>Valid License</translate></span>
<span class="License-redText" ng-show='!compliant'><i class="fa fa-circle License-redText"></i><translate>Invalid License</translate></span>
<span class="License-redText" ng-show='compliant !== undefined && !compliant'><i class="fa fa-circle License-redText"></i><translate>Invalid License</translate></span>
</div>
</div>
<div class="License-field">
@ -94,7 +94,7 @@
2
</span>
<span class="License-helperText">
<translate>Choose your license file or provide your Red Hat subscription credentials, agree to the End User License Agreement, and click submit.</translate>
<translate>Choose your license file or provide your Red Hat customer credentials, agree to the End User License Agreement, and click submit.</translate>
</span>
</div>
@ -108,7 +108,7 @@
<div class="d-block w-100">
<div class="License-helperText License-licenseStepHelp" translate>Upload a license file</div>
<div class="License-filePicker">
<span class="btn btn-primary" ng-click="fakeClick()" ng-disabled="!user_is_superuser || (rhUsername && rhUsername.length > 0) || (rhPassword && rhPassword.length > 0)" translate>Browse</span>
<span class="btn btn-primary" ng-click="fakeClick()" ng-disabled="!user_is_superuser || (rhCreds.username && rhCreds.username.length > 0) || (rhCreds.password && rhCreds.password.length > 0)" translate>Browse</span>
<span class="License-fileName" ng-class="{'License-helperText' : fileName == 'No file selected.'}">{{fileName|translate}}</span>
<input id="License-file" class="form-control" type="file" file-on-change="getKey"/>
</div>
@ -121,15 +121,26 @@
</div>
<div class="License-file--right">
<div class="d-block w-100">
<div class="License-helperText License-licenseStepHelp" translate>Provide your Red Hat subscription credentials</div>
<div class="License-helperText License-licenseStepHelp" translate>Provide your Red Hat customer credentials</div>
<div>
<label class="LoginModal-label d-block" translate>USERNAME</label>
<input class="w-100" type="text" ng-model="rhUsername" ng-disabled="newLicense.file" />
<label class="License-label d-block" translate>USERNAME</label>
<input class="form-control Form-textInput" type="text" ng-model="rhCreds.username" ng-disabled="!user_is_superuser || newLicense.file" />
</div>
<div>
<label class="LoginModal-label d-block" translate>PASSWORD</label>
<input class="w-100" type="password" ng-model="rhPassword" ng-disabled="newLicense.file" />
<label class="License-label d-block" translate>PASSWORD</label>
<div class="input-group Form-mixedInputGroup" ng-if="hasPasswordFromSettings">
<span class="input-group-btn input-group-prepend">
<button aw-password-toggle id="rh_license_pass_show_input_button" class="btn btn-default show_input_button Form-passwordButton" type="button" ng-disabled="!user_is_superuser || newLicense.file" aw-tool-tip="Toggle the display of plaintext." aw-tip-placement="top">Hide</button>
</span>
<input id="rh_license_pass" class="form-control Form-textInput" type="text" ng-model="rhCreds.password" ng-disabled="!user_is_superuser || newLicense.file" />
</div>
<div class="input-group Form-mixedInputGroup" ng-if="!hasPasswordFromSettings">
<span class="input-group-btn input-group-prepend">
<button aw-password-toggle id="rh_license_pass_show_input_button" class="btn btn-default show_input_button Form-passwordButton" type="button" ng-disabled="!user_is_superuser || newLicense.file" aw-tool-tip="Toggle the display of plaintext." aw-tip-placement="top">Show</button>
</span>
<input id="rh_license_pass" class="form-control Form-textInput" type="password" ng-model="rhCreds.password" ng-disabled="!user_is_superuser || newLicense.file" />
</div>
</div>
</div>
</div>
</div>
@ -167,7 +178,7 @@
</div>
</div>
<div>
<button ng-click="submit()" class="btn btn-success pull-right" ng-disabled="(!newLicense.file && (!rhUsername || !rhPassword)) || (newLicense.file && newLicense.file.license_key == null) || newLicense.eula == null || !user_is_superuser" translate>Submit</button>
<button ng-click="submit()" class="btn btn-success pull-right" ng-disabled="(!newLicense.file && (!rhCreds.username || !rhCreds.password)) || (newLicense.file && newLicense.file.license_key == null) || newLicense.eula == null || !user_is_superuser" translate>Submit</button>
<span ng-show="success == true" class="License-greenText License-submit--success pull-right" translate>Save successful!</span>
<span ng-show="licenseError == true" class="License-redText License-submit--failure pull-right" translate>Invalid License - Save unsuccessful</span>
</div>

View File

@ -17,30 +17,31 @@ export default {
ncyBreadcrumb: {
label: N_('LICENSE')
},
onEnter: ['$state', 'ConfigService', (state, configService) => {
return configService.getConfig()
.then(config => {
if (_.get(config, 'license_info.license_type') === 'open') {
return state.go('setup');
}
});
}],
onEnter: ['$state', 'ConfigService', (state, configService) => {
return configService.getConfig()
.then(config => {
if (_.get(config, 'license_info.license_type') === 'open') {
return state.go('setup');
}
});
}],
resolve: {
features: ['CheckLicense', '$rootScope',
function(CheckLicense, $rootScope) {
if($rootScope.licenseMissing === undefined){
return CheckLicense.notify();
}
}],
}
],
config: ['ConfigService', 'CheckLicense', '$rootScope',
function(ConfigService, CheckLicense, $rootScope) {
ConfigService.delete();
return ConfigService.getConfig()
.then(function(config){
$rootScope.licenseMissing = (CheckLicense.valid(config.license_info) === false) ? true : false;
return config;
});
}]
return ConfigService.getConfig()
.then(function(config){
$rootScope.licenseMissing = (CheckLicense.valid(config.license_info) === false) ? true : false;
return config;
});
}
]
},
};