-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afad97d
commit 7773d21
Showing
10 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { GraphQLError } from 'graphql/error' | ||
|
||
const FORBIDDEN_ERROR_CODE = 'FORBIDDEN' | ||
|
||
export class ForbiddenError extends GraphQLError { | ||
constructor(message: string) { | ||
super(message, { | ||
extensions: { | ||
code: FORBIDDEN_ERROR_CODE, | ||
message, | ||
http: { | ||
status: 403, | ||
}, | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './bad-user-input' | ||
export * from './forbidden' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
import { BadUserInputError, ForbiddenError } from '@/errors/graphql-errors' | ||
import TableMetadata from '@/models/table-metadata' | ||
import User from '@/models/user' | ||
import Context from '@/types/express/context' | ||
|
@@ -93,22 +94,6 @@ describe('update table collaborators', () => { | |
expect(addedCollaborator).toHaveProperty('role', 'viewer') | ||
}) | ||
|
||
it('should not allow adding of owner role', async () => { | ||
await expect( | ||
upsertTableCollaborator( | ||
null, | ||
{ | ||
input: { | ||
tableId: dummyTable.id, | ||
email: '[email protected]', | ||
role: 'owner', | ||
}, | ||
}, | ||
context, | ||
), | ||
).rejects.toThrowError('Cannot set collaborator role as owner') | ||
}) | ||
|
||
it('should not allow editing role of owner', async () => { | ||
context.currentUser = editor | ||
await expect( | ||
|
@@ -173,6 +158,66 @@ describe('update table collaborators', () => { | |
}, | ||
context, | ||
), | ||
).rejects.toThrow('You do not have access to this tile') | ||
).rejects.toThrow(ForbiddenError) | ||
}) | ||
|
||
describe('transfer ownership', () => { | ||
it('should not allow adding of owner role if you are not owner', async () => { | ||
context.currentUser = editor | ||
await expect( | ||
upsertTableCollaborator( | ||
null, | ||
{ | ||
input: { | ||
tableId: dummyTable.id, | ||
email: '[email protected]', | ||
role: 'owner', | ||
}, | ||
}, | ||
context, | ||
), | ||
).rejects.toThrowError(ForbiddenError) | ||
}) | ||
|
||
it('should allow transfer of owner role if you are owner, old owner will become editor', async () => { | ||
await expect( | ||
upsertTableCollaborator( | ||
null, | ||
{ | ||
input: { | ||
tableId: dummyTable.id, | ||
email: editor.email, | ||
role: 'owner', | ||
}, | ||
}, | ||
context, | ||
), | ||
).resolves.not.toThrow() | ||
const collaborators = await dummyTable | ||
.$relatedQuery('collaborators') | ||
.where('table_collaborators.deleted_at', null) | ||
expect( | ||
collaborators.find((col) => col.email === editor.email), | ||
).toHaveProperty('role', 'owner') | ||
expect( | ||
collaborators.find((col) => col.email === owner.email), | ||
).toHaveProperty('role', 'editor') | ||
}) | ||
|
||
it('should not allow transfer of ownership to non-existent user', async () => { | ||
await expect( | ||
upsertTableCollaborator( | ||
null, | ||
{ | ||
input: { | ||
tableId: dummyTable.id, | ||
email: '[email protected]', | ||
role: 'owner', | ||
}, | ||
}, | ||
context, | ||
), | ||
).rejects.toThrowError(BadUserInputError) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters