-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tout ce qui a trait à 'admin' concerne désormais uniquement le token.
- Loading branch information
1 parent
b716315
commit 965c551
Showing
14 changed files
with
294 additions
and
219 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
exports.up = async function (db) { | ||
const mongo = await db._run('getDbInstance', true) | ||
try { | ||
await mongo.collection('users').updateMany({}, { $unset: { admin: '' } }) | ||
} finally { | ||
await mongo.close() | ||
} | ||
} | ||
|
||
exports.down = async function (db) { | ||
const mongo = await db._run('getDbInstance', true) | ||
try { | ||
await mongo.collection('users').updateMany({}, { $set: { admin: false } }) | ||
} finally { | ||
await mongo.close() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,16 +3,20 @@ const UserModel = require('../models/user.js') | |
|
||
const user = '63977de2f83aa77c5f92cb1c' | ||
const sameUserObject = new UserModel({ _id: user }) | ||
const sameUserToken = { _id: user, email: '[email protected]', admin: false, session: true, authType: 'oidc' } | ||
const sameUserToken = { | ||
_id: user, | ||
email: '[email protected]', | ||
session: true, | ||
authType: 'oidc', | ||
} | ||
|
||
const differentUserObject = new UserModel({ _id: '00000de2f83aa77c5f92dc2f'}) | ||
const differentUserObject = new UserModel({ _id: '00000de2f83aa77c5f92dc2f' }) | ||
|
||
const adminToken = { admin: true, roles: ['read'], readonly: true } | ||
|
||
|
||
describe('isUser', () => { | ||
test('without token, no args.user', () => { | ||
expect(() => isUser({ }, { token: {} })).toThrow(/Unauthorized/) | ||
expect(() => isUser({}, { token: {} })).toThrow(/Unauthorized/) | ||
}) | ||
|
||
test('without token, explicit args.user', () => { | ||
|
@@ -28,14 +32,23 @@ describe('isUser', () => { | |
}) | ||
|
||
test('with token, implicit user is token user', () => { | ||
expect(isUser({}, { token: sameUserToken, user: sameUserObject })).toEqual({ userId: sameUserToken._id }) | ||
expect(isUser({}, { token: sameUserToken, user: sameUserObject })).toEqual({ | ||
userId: sameUserToken._id, | ||
}) | ||
}) | ||
|
||
test('with token, explicit user is same as user token', () => { | ||
expect(isUser({ user }, { token: sameUserToken, user: sameUserObject })).toEqual({ userId: user }) | ||
expect( | ||
isUser({ user }, { token: sameUserToken, user: sameUserObject }) | ||
).toEqual({ userId: user }) | ||
}) | ||
|
||
test('with token, explicit user is different than user token', () => { | ||
expect(() => isUser({ user: differentUserObject.id }, { token: sameUserToken, user: sameUserObject })).toThrow(/Forbidden/) | ||
expect(() => | ||
isUser( | ||
{ user: differentUserObject.id }, | ||
{ token: sameUserToken, user: sameUserObject } | ||
) | ||
).toThrow(/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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,33 +9,33 @@ describe('article resolver', () => { | |
const context = { | ||
user: { | ||
email: '[email protected]', | ||
admin: false, | ||
id: userId.toString(), | ||
_id: userId._id | ||
} | ||
_id: userId._id, | ||
}, | ||
token: {}, | ||
} | ||
const article = await Article.create({ | ||
title: 'My thesis', | ||
owner: [userId], | ||
contributors: [], | ||
versions: [], | ||
tags: [] | ||
tags: [], | ||
}) | ||
await Workspace.create({ | ||
name: 'Workspace A', | ||
color: '#f4a261', | ||
members: [ | ||
{ | ||
user: new ObjectId(), | ||
role: 'editor' | ||
role: 'editor', | ||
}, | ||
{ | ||
user: new ObjectId(), | ||
role: 'translator' | ||
role: 'translator', | ||
}, | ||
{ | ||
user: userId, | ||
role: 'contributor' | ||
role: 'contributor', | ||
}, | ||
], | ||
articles: [article._id], | ||
|
@@ -47,7 +47,7 @@ describe('article resolver', () => { | |
members: [ | ||
{ | ||
user: new ObjectId(), | ||
role: 'editor' | ||
role: 'editor', | ||
}, | ||
], | ||
articles: [article._id], | ||
|
@@ -59,24 +59,31 @@ describe('article resolver', () => { | |
members: [ | ||
{ | ||
user: userId, | ||
role: 'editor' | ||
role: 'editor', | ||
}, | ||
], | ||
articles: [article._id], | ||
creator: new ObjectId(), | ||
}) | ||
let workspaces = await ArticleMutation.workspaces(article, {}, context) | ||
expect(workspaces.map(w => w.toObject())).toMatchObject([ | ||
expect(workspaces.map((w) => w.toObject())).toMatchObject([ | ||
{ name: 'Workspace A' }, | ||
// should not contain Workspace B because user is not invited in this workspace | ||
{ name: 'Workspace C' } | ||
{ name: 'Workspace C' }, | ||
]) | ||
const contextWithAdminUser = { user: { ...context.user, admin: true } } | ||
workspaces = await ArticleMutation.workspaces(article, {}, contextWithAdminUser) | ||
expect(workspaces.map(w => w.toObject())).toMatchObject([ | ||
const contextWithAdminUser = { | ||
user: { ...context.user }, | ||
token: { admin: true }, | ||
} | ||
workspaces = await ArticleMutation.workspaces( | ||
article, | ||
{}, | ||
contextWithAdminUser | ||
) | ||
expect(workspaces.map((w) => w.toObject())).toMatchObject([ | ||
{ name: 'Workspace A' }, | ||
{ name: 'Workspace B' }, // admin user can see all workspaces that includes a given article | ||
{ name: 'Workspace C' } | ||
{ name: 'Workspace C' }, | ||
]) | ||
}) | ||
}) |
Oops, something went wrong.