fix: org admin has team member privileges [CAL-2338] (#10809)
Co-authored-by: Omar López <[email protected]>
This commit is contained in:
1 parent
8995dcc82a
commit
fe8b13885c
11 files changed
+127
-63
No files matched your search
@@ -37,6 +37,7 @@ export const listOtherTeamHandler = async ({ ctx }: ListOptions) => {
|
||||
return teamsInOrgIamNotPartOf.map(({ team, ...membership }) => ({
|
||||
role: membership.role,
|
||||
accepted: membership.accepted,
|
||||
userId: membership.userId,
|
||||
isOrgAdmin: true,
|
||||
...team,
|
||||
}));
|
||||
|
||||
@@ -66,6 +66,7 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
|
||||
|
||||
const createTeam = await prisma.team.create({
|
||||
data: {
|
||||
...(isOrgChildTeam ? { slug } : {}),
|
||||
name,
|
||||
logo,
|
||||
members: {
|
||||
@@ -75,9 +76,11 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
|
||||
accepted: true,
|
||||
},
|
||||
},
|
||||
metadata: {
|
||||
requestedSlug: slug,
|
||||
},
|
||||
metadata: !isOrgChildTeam
|
||||
? {
|
||||
requestedSlug: slug,
|
||||
}
|
||||
: undefined,
|
||||
...(isOrgChildTeam && { parentId: user.organizationId }),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -15,7 +15,10 @@ type GetOptions = {
|
||||
};
|
||||
|
||||
export const getHandler = async ({ ctx, input }: GetOptions) => {
|
||||
const team = await getTeamWithMembers({ id: input.teamId, userId: ctx.user.id });
|
||||
const team = await getTeamWithMembers({
|
||||
id: input.teamId,
|
||||
userId: ctx.user.organization?.isOrgAdmin ? undefined : ctx.user.id,
|
||||
});
|
||||
|
||||
if (!team) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "Team not found." });
|
||||
|
||||
@@ -35,7 +35,12 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
|
||||
const team = await getTeamOrThrow(input.teamId, input.isOrg);
|
||||
const { autoAcceptEmailDomain, orgVerified } = getIsOrgVerified(input.isOrg, team);
|
||||
|
||||
await checkPermissions({ userId: ctx.user.id, teamId: input.teamId, isOrg: input.isOrg });
|
||||
await checkPermissions({
|
||||
userId: ctx.user.id,
|
||||
teamId:
|
||||
ctx.user.organization.id && ctx.user.organization.isOrgAdmin ? ctx.user.organization.id : input.teamId,
|
||||
isOrg: input.isOrg,
|
||||
});
|
||||
|
||||
const translation = await getTranslation(input.language ?? "en", "common");
|
||||
|
||||
|
||||
@@ -20,12 +20,15 @@ type RemoveMemberOptions = {
|
||||
|
||||
export const removeMemberHandler = async ({ ctx, input }: RemoveMemberOptions) => {
|
||||
const isAdmin = await isTeamAdmin(ctx.user.id, input.teamId);
|
||||
const isOrgAdmin = ctx.user.organizationId
|
||||
? await isTeamAdmin(ctx.user.id, ctx.user.organizationId)
|
||||
: false;
|
||||
if (!isAdmin && ctx.user.id !== input.memberId) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
// Only a team owner can remove another team owner.
|
||||
if ((await isTeamOwner(input.memberId, input.teamId)) && !(await isTeamOwner(ctx.user.id, input.teamId)))
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
|
||||
if (ctx.user.id === input.memberId && isAdmin)
|
||||
if (ctx.user.id === input.memberId && isAdmin && !isOrgAdmin)
|
||||
throw new TRPCError({
|
||||
code: "FORBIDDEN",
|
||||
message: "You can not remove yourself from a team you own.",
|
||||
|
||||
Reference in new issue
Block a user