* inital pbac setup * fix tests * docs intro * more docs * add comments in docs * revert pr_todo * update to use action + custom as defaults * use enums * move to change user role + multi check * add beforeEach import * docs: add PERMISSIONS.md documenting team/organization role usages Co-Authored-By: [email protected] <[email protected]> * docs: add permission string alternatives for helper functions Co-Authored-By: [email protected] <[email protected]> * feat: enhance permission registry and default role permissions Co-Authored-By: [email protected] <[email protected]> * add routers * add hooks + rsc. Also adjsuted test to use prismock * make hooks type safe + add some tests * add a permission context - trpc router to populate context * update docs * explore global and default roles member,admin,owner * fix tests * use kysley and abstract uril * tidy up * update trpc to use pbac route in endpoint + distinct on teamId * make transform util * remove role service dependancy from permission check class * checkTeamId fall back to orgId if team is parent * todos * remove manual migrations to launch softly * address feedback * move permission checks to a repo * move role service database calls to repo. improve mocks * update tests to have describe import * fix types * remove router that is not used to pass build --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
25 lines
858 B
TypeScript
25 lines
858 B
TypeScript
import { usePermissionStore } from "../store/permission-store";
|
|
import type { PermissionString } from "../types/permission-registry";
|
|
|
|
export function usePermission(teamId: number, permission: PermissionString) {
|
|
const hasPermission = usePermissionStore((state) => state.hasPermission(teamId, permission));
|
|
const teamPermissions = usePermissionStore((state) => state.teamPermissions);
|
|
const isLoading = !teamPermissions.has(teamId);
|
|
|
|
return {
|
|
hasPermission,
|
|
isLoading,
|
|
};
|
|
}
|
|
|
|
export function usePermissions(teamId: number, permissions: PermissionString[]) {
|
|
const hasPermissions = usePermissionStore((state) => state.hasPermissions(teamId, permissions));
|
|
const teamPermissions = usePermissionStore((state) => state.teamPermissions);
|
|
const isLoading = !teamPermissions.has(teamId);
|
|
|
|
return {
|
|
hasPermissions,
|
|
isLoading,
|
|
};
|
|
}
|