Skip to content

Commit

Permalink
Merge pull request #2873 from RayeEvtuch/website-transfer-permissions
Browse files Browse the repository at this point in the history
Allow Team Managers to transfer websites to teams
  • Loading branch information
mikecao authored Aug 5, 2024
2 parents e473381 + 0988808 commit 36663bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function WebsiteTransferForm({
{result.data
.filter(({ teamUser }) =>
teamUser.find(
({ role, userId }) => role === ROLES.teamOwner && userId === user.id,
({ role, userId }) => [ ROLES.teamOwner, ROLES.teamManager ].includes(role) && userId === user.id,
),
)
.map(({ id, name }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function canTransferWebsiteToUser({ user }: Auth, websiteId: string
if (website.teamId && user.id === userId) {
const teamUser = await getTeamUser(website.teamId, userId);

return teamUser?.role === ROLES.teamOwner;
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteTransferToUser);
}

return false;
Expand All @@ -118,7 +118,7 @@ export async function canTransferWebsiteToTeam({ user }: Auth, websiteId: string
if (website.userId && website.userId === user.id) {
const teamUser = await getTeamUser(teamId, user.id);

return teamUser?.role === ROLES.teamOwner;
return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteTransferToTeam);
}

return false;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export const PERMISSIONS = {
websiteCreate: 'website:create',
websiteUpdate: 'website:update',
websiteDelete: 'website:delete',
websiteTransferToTeam: 'website:transfer-to-team',
websiteTransferToUser: 'website:transfer-to-user',
teamCreate: 'team:create',
teamUpdate: 'team:update',
teamDelete: 'team:delete',
Expand All @@ -171,12 +173,15 @@ export const ROLE_PERMISSIONS = {
PERMISSIONS.websiteCreate,
PERMISSIONS.websiteUpdate,
PERMISSIONS.websiteDelete,
PERMISSIONS.websiteTransferToTeam,
PERMISSIONS.websiteTransferToUser,
],
[ROLES.teamManager]: [
PERMISSIONS.teamUpdate,
PERMISSIONS.websiteCreate,
PERMISSIONS.websiteUpdate,
PERMISSIONS.websiteDelete,
PERMISSIONS.websiteTransferToTeam,
],
[ROLES.teamMember]: [
PERMISSIONS.websiteCreate,
Expand Down

0 comments on commit 36663bd

Please sign in to comment.