diff --git a/src/api/user/UserAPI.js b/src/api/user/UserAPI.js index de44084379..4cf9804f55 100644 --- a/src/api/user/UserAPI.js +++ b/src/api/user/UserAPI.js @@ -27,6 +27,7 @@ import { } from './constants'; import StatusAPI from './StatusAPI'; import User from './User'; +import SessionPersistance from './SessionPersistance'; class UserAPI extends EventEmitter { /** @@ -90,6 +91,45 @@ class UserAPI extends EventEmitter { } } + getPossibleRoles() { + if (!this.hasProvider()) { + return Promise.resolve(undefined); + } else { + return this._provider.getPossibleRoles(); + } + + } + /** + * If a user provider is set, it will return the active role Id + * @returns object + */ + getActiveRole() { + if (!this.hasProvider()) { + return Promise.resolve(undefined); + } + + // get from session storage + const sessionStorageValue = SessionPersistance.getActiveRole(); + if (sessionStorageValue === 'undefined' || sessionStorageValue === undefined) { + return undefined; + } + + return sessionStorageValue; + + } + setActiveRole(role) { + SessionPersistance.setActiveRole(role); + } + + /** + * Will return if a role can provide a operator status response + * @memberof module:openmct.UserApi# + * @returns {Boolean} + */ + canProvideStatusForRole(roleId) { + return true; + } + /** * If a user provider is set, it will return the user provider's * 'isLoggedIn' method diff --git a/src/api/user/constants.js b/src/api/user/constants.js index 5b63a1d77b..b41f2403cd 100644 --- a/src/api/user/constants.js +++ b/src/api/user/constants.js @@ -24,3 +24,4 @@ export const MULTIPLE_PROVIDER_ERROR = 'Only one user provider may be set at a t export const NO_PROVIDER_ERROR = 'No user provider has been set.'; export const SESSION_STORAGE_KEY = 'USER_ROLE'; +export const BROADCAST_CHANNEL_NAME = 'USER_ROLE'; diff --git a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue index 5c0a7d99a5..e125b2dfb0 100644 --- a/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue +++ b/src/plugins/operatorStatus/operatorStatus/OperatorStatus.vue @@ -73,7 +73,7 @@ export default { }, data() { return { - allRoles: [{ key: 'FLIGHT', name: 'Flight'}, {key: 'CAPCOM', name: 'CAPCOM'}, { key: 'GUIDO', name: 'GUIDO' }], + allRoles: [], role: '--', selectedRole: '', pollQuestionUpdated: '--', @@ -117,12 +117,14 @@ export default { // trigger role selection modal this.promptForRoleSelection(); } + // todo confirm status role this.role = await this.openmct.user.status.getStatusRoleForCurrentUser(); }, promptForRoleSelection() { - const selectionOptions = this.allRoles; + const allRoles = this.openmct.user.getPossibleRoles(); + const selectionOptions = allRoles.filter(this.openmct.user.canProvideStatusForRole); const dialog = this.openmct.overlays.selection({ selectionOptions, iconClass: 'info', @@ -138,8 +140,9 @@ export default { label: 'Select', emphasis: true, callback: () => { - this.setRole(this.selectedRole); dialog.dismiss(); + //TODO: introduce a notification of success + this.setRole(this.selectedRole); } } ] diff --git a/src/plugins/userIndicator/components/UserIndicator.vue b/src/plugins/userIndicator/components/UserIndicator.vue index 796e666442..45f5940c9d 100644 --- a/src/plugins/userIndicator/components/UserIndicator.vue +++ b/src/plugins/userIndicator/components/UserIndicator.vue @@ -23,7 +23,7 @@