Allow team managers to transfer websites to teams

This commit is contained in:
Raye Evtuch 2024-08-04 20:00:45 -05:00
parent b006747a45
commit 0988808b75
No known key found for this signature in database
GPG Key ID: 77718E52A66F54B5
3 changed files with 8 additions and 3 deletions

View File

@ -71,7 +71,7 @@ export function WebsiteTransferForm({
{result.data {result.data
.filter(({ teamUser }) => .filter(({ teamUser }) =>
teamUser.find( teamUser.find(
({ role, userId }) => role === ROLES.teamOwner && userId === user.id, ({ role, userId }) => [ ROLES.teamOwner, ROLES.teamManager ].includes(role) && userId === user.id,
), ),
) )
.map(({ id, name }) => { .map(({ id, name }) => {

View File

@ -106,7 +106,7 @@ export async function canTransferWebsiteToUser({ user }: Auth, websiteId: string
if (website.teamId && user.id === userId) { if (website.teamId && user.id === userId) {
const teamUser = await getTeamUser(website.teamId, userId); const teamUser = await getTeamUser(website.teamId, userId);
return teamUser?.role === ROLES.teamOwner; return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteTransferToUser);
} }
return false; return false;
@ -118,7 +118,7 @@ export async function canTransferWebsiteToTeam({ user }: Auth, websiteId: string
if (website.userId && website.userId === user.id) { if (website.userId && website.userId === user.id) {
const teamUser = await getTeamUser(teamId, user.id); const teamUser = await getTeamUser(teamId, user.id);
return teamUser?.role === ROLES.teamOwner; return teamUser && hasPermission(teamUser.role, PERMISSIONS.websiteTransferToTeam);
} }
return false; return false;

View File

@ -160,6 +160,8 @@ export const PERMISSIONS = {
websiteCreate: 'website:create', websiteCreate: 'website:create',
websiteUpdate: 'website:update', websiteUpdate: 'website:update',
websiteDelete: 'website:delete', websiteDelete: 'website:delete',
websiteTransferToTeam: 'website:transfer-to-team',
websiteTransferToUser: 'website:transfer-to-user',
teamCreate: 'team:create', teamCreate: 'team:create',
teamUpdate: 'team:update', teamUpdate: 'team:update',
teamDelete: 'team:delete', teamDelete: 'team:delete',
@ -180,12 +182,15 @@ export const ROLE_PERMISSIONS = {
PERMISSIONS.websiteCreate, PERMISSIONS.websiteCreate,
PERMISSIONS.websiteUpdate, PERMISSIONS.websiteUpdate,
PERMISSIONS.websiteDelete, PERMISSIONS.websiteDelete,
PERMISSIONS.websiteTransferToTeam,
PERMISSIONS.websiteTransferToUser,
], ],
[ROLES.teamManager]: [ [ROLES.teamManager]: [
PERMISSIONS.teamUpdate, PERMISSIONS.teamUpdate,
PERMISSIONS.websiteCreate, PERMISSIONS.websiteCreate,
PERMISSIONS.websiteUpdate, PERMISSIONS.websiteUpdate,
PERMISSIONS.websiteDelete, PERMISSIONS.websiteDelete,
PERMISSIONS.websiteTransferToTeam,
], ],
[ROLES.teamMember]: [ [ROLES.teamMember]: [
PERMISSIONS.websiteCreate, PERMISSIONS.websiteCreate,