Skip to content

Commit

Permalink
feat: add member org admin check
Browse files Browse the repository at this point in the history
  • Loading branch information
IanFonzie committed Oct 26, 2023
1 parent 182533c commit 78d24a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
33 changes: 30 additions & 3 deletions src/back-end/lib/db/affiliation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,11 @@ export const deleteAffiliation = tryDb<[Id], Affiliation>(
}
);

export async function isUserOwnerOfOrg(
async function isUserMembershipTypeOfOrg(
connection: Connection,
user: User,
orgId: Id
orgId: Id,
membershipType: MembershipType
): Promise<boolean> {
if (!user) {
return false;
Expand All @@ -312,13 +313,39 @@ export async function isUserOwnerOfOrg(
.where({
user: user.id,
organization: orgId,
membershipType: MembershipType.Owner
membershipType
})
.first();

return !!result;
}

export async function isUserOwnerOfOrg(
connection: Connection,
user: User,
orgId: Id
): Promise<boolean> {
return await isUserMembershipTypeOfOrg(
connection,
user,
orgId,
MembershipType.Owner
);
}

export async function isUserAdminOfOrg(
connection: Connection,
user: User,
orgId: Id
): Promise<boolean> {
return await isUserMembershipTypeOfOrg(
connection,
user,
orgId,
MembershipType.Admin
);
}

export async function readActiveOwnerCount(
connection: Connection,
orgId: Id
Expand Down
4 changes: 3 additions & 1 deletion src/back-end/lib/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isSWUOpportunityAuthor,
isTWUOpportunityAuthor,
isTWUProposalAuthor,
isUserAdminOfOrg,
isUserOwnerOfOrg,
userHasAcceptedCurrentTerms,
userHasAcceptedPreviousTerms
Expand Down Expand Up @@ -171,7 +172,8 @@ export async function readOneOrganization(
}
return (
isAdmin(session) ||
(await isUserOwnerOfOrg(connection, session.user, orgId))
(await isUserOwnerOfOrg(connection, session.user, orgId)) ||
(await isUserAdminOfOrg(connection, session.user, orgId))
);
}

Expand Down

0 comments on commit 78d24a7

Please sign in to comment.