mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
b123f830ff
User Membership Access Refactor GitOrigin-RevId: 23e8d342bc4829450625146213ff92cb042550dd
40 lines
1.4 KiB
CoffeeScript
40 lines
1.4 KiB
CoffeeScript
AuthenticationController = require('../Authentication/AuthenticationController')
|
|
UserMembershipHandler = require('./UserMembershipHandler')
|
|
EntityConfigs = require('./UserMembershipEntityConfigs')
|
|
Errors = require('../Errors/Errors')
|
|
logger = require("logger-sharelatex")
|
|
|
|
module.exports =
|
|
index: (req, res, next)->
|
|
{ entity, entityConfig } = req
|
|
UserMembershipHandler.getUsers entity, entityConfig, (error, users)->
|
|
return next(error) if error?
|
|
entityPrimaryKey = entity[entityConfig.fields.primaryKey].toString()
|
|
res.render "user_membership/index",
|
|
users: users
|
|
groupSize: entity.membersLimit if entityConfig.hasMembersLimit
|
|
translations: entityConfig.translations
|
|
paths: entityConfig.pathsFor(entityPrimaryKey)
|
|
|
|
add: (req, res, next)->
|
|
{ entity, entityConfig } = req
|
|
email = req.body.email
|
|
return res.sendStatus 422 unless email
|
|
|
|
if entityConfig.readOnly
|
|
return next(new Errors.NotFoundError("Cannot add users to entity"))
|
|
|
|
UserMembershipHandler.addUser entity, entityConfig, email, (error, user)->
|
|
return next(error) if error?
|
|
res.json(user: user)
|
|
|
|
remove: (req, res, next)->
|
|
{ entity, entityConfig } = req
|
|
userId = req.params.userId
|
|
|
|
if entityConfig.readOnly
|
|
return next(new Errors.NotFoundError("Cannot remove users from entity"))
|
|
|
|
UserMembershipHandler.removeUser entity, entityConfig, userId, (error, user)->
|
|
return next(error) if error?
|
|
res.send()
|