Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Sep 11, 2024
1 parent b077ab1 commit dc69c13
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 58 deletions.
1 change: 0 additions & 1 deletion apps/api/src/secret/secret.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ describe('Secret Controller Tests', () => {
}
})

expect(response.statusCode).toBe(200)
expect(response.json().count).toEqual(2)

versions = await prisma.secretVersion.findMany({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class WorkspaceMembershipController {
}

@Post(':workspaceSlug/invite-users')
@RequiredApiKeyAuthorities(Authority.ADD_USER)
@RequiredApiKeyAuthorities(Authority.ADD_USER, Authority.READ_WORKSPACE)
async addUsers(
@CurrentUser() user: User,
@Param('workspaceSlug') workspaceSlug: Workspace['slug'],
Expand All @@ -49,7 +49,7 @@ export class WorkspaceMembershipController {
}

@Delete(':workspaceSlug/remove-users')
@RequiredApiKeyAuthorities(Authority.REMOVE_USER)
@RequiredApiKeyAuthorities(Authority.REMOVE_USER, Authority.READ_WORKSPACE)
async removeUsers(
@CurrentUser() user: User,
@Param('workspaceSlug') workspaceSlug: Workspace['slug'],
Expand All @@ -63,7 +63,10 @@ export class WorkspaceMembershipController {
}

@Put(':workspaceSlug/update-member-role/:userEmail')
@RequiredApiKeyAuthorities(Authority.UPDATE_USER_ROLE)
@RequiredApiKeyAuthorities(
Authority.UPDATE_USER_ROLE,
Authority.READ_WORKSPACE
)
async updateMemberRoles(
@CurrentUser() user: User,
@Param('workspaceSlug') workspaceSlug: Workspace['slug'],
Expand Down
124 changes: 76 additions & 48 deletions apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Workspace Membership Controller Tests', () => {
let workspaceRoleService: WorkspaceRoleService

let user1: User, user2: User, user3: User
let workspace1: Workspace, workspace2: Workspace
let workspace1: Workspace
let adminRole: WorkspaceRole, memberRole: WorkspaceRole

beforeAll(async () => {
Expand Down Expand Up @@ -137,7 +137,6 @@ describe('Workspace Membership Controller Tests', () => {
})

workspace1 = createUser1.defaultWorkspace
workspace2 = createUser2.defaultWorkspace

delete createUser1.defaultWorkspace
delete createUser2.defaultWorkspace
Expand Down Expand Up @@ -288,12 +287,16 @@ describe('Workspace Membership Controller Tests', () => {

it('should not be able to transfer ownership of default workspace', async () => {
// Invite another user to the workspace
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
]
)

// Accept the invitation
await workspaceMembershipService.acceptInvitation(user2, workspace1.slug)
Expand Down Expand Up @@ -416,12 +419,16 @@ describe('Workspace Membership Controller Tests', () => {

it('should have created a INVITED_TO_WORKSPACE event', async () => {
// Invite user2 to workspace1
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: []
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: []
}
]
)

const response = await fetchEvents(
eventService,
Expand Down Expand Up @@ -517,9 +524,11 @@ describe('Workspace Membership Controller Tests', () => {
await createMembership(adminRole.id, user2.id, workspace1.id, prisma)

// Remove user2 from workspace1
await workspaceMembershipService.removeUsersFromWorkspace(user1, workspace1.slug, [
user2.email
])
await workspaceMembershipService.removeUsersFromWorkspace(
user1,
workspace1.slug,
[user2.email]
)

const response = await fetchEvents(
eventService,
Expand Down Expand Up @@ -651,12 +660,16 @@ describe('Workspace Membership Controller Tests', () => {
describe('Cancel Invitation Tests', () => {
it('should be able to cancel the invitation', async () => {
// Invite user2 to workspace1
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: []
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: []
}
]
)

const response = await app.inject({
method: 'DELETE',
Expand Down Expand Up @@ -699,12 +712,16 @@ describe('Workspace Membership Controller Tests', () => {

it('should have created a CANCELLED_INVITATION event', async () => {
// Invite user2 to workspace1
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: []
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: []
}
]
)

// Cancel the invitation
await workspaceMembershipService.cancelInvitation(
Expand Down Expand Up @@ -735,12 +752,16 @@ describe('Workspace Membership Controller Tests', () => {
describe('Decline Invitation Tests', () => {
it('should be able to decline invitation to the workspace', async () => {
// Send an invitation
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
]
)

const response = await app.inject({
method: 'DELETE',
Expand Down Expand Up @@ -783,12 +804,16 @@ describe('Workspace Membership Controller Tests', () => {

it('should have created a DECLINED_INVITATION event', async () => {
// Invite user2 to workspace1
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
]
)

// Decline the invitation
await workspaceMembershipService.declineInvitation(user2, workspace1.slug)
Expand Down Expand Up @@ -863,12 +888,16 @@ describe('Workspace Membership Controller Tests', () => {

it('should have created a ACCEPT_INVITATION event', async () => {
// Invite user2 to workspace1
await workspaceMembershipService.inviteUsersToWorkspace(user1, workspace1.slug, [
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
])
await workspaceMembershipService.inviteUsersToWorkspace(
user1,
workspace1.slug,
[
{
email: user2.email,
roleSlugs: [memberRole.slug]
}
]
)

// Accept the invitation
await workspaceMembershipService.acceptInvitation(user2, workspace1.slug)
Expand Down Expand Up @@ -1043,5 +1072,4 @@ describe('Workspace Membership Controller Tests', () => {
expect(response.statusCode).toBe(401)
})
})

})
8 changes: 2 additions & 6 deletions apps/api/src/workspace/controller/workspace.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import {
} from '@nestjs/common'
import { WorkspaceService } from '../service/workspace.service'
import { CurrentUser } from '@/decorators/user.decorator'
import { Authority, User, Workspace, WorkspaceRole } from '@prisma/client'
import {
CreateWorkspace,
} from '../dto/create.workspace/create.workspace'
import { Authority, User, Workspace } from '@prisma/client'
import { CreateWorkspace } from '../dto/create.workspace/create.workspace'
import { UpdateWorkspace } from '../dto/update.workspace/update.workspace'
import { RequiredApiKeyAuthorities } from '@/decorators/required-api-key-authorities.decorator'

Expand All @@ -37,7 +35,6 @@ export class WorkspaceController {
return this.workspaceService.updateWorkspace(user, workspaceSlug, dto)
}


@Delete(':workspaceSlug')
@RequiredApiKeyAuthorities(Authority.DELETE_WORKSPACE)
async delete(
Expand All @@ -47,7 +44,6 @@ export class WorkspaceController {
return this.workspaceService.deleteWorkspace(user, workspaceSlug)
}


@Get(':workspaceSlug')
@RequiredApiKeyAuthorities(Authority.READ_WORKSPACE)
async getWorkspace(
Expand Down

0 comments on commit dc69c13

Please sign in to comment.