-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Booster service should be restricted for Project Owners #45
- Loading branch information
1 parent
e6f6319
commit 33e3b6e
Showing
6 changed files
with
71 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const subscriptionKey = 'enonic.platform.subscription'; | ||
const licenseLib = require('/lib/license'); | ||
const authLib = require('/lib/xp/auth'); | ||
|
||
const allowedRoles = ['role:system.admin', 'role:cms.admin']; | ||
|
||
const getProjectOwnerRole = (project) => project ? `role:cms.project.${project}.owner` : null; | ||
|
||
exports.hasAllowedRole = (project) => { | ||
let hasAllowedRole = false; | ||
allowedRoles.concat(getProjectOwnerRole(project)).forEach(role => { | ||
if (authLib.hasRole(role)) { | ||
log.info('Current user has role: ' + role); | ||
hasAllowedRole = true; | ||
} | ||
}); | ||
return hasAllowedRole; | ||
} | ||
|
||
const getLicenseDetails = (license) => { | ||
const params = { | ||
appKey: subscriptionKey, | ||
}; | ||
if (license) { | ||
params.license = license; | ||
} | ||
|
||
return licenseLib.validateLicense(params); | ||
} | ||
|
||
const isLicenseValid = (license) => { | ||
const licenseDetails = license ? getLicenseDetails(license) : getLicenseDetails(); | ||
|
||
return licenseDetails && !licenseDetails.expired; | ||
} | ||
|
||
exports.isLicenseValid = isLicenseValid; | ||
|
||
exports.installLicense = (license) => { | ||
if (!isLicenseValid(license)) { | ||
return false; | ||
} | ||
|
||
licenseLib.installLicense({ | ||
license: license, | ||
appKey: subscriptionKey, | ||
}); | ||
|
||
return true; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters