This commit is contained in:
Jori Lallo
2018-03-04 16:53:57 -08:00
parent 06a6573feb
commit a0f58583b5
12 changed files with 136 additions and 123 deletions

View File

@@ -1,62 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`#team.addAdmin should promote a new admin 1`] = `
Object {
"data": Object {
"avatarUrl": "http://example.com/avatar.png",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": true,
"name": "User 1",
"username": "user1",
},
"ok": true,
"status": 200,
}
`;
exports[`#team.addAdmin should require admin 1`] = `
Object {
"error": "admin_required",
"message": "An admin role is required to access this resource",
"ok": false,
"status": 403,
}
`;
exports[`#team.removeAdmin should demote an admin 1`] = `
Object {
"data": Object {
"avatarUrl": "http://example.com/avatar.png",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"name": "User 1",
"username": "user1",
},
"ok": true,
"status": 200,
}
`;
exports[`#team.removeAdmin should require admin 1`] = `
Object {
"error": "admin_required",
"message": "An admin role is required to access this resource",
"ok": false,
"status": 403,
}
`;
exports[`#team.removeAdmin shouldn't demote admins if only one available 1`] = `
Object {
"error": "validation_error",
"message": "At least one admin is required",
"ok": false,
"status": 400,
}
`;
exports[`#team.users should require admin for detailed info 1`] = `
Object {
"data": Array [
@@ -91,6 +34,7 @@ Object {
"email": "admin@example.com",
"id": "fa952cff-fa64-4d42-a6ea-6955c9689046",
"isAdmin": true,
"isSuspended": false,
"name": "Admin User",
"username": "admin",
},
@@ -99,6 +43,7 @@ Object {
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"isSuspended": false,
"name": "User 1",
"username": "user1",
},

View File

@@ -125,7 +125,7 @@ router.post('user.suspend', auth(), async ctx => {
const admin = ctx.state.user;
const userId = ctx.body.id;
const teamId = ctx.state.user.teamId;
ctx.assertPresent(userId, 'user is required');
ctx.assertPresent(userId, 'id is required');
const user = await User.findById(userId);
authorize(ctx.state.user, 'suspend', user);
@@ -152,7 +152,7 @@ router.post('user.activate', auth(), async ctx => {
const admin = ctx.state.user;
const userId = ctx.body.id;
const teamId = ctx.state.user.teamId;
ctx.assertPresent(userId, 'user is required');
ctx.assertPresent(userId, 'id is required');
const user = await User.findById(userId);
authorize(ctx.state.user, 'activate', user);

View File

@@ -72,7 +72,7 @@ describe('#user.promote', async () => {
const { admin, user } = await seed();
const res = await server.post('/api/user.promote', {
body: { token: admin.getJwtToken(), user: user.id },
body: { token: admin.getJwtToken(), id: user.id },
});
const body = await res.json();
@@ -83,7 +83,7 @@ describe('#user.promote', async () => {
it('should require admin', async () => {
const { user } = await seed();
const res = await server.post('/api/user.promote', {
body: { token: user.getJwtToken(), user: user.id },
body: { token: user.getJwtToken(), id: user.id },
});
const body = await res.json();
@@ -100,7 +100,7 @@ describe('#user.demote', async () => {
const res = await server.post('/api/user.demote', {
body: {
token: admin.getJwtToken(),
user: user.id,
id: user.id,
},
});
const body = await res.json();
@@ -115,7 +115,7 @@ describe('#user.demote', async () => {
const res = await server.post('/api/user.demote', {
body: {
token: admin.getJwtToken(),
user: admin.id,
id: admin.id,
},
});
const body = await res.json();
@@ -127,7 +127,7 @@ describe('#user.demote', async () => {
it('should require admin', async () => {
const { user } = await seed();
const res = await server.post('/api/user.promote', {
body: { token: user.getJwtToken(), user: user.id },
body: { token: user.getJwtToken(), id: user.id },
});
const body = await res.json();
@@ -143,7 +143,7 @@ describe('#user.suspend', async () => {
const res = await server.post('/api/user.suspend', {
body: {
token: admin.getJwtToken(),
user: user.id,
id: user.id,
},
});
const body = await res.json();
@@ -158,7 +158,7 @@ describe('#user.suspend', async () => {
const res = await server.post('/api/user.suspend', {
body: {
token: admin.getJwtToken(),
user: admin.id,
id: admin.id,
},
});
const body = await res.json();
@@ -170,7 +170,7 @@ describe('#user.suspend', async () => {
it('should require admin', async () => {
const { user } = await seed();
const res = await server.post('/api/user.suspend', {
body: { token: user.getJwtToken(), user: user.id },
body: { token: user.getJwtToken(), id: user.id },
});
const body = await res.json();
@@ -191,7 +191,7 @@ describe('#user.activate', async () => {
const res = await server.post('/api/user.activate', {
body: {
token: admin.getJwtToken(),
user: user.id,
id: user.id,
},
});
const body = await res.json();
@@ -203,7 +203,7 @@ describe('#user.activate', async () => {
it('should require admin', async () => {
const { user } = await seed();
const res = await server.post('/api/user.activate', {
body: { token: user.getJwtToken(), user: user.id },
body: { token: user.getJwtToken(), id: user.id },
});
const body = await res.json();

View File

@@ -29,9 +29,9 @@ export default (
user.avatarUrl || (user.slackData ? user.slackData.image_192 : null);
if (options.includeDetails) {
userData.email = user.email;
userData.isAdmin = user.isAdmin;
userData.isSuspended = user.isSuspended;
userData.email = user.email;
}
return userData;