refactor: imports

This commit is contained in:
nafees nazik
2024-07-09 11:33:29 +05:30
parent efc3f2b5e5
commit 25548c2f8f
10 changed files with 22 additions and 22 deletions
@@ -2,13 +2,8 @@
import Modal from "@/components/common/push-modal";
import {
ACTIONS,
SUBJECTS,
type TActions,
type TSubjects,
} from "@/lib/rbac/constants";
import { ACTIONS, type TActions } from "@/lib/rbac/actions";
import { SUBJECTS, type TSubjects } from "@/lib/rbac/subjects";
import { api } from "@/trpc/react";
import {
type TypeZodCreateRoleMutationSchema,
+2 -1
View File
@@ -1,4 +1,5 @@
import type { TActions, TSubjects } from "@/lib/rbac/constants";
import type { TActions } from "@/lib/rbac/actions";
import type { TSubjects } from "@/lib/rbac/subjects";
import { useRoles } from "@/providers/roles-provider";
export interface useAllowedOptions {
+2 -2
View File
@@ -4,8 +4,6 @@ import {
ADMIN_PERMISSION,
ADMIN_ROLE_ID,
DEFAULT_PERMISSION,
type TActions,
type TSubjects,
} from "@/lib/rbac/constants";
import { Roles } from "@/prisma/enums";
import { checkMembership, withServerComponentSession } from "@/server/auth";
@@ -16,7 +14,9 @@ import { z } from "zod";
import { RBAC, type addPolicyOption } from ".";
import { Err, Ok, wrap } from "../error";
import { BaseError } from "../error/errors/base";
import type { TActions } from "./actions";
import { permissionSchema } from "./schema";
import type { TSubjects } from "./subjects";
export interface checkMembershipOptions {
session: Session;
+2
View File
@@ -0,0 +1,2 @@
export const ACTIONS = ["create", "read", "update", "delete", "*"] as const;
export type TActions = (typeof ACTIONS)[number];
+2 -5
View File
@@ -1,8 +1,7 @@
import type { TPermission } from "@/lib/rbac/schema";
import type { Roles } from "@/prisma/enums";
export const ACTIONS = ["create", "read", "update", "delete", "*"] as const;
export const SUBJECTS = ["billing", "members", "stakeholder", "roles"] as const;
import type { TActions } from "./actions";
import { SUBJECTS } from "./subjects";
export const ADMIN_PERMISSION = SUBJECTS.map((item) => ({
actions: ["*" as TActions],
@@ -39,6 +38,4 @@ export type RoleList = {
}
);
export type TSubjects = (typeof SUBJECTS)[number];
export type TActions = (typeof ACTIONS)[number];
type DefaultRoles = Exclude<Roles, "CUSTOM">;
+2 -1
View File
@@ -1,6 +1,7 @@
import type { TActions, TSubjects } from "@/lib/rbac/constants";
import { Ok, type Result } from "../error";
import type { TActions } from "./actions";
import type { TPermission } from "./schema";
import type { TSubjects } from "./subjects";
type Effect = "allow" | "deny";
+4 -4
View File
@@ -32,11 +32,11 @@ describe("evaluating a query", () => {
valid: true,
permissions: [
{ subject: "billing", actions: ["read", "update", "delete"] },
{ subject: "invite", actions: ["read", "update"] },
{ subject: "roles", actions: ["read", "update"] },
],
policies: {
billing: { allow: ["read", "update"] },
invite: { allow: ["read"] },
roles: { allow: ["read"] },
},
},
{
@@ -44,11 +44,11 @@ describe("evaluating a query", () => {
valid: false,
permissions: [
{ subject: "billing", actions: ["read", "update", "delete"] },
{ subject: "invite", actions: ["read", "update"] },
{ subject: "roles", actions: ["read", "update"] },
],
policies: {
billing: { allow: ["read", "update"] },
invite: { allow: ["delete"] },
roles: { allow: ["delete"] },
},
},
{
+2 -1
View File
@@ -1,5 +1,6 @@
import { ACTIONS, SUBJECTS, type TActions } from "@/lib/rbac/constants";
import { z } from "zod";
import { ACTIONS } from "./actions";
import { SUBJECTS } from "./subjects";
export const permissionSchema = z.object({
actions: z.array(z.enum(ACTIONS)),
+2
View File
@@ -0,0 +1,2 @@
export const SUBJECTS = ["billing", "members", "stakeholder", "roles"] as const;
export type TSubjects = (typeof SUBJECTS)[number];
@@ -1,5 +1,6 @@
import type { TActions, TSubjects } from "@/lib/rbac/constants";
import type { TActions } from "@/lib/rbac/actions";
import type { TPermission } from "@/lib/rbac/schema";
import type { TSubjects } from "@/lib/rbac/subjects";
import { withAccessControl } from "@/trpc/api/trpc";
import {
type TypeZodCreateRoleMutationSchema,