Use a different API method to move groups (#20820)
Closes #20615 Co-authored-by: daniel-brannon <daniel.brannon@ososlo.com>
This commit is contained in:
parent
6a92669139
commit
c026884734
4 changed files with 42 additions and 32 deletions
|
@ -81,7 +81,7 @@ class AdminClient {
|
|||
if (!parentGroup) {
|
||||
parentGroup = await this.client.groups.create({ name: group });
|
||||
} else {
|
||||
parentGroup = await this.client.groups.setOrCreateChild(
|
||||
parentGroup = await this.client.groups.createChildGroup(
|
||||
{ id: parentGroup.id },
|
||||
{ name: group }
|
||||
);
|
||||
|
|
|
@ -48,7 +48,9 @@ export const GroupsModal = ({
|
|||
} else if (rename) {
|
||||
await adminClient.groups.update({ id }, group);
|
||||
} else {
|
||||
await adminClient.groups.setOrCreateChild({ id }, group);
|
||||
await (group.id
|
||||
? adminClient.groups.updateChildGroup({ id }, group)
|
||||
: adminClient.groups.createChildGroup({ id }, group));
|
||||
}
|
||||
|
||||
refresh(rename ? group : undefined);
|
||||
|
|
|
@ -11,39 +11,15 @@ type MoveDialogProps = {
|
|||
refresh: () => void;
|
||||
};
|
||||
|
||||
const moveToRoot = async (source: GroupRepresentation) => {
|
||||
await adminClient.groups.del({ id: source.id! });
|
||||
const { id } = await adminClient.groups.create({
|
||||
...source,
|
||||
id: undefined,
|
||||
});
|
||||
if (source.subGroups) {
|
||||
await Promise.all(
|
||||
source.subGroups.map((s) =>
|
||||
adminClient.groups.setOrCreateChild(
|
||||
{ id: id! },
|
||||
{
|
||||
...s,
|
||||
id: undefined,
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
const moveToRoot = (source: GroupRepresentation) =>
|
||||
source.id
|
||||
? adminClient.groups.updateRoot(source)
|
||||
: adminClient.groups.create(source);
|
||||
|
||||
const moveToGroup = async (
|
||||
source: GroupRepresentation,
|
||||
dest: GroupRepresentation
|
||||
) => {
|
||||
try {
|
||||
await adminClient.groups.setOrCreateChild({ id: dest.id! }, source);
|
||||
} catch (error: any) {
|
||||
if (error.response) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
) => adminClient.groups.updateChildGroup({ id: dest.id! }, source);
|
||||
|
||||
export const MoveDialog = ({ source, onClose, refresh }: MoveDialogProps) => {
|
||||
const { t } = useTranslation("groups");
|
||||
|
|
|
@ -29,6 +29,10 @@ export class Groups extends Resource<{ realm?: string }> {
|
|||
returnResourceIdInLocationHeader: { field: "id" },
|
||||
});
|
||||
|
||||
public updateRoot = this.makeRequest<GroupRepresentation, void>({
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
/**
|
||||
* Single user
|
||||
*/
|
||||
|
@ -67,8 +71,8 @@ export class Groups extends Resource<{ realm?: string }> {
|
|||
/**
|
||||
* Set or create child.
|
||||
* This will just set the parent if it exists. Create it and set the parent if the group doesn’t exist.
|
||||
* @deprecated Use `createChildGroup` or `updateChildGroup` instead.
|
||||
*/
|
||||
|
||||
public setOrCreateChild = this.makeUpdateRequest<
|
||||
{ id: string },
|
||||
GroupRepresentation,
|
||||
|
@ -80,6 +84,34 @@ export class Groups extends Resource<{ realm?: string }> {
|
|||
returnResourceIdInLocationHeader: { field: "id" },
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a child group on the specified parent group. If the group already exists, then an error is returned.
|
||||
*/
|
||||
public createChildGroup = this.makeUpdateRequest<
|
||||
{ id: string },
|
||||
Omit<GroupRepresentation, "id">,
|
||||
{ id: string }
|
||||
>({
|
||||
method: "POST",
|
||||
path: "/{id}/children",
|
||||
urlParamKeys: ["id"],
|
||||
returnResourceIdInLocationHeader: { field: "id" },
|
||||
});
|
||||
|
||||
/**
|
||||
* Updates a child group on the specified parent group. If the group doesn’t exist, then an error is returned.
|
||||
* Can be used to move a group from one parent to another.
|
||||
*/
|
||||
public updateChildGroup = this.makeUpdateRequest<
|
||||
{ id: string },
|
||||
GroupRepresentation,
|
||||
void
|
||||
>({
|
||||
method: "POST",
|
||||
path: "/{id}/children",
|
||||
urlParamKeys: ["id"],
|
||||
});
|
||||
|
||||
/**
|
||||
* Members
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue