diff --git a/src/Permissions.test.ts b/src/Permissions.test.ts index 5974fd99..56d7b4af 100644 --- a/src/Permissions.test.ts +++ b/src/Permissions.test.ts @@ -136,20 +136,6 @@ describe("PermissionsService", () => { expect(client.permission.canSpace(Actions.GetBillingPageToken, mockSpace1, ownerUser.id!)).toBeTruthy(); }); - it("can't delete Personal Space", () => { - expect(client.permission.canSpace(Actions.DeleteSpace, { - ...mockSpace1, - kind: "Personal", - }, ownerUser.id!)).toBeFalsy(); - }); - - it("can't rename Personal Space", () => { - expect(client.permission.canSpace(Actions.RenameSpace, { - ...mockSpace1, - kind: "Personal", - }, ownerUser.id!)).toBeFalsy(); - }); - it("recognizes admin privileges", () => { expect(client.permission.canSpace(Actions.DeleteSpace, mockSpace1, adminUser.id!)).toBeFalsy(); expect(client.permission.canSpace(Actions.RenameSpace, mockSpace1, adminUser.id!)).toBeTruthy(); @@ -209,13 +195,6 @@ describe("PermissionsService", () => { expect(client.permission.canTeam(TeamActions.AddUser, mockSpace1, ownerTeam, ownerUser.id ?? "")).toBeTruthy(); }); - it("can add user to Owner team of Personal Space", () => { - expect(client.permission.canTeam(TeamActions.AddUser, { - ...mockSpace1, - kind: "Personal", - }, ownerTeam, adminUser.id ?? "")).toBeFalsy(); - }); - it("admin user can't add user to owner team", () => { expect(client.permission.canTeam(TeamActions.AddUser, mockSpace1, ownerTeam, adminUser.id ?? "")).toBeFalsy(); }); @@ -237,44 +216,37 @@ describe("PermissionsService", () => { }); it("member user can't add user to normal team", () => { - expect(client.permission.canTeam(TeamActions.AddUser, mockSpace1, normalTeam, memberUser.id ?? "", memberUser.id ?? "")).toBeFalsy(); + expect(client.permission.canTeam(TeamActions.AddUser, mockSpace1, normalTeam, memberUser.id ?? "")).toBeFalsy(); }); }); describe("RemoveUser", () => { it("can remove user from team as Owner", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, ownerTeam, ownerUser.id ?? "", ownerUser.id ?? "")).toBeTruthy(); - }); - - it("can't remove itself from Owner team of Personal Space", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, { - ...mockSpace1, - kind: "Personal", - }, ownerTeam, ownerUser.id ?? "", ownerUser.id ?? "")).toBeFalsy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, ownerTeam, ownerUser.id ?? "")).toBeTruthy(); }); it("admin team can't remove user from owner team", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, ownerTeam, adminUser.id ?? "", ownerUser.id ?? "")).toBeFalsy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, ownerTeam, adminUser.id ?? "")).toBeFalsy(); }); it("admin team can remove user from admin team", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, adminTeam, adminUser.id ?? "", adminUser.id ?? "")).toBeTruthy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, adminTeam, adminUser.id ?? "")).toBeTruthy(); }); it("admin team can remove user from normal team", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, normalTeam, adminUser.id ?? "", memberUser.id ?? "")).toBeTruthy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, normalTeam, adminUser.id ?? "")).toBeTruthy(); }); it("member user can't remove user to owner team", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, ownerTeam, memberUser.id ?? "", ownerUser.id ?? "")).toBeFalsy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, ownerTeam, memberUser.id ?? "")).toBeFalsy(); }); it("member user can't remove user to admin team", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, adminTeam, memberUser.id ?? "", adminUser.id ?? "")).toBeFalsy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, adminTeam, memberUser.id ?? "")).toBeFalsy(); }); it("member user can't remove user to normal team", () => { - expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, normalTeam, memberUser.id ?? "", memberUser.id ?? "")).toBeFalsy(); + expect(client.permission.canTeam(TeamActions.RemoveUser, mockSpace1, normalTeam, memberUser.id ?? "")).toBeFalsy(); }); }); }); diff --git a/src/Permissions.ts b/src/Permissions.ts index c6805251..0e60dcac 100644 --- a/src/Permissions.ts +++ b/src/Permissions.ts @@ -70,7 +70,7 @@ export class Permissions { return role === Roles.Owner; case Actions.DeleteSpace: - return forSpace.kind !== "Personal" && role === Roles.Owner; + return role === Roles.Owner; case Actions.PatchInvitation: return this.canPatchOrRevokeInvitation(forRevokeInvitation, role); @@ -79,7 +79,7 @@ export class Permissions { return this.canPatchOrRevokeInvitation(forRevokeInvitation, role); case Actions.RenameSpace: - return forSpace.kind !== "Personal" && isAdminOrOwner; + return isAdminOrOwner; case Actions.CreateInvitation: return isAdminOrOwner; @@ -119,8 +119,7 @@ export class Permissions { * @param targetUserId - User that is the target of the exection, e.g. user to be removed * @returns */ - // eslint-disable-next-line max-params - canTeam(action: TeamActions, space: Space | SpaceEntity, team: Team | TeamEntity, forUserId: string, targetUserId?: string) { + canTeam(action: TeamActions, space: Space | SpaceEntity, team: Team | TeamEntity, forUserId: string) { const role = this.getRole(space, forUserId); const isAdminOrOwner = [Roles.Owner, Roles.Admin].includes(role); switch (action) { @@ -129,11 +128,6 @@ export class Permissions { return false; } - // Prevent adding any user to Owner team of a Personal Space - if (team.kind === "Owner" && space.kind === "Personal") { - return false; - } - if (team.kind === "Owner") { return role === Roles.Owner; } @@ -154,11 +148,6 @@ export class Permissions { return false; } - // Prevent removing creator of Personal Space from the Owner team - if (team.kind === "Owner" && space.kind === "Personal" && space.createdById === targetUserId) { - return false; - } - if (team.kind === "Owner") { return role === Roles.Owner; } diff --git a/src/PermissionsService.ts b/src/PermissionsService.ts index 353cb0de..340b5903 100644 --- a/src/PermissionsService.ts +++ b/src/PermissionsService.ts @@ -39,9 +39,8 @@ export class PermissionsService extends Base { * @param targetUserId - User that is the target of the exection, e.g. user to be removed * @returns */ - // eslint-disable-next-line max-params - canTeam(action: TeamActions, space: Space | SpaceEntity, team: Team | TeamEntity, forUserId: string, targetUserId?: string) { - return this.permissions.canTeam(action, space, team, forUserId, targetUserId); + canTeam(action: TeamActions, space: Space | SpaceEntity, team: Team | TeamEntity, forUserId: string) { + return this.permissions.canTeam(action, space, team, forUserId); } /** diff --git a/src/SpaceService.ts b/src/SpaceService.ts index 6ecbce47..3ccb6920 100644 --- a/src/SpaceService.ts +++ b/src/SpaceService.ts @@ -20,7 +20,7 @@ import { import type { MapToEntity } from "./types/types"; import type { Except } from "type-fest"; -export const spaceKinds = ["Personal", "Team"] as const; +export const spaceKinds = ["Team"] as const; export type SpaceKind = typeof spaceKinds[number]; export const spaceFeatures = ["DevCluster"] as const; @@ -133,44 +133,6 @@ class SpaceService extends Base { return (json as unknown) as CatalogAPI; } - /** - * Add feature to users' Personal Spaces. - * @param feature - Feature to add - * @param users - Array of usernames or email addresses - */ - async addSpaceFeature(feature: SpaceFeature, users: string[]): Promise> { - const { apiEndpointAddress, fetch } = this.lensPlatformClient; - const url = `${apiEndpointAddress}/spaces/features`; - - const json = await throwExpected( - async () => fetch.post(url, { feature, users }), - { - 404: () => new NotFoundException(), - }, - ); - - return (json as unknown) as Record; - } - - /** - * Remove feature from users' Personal Spaces. - * @param feature - Feature remove add - * @param users - Array of usernames or email addresses - */ - async removeSpaceFeature(feature: SpaceFeature, users: string[]): Promise> { - const { apiEndpointAddress, fetch } = this.lensPlatformClient; - const url = `${apiEndpointAddress}/spaces/features/remove`; - - const json = await throwExpected( - async () => fetch.delete(url, { data: { feature, users } }), - { - 404: () => new NotFoundException(), - }, - ); - - return (json as unknown) as Record; - } - /** * Update one space */