diff --git a/example/exampleUser/ExampleUserProvider.js b/example/exampleUser/ExampleUserProvider.js index ed64fd07c6..cb54f81a8c 100644 --- a/example/exampleUser/ExampleUserProvider.js +++ b/example/exampleUser/ExampleUserProvider.js @@ -94,8 +94,8 @@ export default class ExampleUserProvider extends EventEmitter { return this.loginPromise; } - canProvideStatusForRole() { - return Promise.resolve(true); + canProvideStatusForRole(role) { + return this.statusRoles.includes(role); } canSetPollQuestion() { @@ -114,8 +114,12 @@ export default class ExampleUserProvider extends EventEmitter { Promise.resolve(undefined); } - return Promise.resolve(this.user.getRoles()) + return Promise.resolve(this.selectedStatusRole); } + getPossibleRoles() { + return this.user.getRoles(); + } + getStatusRoleForCurrentUser() { return Promise.resolve(this.selectedStatusRole); @@ -182,7 +186,7 @@ export default class ExampleUserProvider extends EventEmitter { // for testing purposes, this will skip the form, this wouldn't be used in // a normal authentication process if (this.autoLoginUser) { - this.user = new this.ExampleUser(id, this.autoLoginUser, ['example-role']); + this.user = new this.ExampleUser(id, this.autoLoginUser, ['test-role-1', 'test-role-2', 'test-role-3', 'test-role-4']); this.loggedIn = true; return Promise.resolve(); diff --git a/src/api/user/StatusAPI.js b/src/api/user/StatusAPI.js index 4c6f4845ed..acae0d54d1 100644 --- a/src/api/user/StatusAPI.js +++ b/src/api/user/StatusAPI.js @@ -151,11 +151,16 @@ export default class StatusAPI extends EventEmitter { * @param {Status} status The status to set for the provided role * @returns {Promise} true if operation was successful, otherwise false. */ - setStatusForRole(role, status) { + async setStatusForRole(role, status) { const provider = this.#userAPI.getProvider(); if (provider.setStatusForRole) { - return provider.setStatusForRole(role, status); + const activeRole = await provider.getActiveRole(); + if (!provider.canProvideStatusForRole(activeRole)) { + return false; + } + + return provider.setStatusForRole(activeRole, status); } else { this.#userAPI.error("User provider does not support setting role status"); } diff --git a/src/api/user/UserAPI.js b/src/api/user/UserAPI.js index 4cf9804f55..36a06b91af 100644 --- a/src/api/user/UserAPI.js +++ b/src/api/user/UserAPI.js @@ -115,7 +115,6 @@ class UserAPI extends EventEmitter { } return sessionStorageValue; - } setActiveRole(role) { SessionPersistance.setActiveRole(role); @@ -125,9 +124,15 @@ class UserAPI extends EventEmitter { * Will return if a role can provide a operator status response * @memberof module:openmct.UserApi# * @returns {Boolean} - */ - canProvideStatusForRole(roleId) { - return true; + */ + canProvideStatusForRole() { + if (!this || !this.hasProvider()) { + return Promise.resolve(undefined); + } + + const activeRole = this.getActiveRole(); + + return this._provider.canProvideStatusForRole?.(activeRole); } /** diff --git a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue index dd7ced6c22..18d9cca97d 100644 --- a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue +++ b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue @@ -155,11 +155,16 @@ export default { return this.allStatuses.find(possibleMatch => possibleMatch.key === statusKey); }, async changeStatus() { + if (!this.openmct.user.canProvideStatusForRole()) { + this.openmct.notifications.error('User role is ineligible to provide operator status') + + return; + } + if (this.selectedStatus !== undefined) { const statusObject = this.findStatusByKey(this.selectedStatus); - const result = await this.openmct.user.status.setStatusForRole(this.role, statusObject); - + const result = await this.openmct.user.status.setStatusForRole(this.selectedRole, statusObject); if (result === true) { this.openmct.notifications.info("Successfully set operator status"); } else { diff --git a/src/plugins/userIndicator/components/UserIndicator.vue b/src/plugins/userIndicator/components/UserIndicator.vue index c646450754..a4ac3f7119 100644 --- a/src/plugins/userIndicator/components/UserIndicator.vue +++ b/src/plugins/userIndicator/components/UserIndicator.vue @@ -64,11 +64,10 @@ export default { const activeRole = UserAPI.getActiveRole(); this.selectedRole = activeRole; if (!activeRole) { - // trigger role selection modal this.promptForRoleSelection(); } - // todo confirm status role + // todo confirm status role this.role = await this.openmct.user.status.getStatusRoleForCurrentUser(); },