Skip to content

Commit

Permalink
Refactor sider to remove deprecated jsx-style menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
jthoward64 committed Dec 10, 2024
1 parent c29c5a9 commit 2d476d4
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 251 deletions.
7 changes: 4 additions & 3 deletions packages/portal/graphql/graphql-env.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@urql/core": "^5.0.8",
"@urql/devtools": "^2.0.3",
"@wysimark/react": "^3.0.20",
"antd": "^5.22.3",
"antd": "^5.22.4",
"camelcase": "^8.0.0",
"class-validator": "^0.14.1",
"gql.tada": "^1.8.10",
Expand Down
65 changes: 31 additions & 34 deletions packages/portal/src/config/refine/authorization.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
import type { AccessControlProvider } from "@refinedev/core";
import type { AccessControlProvider, CanParams } from "@refinedev/core";
import type { Action } from "@ukdanceblue/common";

import { urqlClient } from "#config/api.ts";
import type { PortalAuthData } from "#hooks/useLoginState.ts";
import { getLoginState } from "#hooks/useLoginState.ts";

export const accessControlProvider: AccessControlProvider = {
can: ({ action, params }) => {
// eslint-disable-next-line @typescript-eslint/require-await
can: async (param) => {
const loginState = getLoginState(urqlClient);

if (loginState.isErr()) {
return Promise.resolve({ can: false });
return { can: false };
}

const ok = loginState.value.ability.can(
action === "clone"
? "create"
: action === "edit"
? "update"
: action === "show"
? "get"
: (action as Action),
params?.resource?.meta?.modelName
? {
id: params.id ? String(params.id) : undefined,
kind: params.resource.meta.modelName as "FundraisingAssignmentNode",
}
: "all"
);

console.log("Checking access control", {
authorized: ok,
action,
subject: params?.resource?.meta?.modelName
? {
id: params.id ? String(params.id) : undefined,
kind: params.resource.meta.modelName as "FundraisingAssignmentNode",
}
: "all",
params,
});

return Promise.resolve({
can: ok,
});
return {
can: canSync(param, loginState.value),
};
},
options: {
buttons: {
Expand All @@ -54,3 +28,26 @@ export const accessControlProvider: AccessControlProvider = {
},
},
};

export function canSync(
{ action, params }: CanParams,
loginState: PortalAuthData
): boolean {
const ok = loginState.ability.can(
action === "clone"
? "create"
: action === "edit"
? "update"
: action === "show"
? "get"
: (action as Action),
params?.resource?.meta?.modelName
? {
id: params.id ? String(params.id) : undefined,
kind: params.resource.meta.modelName as "FundraisingAssignmentNode",
}
: "all"
);

return ok;
}
Loading

0 comments on commit 2d476d4

Please sign in to comment.