MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / buildAbility

Function buildAbility

apps/ui/src/lib/acl/ability.ts:16–62  ·  view source on GitHub ↗
(
  role: Role,
  accountId: string,
  features: IResolvedFeatures
)

Source from the content-addressed store, hash-verified

14 * its own `requireAbility(...)` from server-side state.
15 */
16export function buildAbility(
17 role: Role,
18 accountId: string,
19 features: IResolvedFeatures
20): AppAbility {
21 const { can, cannot, build } = new AbilityBuilder<AppAbility>(
22 createMongoAbility
23 );
24
25 switch (role) {
26 case ROLE.owner:
27 can("manage", "TeamMember", { accountId });
28 can("manage", "Site", { accountId });
29 can("manage", "Account", { id: accountId });
30 break;
31 case ROLE.admin:
32 can("manage", "TeamMember", { accountId });
33 can("manage", "Site", { accountId });
34 can("read", "Account", { id: accountId });
35 break;
36 case ROLE.member:
37 can("read", "TeamMember", { accountId });
38 can("read", "Account", { id: accountId });
39 can("create", "Site", { accountId });
40 can("read", "Site", { accountId });
41 can("update", "Site", { accountId });
42 can("delete", "Site", { accountId });
43 break;
44 case ROLE.viewer:
45 can("read", "TeamMember", { accountId });
46 can("read", "Site", { accountId });
47 can("read", "Account", { id: accountId });
48 break;
49 default:
50 break;
51 }
52
53 if (!features.can_export) {
54 cannot("export", "Site");
55 }
56
57 if (!features.can_invite_team) {
58 cannot("invite", "TeamMember");
59 }
60
61 return build();
62}

Callers 7

useCan.test.tsxFile · 0.90
ability.test.tsFile · 0.90
Can.test.tsxFile · 0.90
renderPageFunction · 0.90
renderPageFunction · 0.90
withSeedFunction · 0.90
AbilityProviderFunction · 0.90

Calls

no outgoing calls

Tested by 2

renderPageFunction · 0.72
renderPageFunction · 0.72