Skip to content

Commit

Permalink
refactor: role param name
Browse files Browse the repository at this point in the history
  • Loading branch information
wflore19 committed Oct 3, 2024
1 parent 03a18b0 commit b232b6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/admin-dashboard/app/routes/_dashboard.admins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
row.id !== admin.id &&
doesAdminHavePermission({
minimumRole: row.role as AdminRole,
role: admin.role as AdminRole,
actorsRole: admin.role as AdminRole,
}),

isDeleted: !!deletedAt,
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-dashboard/app/shared/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function getAuthenticationStatus(

const hasPermission = doesAdminHavePermission({
minimumRole: options.minimumRole || 'admin',
role: admin.role as AdminRole,
actorsRole: admin.role as AdminRole,
});

if (!hasPermission) {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/modules/admin/admin.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function addAdmin({

const hasPermission = doesAdminHavePermission({
minimumRole: role,
role: actingAdmin.role as AdminRole,
actorsRole: actingAdmin.role as AdminRole,
});

if (!hasPermission) {
Expand Down Expand Up @@ -199,7 +199,7 @@ export async function removeAdmin({

const hasPermission = doesAdminHavePermission({
minimumRole: adminToRemove.role as AdminRole,
role: actingAdmin.role as AdminRole,
actorsRole: actingAdmin.role as AdminRole,
});

if (!hasPermission) {
Expand All @@ -222,15 +222,15 @@ export async function removeAdmin({

type DoesAdminHavePermissionInput = {
minimumRole: AdminRole;
role: AdminRole;
actorsRole: AdminRole;
};

/**
* Returns whether or not the given admin has the required role to perform the
* action.
*
* @param minimumRole - The minimum role required to perform the action.
* @param role - The role of the acting admin.
* @param actorsRole - The role of the acting admin.
*
* @example
* ```ts
Expand Down Expand Up @@ -261,12 +261,12 @@ type DoesAdminHavePermissionInput = {
*/
export function doesAdminHavePermission({
minimumRole,
role,
actorsRole,
}: DoesAdminHavePermissionInput) {
const roles = [AdminRole.AMBASSADOR, AdminRole.ADMIN, AdminRole.OWNER];

const minimumRoleIndex = roles.indexOf(minimumRole);
const roleIndex = roles.indexOf(role);
const roleIndex = roles.indexOf(actorsRole);

return roleIndex >= minimumRoleIndex;
}

0 comments on commit b232b6e

Please sign in to comment.