mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
feat: add way to purge all scim groups
This commit is contained in:
parent
d9ac57052e
commit
33e139bce3
@ -11,6 +11,7 @@ import { useScimSettingsApi } from 'hooks/api/actions/useScimSettingsApi/useScim
|
||||
import { useScimSettings } from 'hooks/api/getters/useScimSettings/useScimSettings';
|
||||
import { ScimDeleteEntityDialog } from './ScimDeleteUsersDialog';
|
||||
import useAdminUsersApi from 'hooks/api/actions/useAdminUsersApi/useAdminUsersApi';
|
||||
import { useGroupApi } from 'hooks/api/actions/useGroupApi/useGroupApi';
|
||||
|
||||
const StyledContainer = styled('div')(({ theme }) => ({
|
||||
padding: theme.spacing(3),
|
||||
@ -32,6 +33,7 @@ export const ScimSettings = () => {
|
||||
const [tokenDialog, setTokenDialog] = useState(false);
|
||||
const { settings, refetch } = useScimSettings();
|
||||
const { deleteScimUsers } = useAdminUsersApi();
|
||||
const { deleteScimGroups } = useGroupApi();
|
||||
const [enabled, setEnabled] = useState(settings.enabled ?? true);
|
||||
|
||||
useEffect(() => {
|
||||
@ -46,7 +48,17 @@ export const ScimSettings = () => {
|
||||
};
|
||||
|
||||
const onDeleteScimGroups = async () => {
|
||||
setDeleteGroupsDialog(true);
|
||||
try {
|
||||
await deleteScimGroups();
|
||||
setToastData({
|
||||
text: 'Scim Groups have been deleted',
|
||||
type: 'success',
|
||||
});
|
||||
setDeleteGroupsDialog(false);
|
||||
refetch();
|
||||
} catch (error: unknown) {
|
||||
setToastApiError(formatUnknownError(error));
|
||||
}
|
||||
};
|
||||
|
||||
const onDeleteScimUsers = async () => {
|
||||
@ -203,7 +215,9 @@ export const ScimSettings = () => {
|
||||
variant='outlined'
|
||||
color='error'
|
||||
disabled={loading}
|
||||
onClick={onDeleteScimGroups}
|
||||
onClick={() => {
|
||||
setDeleteGroupsDialog(true);
|
||||
}}
|
||||
>
|
||||
Delete Groups
|
||||
</Button>
|
||||
@ -226,14 +240,14 @@ export const ScimSettings = () => {
|
||||
closeDialog={() => setDeleteUsersDialog(false)}
|
||||
deleteEntities={onDeleteScimUsers}
|
||||
entityType='Users'
|
||||
></ScimDeleteEntityDialog>
|
||||
/>
|
||||
|
||||
<ScimDeleteEntityDialog
|
||||
open={deleteGroupsDialog}
|
||||
closeDialog={() => setDeleteGroupsDialog(false)}
|
||||
deleteEntities={onDeleteScimGroups}
|
||||
entityType='Groups'
|
||||
></ScimDeleteEntityDialog>
|
||||
/>
|
||||
</StyledContainer>
|
||||
</>
|
||||
);
|
||||
|
@ -46,10 +46,20 @@ export const useGroupApi = () => {
|
||||
await makeRequest(req.caller, req.id);
|
||||
};
|
||||
|
||||
const deleteScimGroups = async () => {
|
||||
const path = `api/admin/groups/scim-groups`;
|
||||
const req = createRequest(path, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
await makeRequest(req.caller, req.id);
|
||||
};
|
||||
|
||||
return {
|
||||
createGroup,
|
||||
updateGroup,
|
||||
removeGroup,
|
||||
deleteScimGroups,
|
||||
errors,
|
||||
loading,
|
||||
};
|
||||
|
@ -354,4 +354,8 @@ export default class GroupStore implements IGroupStore {
|
||||
const { present } = result.rows[0];
|
||||
return present;
|
||||
}
|
||||
|
||||
async deleteScimGroups(): Promise<void> {
|
||||
await this.db(T.GROUPS).whereNotNull('scim_id').del();
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import {
|
||||
GROUP_CREATED,
|
||||
GroupUserAdded,
|
||||
GroupUserRemoved,
|
||||
ScimGroupsDeleted,
|
||||
type IBaseEvent,
|
||||
} from '../types/events';
|
||||
import NameExistsError from '../error/name-exists-error';
|
||||
@ -310,6 +311,16 @@ export class GroupService {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteScimGroups(auditUser: IAuditUser): Promise<void> {
|
||||
await this.groupStore.deleteScimGroups();
|
||||
await this.eventService.storeEvent(
|
||||
new ScimGroupsDeleted({
|
||||
data: null,
|
||||
auditUser,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private mapGroupWithUsers(
|
||||
group: IGroup,
|
||||
allGroupUsers: IGroupUser[],
|
||||
|
@ -66,4 +66,6 @@ export interface IGroupStore extends Store<IGroup, number> {
|
||||
create(group: IStoreGroup): Promise<IGroup>;
|
||||
|
||||
count(): Promise<number>;
|
||||
|
||||
deleteScimGroups(): Promise<void>;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user