UserAPI role updates and UserIndicator improvement

This commit is contained in:
Michael Rogers 2023-06-01 17:24:13 -05:00
parent 01131c1d90
commit 035cb1e33b
4 changed files with 48 additions and 4 deletions

View File

@ -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

View File

@ -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';

View File

@ -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);
}
}
]

View File

@ -23,7 +23,7 @@
<template>
<div class="c-indicator icon-person c-indicator--clickable">
<span class="label c-indicator__label">
{{ `${userName}: ${role}` }}
{{ role ? `${userName}: ${role}` : userName }}
<button>Change Role</button>
</span>
</div>