Skip to content

chore(site): remove template ACL XService #10332

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

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Extract user remove
  • Loading branch information
BrunoQuaresma committed Oct 18, 2023
commit f972b82a1512394a8b0fbcf97e796eedfcffd5c5
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const TemplatePermissionsPage: FC<
const queryClient = useQueryClient();
const addUserMutation = useMutation(setUserRole(queryClient));
const updateUserMutation = useMutation(setUserRole(queryClient));
const removeUserMutation = useMutation(setUserRole(queryClient));

return (
<>
Expand Down Expand Up @@ -94,8 +95,13 @@ export const TemplatePermissionsPage: FC<
? updateUserMutation.variables?.userId
: undefined
}
onRemoveUser={(user) => {
send("REMOVE_USER", { user });
onRemoveUser={async (user) => {
await removeUserMutation.mutateAsync({
templateId: template.id,
userId: user.id,
role: "",
});
displaySuccess("User removed successfully!");
}}
onAddGroup={(group, role, reset) => {
send("ADD_GROUP", { group, role, onDone: reset });
Expand Down
51 changes: 1 addition & 50 deletions site/src/xServices/template/templateACLXService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { updateTemplateACL } from "api/api";
import {
TemplateACL,
TemplateGroup,
TemplateRole,
TemplateUser,
} from "api/typesGenerated";
import { TemplateACL, TemplateGroup, TemplateRole } from "api/typesGenerated";
import { displaySuccess } from "components/GlobalSnackbar/utils";
import { assign, createMachine } from "xstate";

Expand All @@ -23,7 +18,6 @@ export const templateACLMachine = createMachine(
loadTemplateACL: {
data: TemplateACL;
};
// User
// Group
addGroup: {
data: unknown;
Expand All @@ -37,10 +31,6 @@ export const templateACLMachine = createMachine(
type: "LOAD";
data: TemplateACL;
}
| {
type: "REMOVE_USER";
user: TemplateUser;
}
// Group
| {
type: "ADD_GROUP";
Expand Down Expand Up @@ -72,11 +62,6 @@ export const templateACLMachine = createMachine(
},
idle: {
on: {
// User
REMOVE_USER: {
target: "removingUser",
actions: ["removeUserFromTemplateACL"],
},
// Group
ADD_GROUP: {
target: "addingGroup",
Expand All @@ -92,16 +77,6 @@ export const templateACLMachine = createMachine(
},
},
},
// User
removingUser: {
invoke: {
src: "removeUser",
onDone: {
target: "idle",
actions: ["displayRemoveUserSuccessMessage"],
},
},
},
// Group
addingGroup: {
invoke: {
Expand Down Expand Up @@ -138,13 +113,6 @@ export const templateACLMachine = createMachine(
},
{
services: {
// User
removeUser: ({ templateId }, { user }) =>
updateTemplateACL(templateId, {
user_perms: {
[user.id]: "",
},
}),
// Group
addGroup: ({ templateId }, { group, role }) =>
updateTemplateACL(templateId, {
Expand All @@ -169,23 +137,6 @@ export const templateACLMachine = createMachine(
assignTemplateACL: assign({
templateACL: (_, { data }) => data,
}),
// User
removeUserFromTemplateACL: assign({
templateACL: ({ templateACL }, { user }) => {
if (!templateACL) {
throw new Error("Template ACL is not loaded yet");
}
return {
...templateACL,
users: templateACL.users.filter((oldTemplateUser) => {
return oldTemplateUser.id !== user.id;
}),
};
},
}),
displayRemoveUserSuccessMessage: () => {
displaySuccess("User removed successfully!");
},
// Group
assignGroupToBeAdded: assign({
groupToBeAdded: (_, { group, role }) => ({ ...group, role }),
Expand Down