Skip to content
Snippets Groups Projects
Commit 6a4be16a authored by Jure's avatar Jure
Browse files

feat(model-team): use authorization helpers available from context

parent 74c665b6
No related branches found
No related tags found
No related merge requests found
......@@ -48,14 +48,9 @@ const resolvers = {
return ctx.connectors.Team.update(id, input, ctx)
},
async addMembers(_, { id, members }, ctx) {
const {
helpers: { can, canKnowAbout },
} = require('pubsweet-server')
await can(ctx.user, 'addMembers', id)
await ctx.helpers.can(ctx.user, 'addMembers', id)
let team = await ctx.connectors.Team.model.query().findById(id)
await team.$relatedQuery('members').relate(members)
team = await ctx.connectors.Team.model
......@@ -65,22 +60,17 @@ const resolvers = {
team.members = team.members.map(member => member.id)
const outputFilter = await canKnowAbout(ctx.user, team)
const outputFilter = await ctx.helpers.canKnowAbout(ctx.user, team)
return outputFilter(team)
},
async removeMembers(_, { id, members }, ctx) {
const {
helpers: { can, canKnowAbout },
} = require('pubsweet-server')
await can(ctx.user, 'removeMembers', id)
await ctx.helpers.can(ctx.user, 'removeMembers', id)
let team = await ctx.connectors.Team.model.query().findById(id)
await team
.$relatedQuery('members')
.unrelate()
.whereIn('id', members)
.whereIn('team_members.user_id', members)
team = await ctx.connectors.Team.model
.query()
......@@ -89,7 +79,7 @@ const resolvers = {
team.members = team.members.map(member => member.id)
const outputFilter = await canKnowAbout(ctx.user, team)
const outputFilter = await ctx.helpers.canKnowAbout(ctx.user, team)
return outputFilter(team)
},
},
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment