Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove logic related to 'Personal' space #275

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 8 additions & 36 deletions src/Permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
});
});
Expand Down
17 changes: 3 additions & 14 deletions src/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/PermissionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
40 changes: 1 addition & 39 deletions src/SpaceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Record<string, unknown>> {
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<string, unknown>;
}

/**
* 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<Record<string, unknown>> {
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<string, unknown>;
}

/**
* Update one space
*/
Expand Down