Updates to status api canPRovideStatusForRole

This commit is contained in:
Michael Rogers 2023-06-14 11:00:01 -05:00
parent 20101911d3
commit 78d686607e
5 changed files with 32 additions and 14 deletions

View File

@ -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();

View File

@ -151,11 +151,16 @@ export default class StatusAPI extends EventEmitter {
* @param {Status} status The status to set for the provided role
* @returns {Promise<Boolean>} 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");
}

View File

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

View File

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

View File

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