From 1b4b8e76dedf6b1e32d9bb6777f04b8a7b3bd1c9 Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Tue, 14 May 2024 22:00:53 +0200 Subject: [PATCH] fix: cleanup/remove unnecessary parts --- js/const.js | 1 - .../cohort-definition-manager.js | 21 ++++++------ js/pages/concept-sets/conceptset-manager.js | 24 ++++++-------- js/services/AuthAPI.js | 3 -- js/services/ShareRoleCheck.js | 32 ------------------- 5 files changed, 19 insertions(+), 62 deletions(-) delete mode 100644 js/services/ShareRoleCheck.js diff --git a/js/const.js b/js/const.js index 6df92fe7b..9bb28330d 100644 --- a/js/const.js +++ b/js/const.js @@ -192,7 +192,6 @@ define([ const apiPaths = { role: (id = '') => `${config.api.url}role/${id}`, roleUsers: roleId => `${config.api.url}role/${roleId}/users`, - userRoles: userId => `${config.api.url}user/${userId}/roles`, permissions: () => `${config.api.url}permission`, rolePermissions: roleId => `${config.api.url}role/${roleId}/permissions`, relations: (roleId, relation, ids = []) => `${config.api.url}role/${roleId}/${relation}/${ids.join('+')}`, diff --git a/js/pages/cohort-definitions/cohort-definition-manager.js b/js/pages/cohort-definitions/cohort-definition-manager.js index 7ceeb8360..d8040396d 100644 --- a/js/pages/cohort-definitions/cohort-definition-manager.js +++ b/js/pages/cohort-definitions/cohort-definition-manager.js @@ -2,7 +2,6 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html', 'appConfig', 'components/cohortbuilder/CohortDefinition', 'services/CohortDefinition', - 'services/ShareRoleCheck', 'services/MomentAPI', 'services/ConceptSet', 'services/Permission', @@ -66,8 +65,7 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html', view, config, CohortDefinition, - cohortDefinitionService, - shareRoleCheck, + cohortDefinitionService, momentApi, conceptSetService, PermissionService, @@ -201,15 +199,14 @@ define(['jquery', 'knockout', 'text!./cohort-definition-manager.html', this.authApi = authApi; this.config = config; - this.enablePermissionManagement = ko.observable(false); - this.enablePermissionManagement(config.enablePermissionManagement); - - this.userCanShare = ko.observable(false); - if (config.permissionManagementRoleId === "") { - this.userCanShare(true); - } else { - this.userCanShare(authApi.isPermittedGlobalShareCohort()); - } + this.enablePermissionManagement = ko.observable(config.enablePermissionManagement); + if (config.enablePermissionManagement) { + this.userCanShare = ko.observable( + !config.limitedPermissionManagement || + authApi.isPermittedGlobalShareCohort()); + } else { + this.userCanShare = ko.observable(false); + } this.relatedSourcecodesOptions = globalConstants.relatedSourcecodesOptions; this.commonUtils = commonUtils; diff --git a/js/pages/concept-sets/conceptset-manager.js b/js/pages/concept-sets/conceptset-manager.js index 43005eace..8704fad6b 100644 --- a/js/pages/concept-sets/conceptset-manager.js +++ b/js/pages/concept-sets/conceptset-manager.js @@ -8,8 +8,7 @@ define([ './const', 'const', 'components/conceptset/utils', - 'services/Vocabulary', - 'services/ShareRoleCheck', + 'services/Vocabulary', 'services/Permission', 'services/Tags', 'components/security/access/const', @@ -56,8 +55,7 @@ define([ constants, globalConstants, utils, - vocabularyAPI, - shareRoleCheck, + vocabularyAPI, GlobalPermissionService, TagsService, { entityType }, @@ -177,17 +175,15 @@ define([ return this.currentConceptSet() && this.currentConceptSet().id > 0; }); - this.enablePermissionManagement = ko.observable(false); - this.enablePermissionManagement(config.enablePermissionManagement); - - this.userCanShare = ko.observable(false); - if (config.permissionManagementRoleId === "") { - this.userCanShare(true); - } else { - this.userCanShare(authApi.isPermittedGlobalShareCohort()); - } + this.enablePermissionManagement = ko.observable(config.enablePermissionManagement); + if (config.enablePermissionManagement) { + this.userCanShare = ko.observable( + !config.limitedPermissionManagement || + authApi.isPermittedGlobalShareCohort()); + } else { + this.userCanShare = ko.observable(false); + } - this.isSaving = ko.observable(false); this.isDeleting = ko.observable(false); this.isOptimizing = ko.observable(false); diff --git a/js/services/AuthAPI.js b/js/services/AuthAPI.js index 8420b0fe2..71f0e8867 100644 --- a/js/services/AuthAPI.js +++ b/js/services/AuthAPI.js @@ -62,7 +62,6 @@ define(function(require, exports) { var subject = ko.observable(); var permissions = ko.observable(); var fullName = ko.observable(); - var userId = ko.observable(); const authProvider = ko.observable(); authProvider.subscribe(provider => { @@ -83,7 +82,6 @@ define(function(require, exports) { subject(info.login); authProvider(jqXHR.getResponseHeader('x-auth-provider')); fullName(info.name ? info.name : info.login); - userId(info.id); resolve(); }, error: function (err) { @@ -568,7 +566,6 @@ define(function(require, exports) { reloginRequired: reloginRequired, subject: subject, fullName, - userId, tokenExpirationDate: tokenExpirationDate, tokenExpired: tokenExpired, authProvider: authProvider, diff --git a/js/services/ShareRoleCheck.js b/js/services/ShareRoleCheck.js deleted file mode 100644 index 1644cd5c4..000000000 --- a/js/services/ShareRoleCheck.js +++ /dev/null @@ -1,32 +0,0 @@ -define(function (require, exports) { - var $ = require('jquery'); - var constants = require('const'); - const httpService = require('services/http'); - const authApi = require('services/AuthAPI'); - - async function getUserRoles() { - return await httpService.doGet(constants.apiPaths.userRoles(authApi.userId())) - .then(({ data = [] }) => data) - .catch((er) => { - console.error('ERROR: Can\'t find user roles for: ' + authApi.userId()); - }); - }; - async function checkIfRoleCanShare(subject, permissionManagementRoleId) { - var isAbleToShare = false; - const userRoles = await getUserRoles(); - console.log("INFO: roleUsers:" + userRoles.toString()); - - userRoles.forEach((role) => { - console.log("INFO: role " + role ); - if (role.id == permissionManagementRoleId){ - isAbleToShare = true; - } - }); - console.log("INFO: isAbleToShare: " + isAbleToShare); - return isAbleToShare; - }; - - return { - checkIfRoleCanShare, - }; -});