wizard: add Administrator checkbox to users step (HMS-4903)
this commit add Administrator checkbox to users step
This commit is contained in:
parent
bdd259f758
commit
25f124077c
5 changed files with 87 additions and 1 deletions
|
|
@ -46,6 +46,8 @@ export type ComplianceType = 'openscap' | 'compliance';
|
|||
|
||||
export type UserWithAdditionalInfo = {
|
||||
[K in keyof User]-?: NonNullable<User[K]>;
|
||||
} & {
|
||||
isAdministrator: boolean;
|
||||
};
|
||||
|
||||
type UserPayload = {
|
||||
|
|
@ -63,6 +65,11 @@ type UserSshKeyPayload = {
|
|||
sshKey: string;
|
||||
};
|
||||
|
||||
type UserAdministratorPayload = {
|
||||
index: number;
|
||||
isAdministrator: boolean;
|
||||
};
|
||||
|
||||
export type wizardState = {
|
||||
env: {
|
||||
serverUrl: string;
|
||||
|
|
@ -386,6 +393,11 @@ export const selectUserSshKeyByIndex =
|
|||
return state.wizard.users[userIndex]?.ssh_key;
|
||||
};
|
||||
|
||||
export const selectUserAdministrator =
|
||||
(userIndex: number) => (state: RootState) => {
|
||||
return state.wizard.users[userIndex].isAdministrator;
|
||||
};
|
||||
|
||||
export const selectKernel = (state: RootState) => {
|
||||
return state.wizard.kernel;
|
||||
};
|
||||
|
|
@ -864,6 +876,20 @@ export const wizardSlice = createSlice({
|
|||
1
|
||||
);
|
||||
},
|
||||
setUserAdministratorByIndex: (
|
||||
state,
|
||||
action: PayloadAction<UserAdministratorPayload>
|
||||
) => {
|
||||
const { index, isAdministrator } = action.payload;
|
||||
const user = state.users[index];
|
||||
|
||||
user.isAdministrator = isAdministrator;
|
||||
if (isAdministrator) {
|
||||
user.groups.push('wheel');
|
||||
} else {
|
||||
user.groups = user.groups.filter((group) => group !== 'wheel');
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -939,5 +965,6 @@ export const {
|
|||
setUserNameByIndex,
|
||||
setUserPasswordByIndex,
|
||||
setUserSshKeyByIndex,
|
||||
setUserAdministratorByIndex,
|
||||
} = wizardSlice.actions;
|
||||
export default wizardSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue