Skip to content

Commit

Permalink
CODENVY-621 fix user checking for legal on-prem usage according to li…
Browse files Browse the repository at this point in the history
…cense term

Signed-off-by: Oleksii Orel <oorel@codenvy.com>
  • Loading branch information
Oleksii Orel committed Sep 16, 2016
1 parent 20850f6 commit 4f3048e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,24 @@ export class NagMessageCtrl {
this.nagMessageService = nagMessageService;

this.userServices = codenvyPermissions.getUserServices();
this.licenseLegality = imsLicenseApi.getLicenseLegality();
this.numberOfFreeUsers = imsLicenseApi.getNumberOfFreeUsers();

this.checkLicenseStatus();
}
let licenseLegality = imsLicenseApi.getLicenseLegality();

/**
* Check the installation manager status
*/
checkLicenseStatus() {
if (this.userServices.hasInstallationManagerService) {
this.updateLicense();
return;
}
//returns an unregister function
var unregister = this.$scope.$watch(()=> {
return this.userServices.hasInstallationManagerService;
}, (isAvailable)=> {
if (!isAvailable) {
return;
}
this.updateLicense();
unregister();
this.imsLicenseApi.fetchLicenseLegality().finally(() => {
this.checkLegality(licenseLegality);
});
}

/**
* Update license's properties if installation manager is available
*/
updateLicense() {
this.checkLegality(this.licenseLegality);

this.imsLicenseApi.fetchLicenseLegality();

//returns an unregister function
this.$scope.$watch(()=> {
return this.imsLicenseApi.getLicenseLegality();
}, (newLicenseLegality)=> {
this.checkLegality(newLicenseLegality);
return licenseLegality.value;
}, ()=> {
this.checkLegality(licenseLegality);
});
}

/**
* Check the license legality
* @param licenseLegality
*/
checkLegality(licenseLegality) {
if (licenseLegality && licenseLegality.value === 'false') {
Expand Down
9 changes: 4 additions & 5 deletions dashboard/src/components/ims/ims-license.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export class ImsLicenseApi {
// default number of free users
this.numberOfFreeUsers = 5;

this.licenseLegality = {};
// default license legality
this.licenseLegality = {value: true};
}

/**
Expand Down Expand Up @@ -204,11 +205,9 @@ export class ImsLicenseApi {
let promise = this.remoteLicenseAPI.getLegality().$promise;

// check if was OK or not
promise.then((licenseLegality) => {
this.licenseLegality = licenseLegality;
return promise.then((licenseLegality) => {
this.licenseLegality.value = licenseLegality.value === true;
});

return promise;
}

/**
Expand Down

0 comments on commit 4f3048e

Please sign in to comment.