Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-5891 User - error after disabling and deleting #3056

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export const AdministrationUserForm = observer<Props>(function AdministrationUse
</Container>
<Container keepSize noWrap center gap compact>
{editing && (
<AdministrationUserFormDeleteButton userId={userFormInfoPart.initialState.userId} enabled={userFormInfoPart.initialState.enabled} />
<AdministrationUserFormDeleteButton
userId={userFormInfoPart.initialState.userId}
enabled={userFormInfoPart.initialState.enabled}
disableUser={userFormInfoPart.disableUser}
/>
)}
<Button type="button" disabled={state.isDisabled} mod={['outlined']} onClick={onClose}>
{translate('ui_processing_cancel')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ import { DisableUserDialog } from './DisableUserDialog.js';
interface Props extends ButtonProps {
userId: string;
enabled: boolean;
disableUser: () => Promise<void>;
}

export const AdministrationUserFormDeleteButton: React.FC<Props> = function AdministrationUserFormDeleteButton({ userId, enabled, ...rest }) {
export const AdministrationUserFormDeleteButton: React.FC<Props> = function AdministrationUserFormDeleteButton({
userId,
enabled,
disableUser,
...rest
}) {
const translate = useTranslate();
const commonDialogService = useService(CommonDialogService);
const administrationUsersManagementService = useService(AdministrationUsersManagementService);
Expand All @@ -43,6 +49,7 @@ export const AdministrationUserFormDeleteButton: React.FC<Props> = function Admi
await commonDialogService.open(DisableUserDialog, {
userId,
onDelete: openUserDeleteDialog,
disableUser: disableUser,
});
} else {
await openUserDeleteDialog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
import { observer } from 'mobx-react-lite';

import { UsersResource } from '@cloudbeaver/core-authentication';
import {
Button,
CommonDialogBody,
Expand All @@ -18,7 +17,6 @@ import {
Fill,
s,
Text,
useResource,
useS,
useTranslate,
} from '@cloudbeaver/core-blocks';
Expand All @@ -31,17 +29,17 @@ import classes from './DisableUserDialog.module.css';
interface IPayload {
userId: string;
onDelete: () => void;
disableUser: () => Promise<void>;
}

export const DisableUserDialog: DialogComponent<IPayload> = observer(function DisableUserDialog(props) {
const translate = useTranslate();
const styles = useS(classes);
const notificationService = useService(NotificationService);
const usersResource = useResource(DisableUserDialog, UsersResource, null);

async function disableHandler() {
try {
await usersResource.resource.enableUser(props.payload.userId, false);
await props.payload.disableUser();
notificationService.logSuccess({ title: 'authentication_administration_users_disable_user_success', message: props.payload.userId });
props.resolveDialog();
} catch (exception: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
teams: [],
authRole: '',
});

this.disableUser = this.disableUser.bind(this);
}

protected override format(data: IFormState<IUserFormState>, contexts: IExecutionContextProvider<IFormState<IUserFormState>>): void | Promise<void> {
Expand Down Expand Up @@ -74,6 +76,12 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
return this.loaded;
}

async disableUser() {
await this.usersResource.enableUser(this.state.userId, false, true);
this.state.enabled = false;
this.initialState.enabled = false;
}

override get isChanged(): boolean {
if (!this.loaded) {
return false;
Expand Down
Loading