MCPcopy Index your code
hub / github.com/CapSoftware/Cap / getOrganizationAccess

Function getOrganizationAccess

apps/web/actions/organization/authorization.ts:21–68  ·  view source on GitHub ↗
(
	userId: User.UserId,
	organizationId: Organisation.OrganisationId,
)

Source from the content-addressed store, hash-verified

19};
20
21export async function getOrganizationAccess(
22 userId: User.UserId,
23 organizationId: Organisation.OrganisationId,
24): Promise<OrganizationAccess | null> {
25 const [organization] = await db()
26 .select({
27 id: organizations.id,
28 ownerId: organizations.ownerId,
29 memberId: organizationMembers.id,
30 memberRole: organizationMembers.role,
31 })
32 .from(organizations)
33 .leftJoin(
34 organizationMembers,
35 and(
36 eq(organizationMembers.organizationId, organizations.id),
37 eq(organizationMembers.userId, userId),
38 ),
39 )
40 .where(
41 and(
42 eq(organizations.id, organizationId),
43 isNull(organizations.tombstoneAt),
44 or(
45 eq(organizations.ownerId, userId),
46 eq(organizationMembers.userId, userId),
47 ),
48 ),
49 )
50 .limit(1);
51
52 if (!organization) return null;
53
54 const role = getEffectiveOrganizationRole({
55 userId,
56 ownerId: organization.ownerId,
57 memberRole: organization.memberRole,
58 });
59
60 if (!role) return null;
61
62 return {
63 id: organization.id,
64 ownerId: organization.ownerId,
65 memberId: organization.memberId,
66 role,
67 };
68}
69
70export async function requireOrganizationAccess(
71 userId: User.UserId,

Callers 5

importFromLoomCsvFunction · 0.90
setFolderLogoFunction · 0.90
FolderPageFunction · 0.90

Calls 2

dbFunction · 0.90

Tested by

no test coverage detected