mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
dffb6bc7a2
Add Publisher Entity for UserMemberships GitOrigin-RevId: 862b1e4fe6d33b63ddfdaef47c02809c4558f9cc
50 lines
1.9 KiB
CoffeeScript
50 lines
1.9 KiB
CoffeeScript
AuthenticationController = require('../Authentication/AuthenticationController')
|
|
AuthorizationMiddlewear = require('../Authorization/AuthorizationMiddlewear')
|
|
UserMembershipHandler = require('./UserMembershipHandler')
|
|
EntityConfigs = require('./UserMembershipEntityConfigs')
|
|
Errors = require('../Errors/Errors')
|
|
logger = require("logger-sharelatex")
|
|
|
|
module.exports =
|
|
requireTeamAccess: (req, res, next) ->
|
|
requireAccessToEntity('team', req.params.id, req, res, next)
|
|
|
|
requireGroupAccess: (req, res, next) ->
|
|
requireAccessToEntity('group', req.params.id, req, res, next)
|
|
|
|
requireGroupManagersAccess: (req, res, next) ->
|
|
requireAccessToEntity('groupManagers', req.params.id, req, res, next)
|
|
|
|
requireInstitutionAccess: (req, res, next) ->
|
|
requireAccessToEntity('institution', req.params.id, req, res, next)
|
|
|
|
requirePublisherAccess: (req, res, next) ->
|
|
requireAccessToEntity('publisher', req.params.id, req, res, next)
|
|
|
|
requireGraphAccess: (req, res, next) ->
|
|
requireAccessToEntity(
|
|
req.query.resource_type, req.query.resource_id, req, res, next
|
|
)
|
|
|
|
requireAccessToEntity = (entityName, entityId, req, res, next) ->
|
|
loggedInUser = AuthenticationController.getSessionUser(req)
|
|
unless loggedInUser
|
|
return AuthorizationMiddlewear.redirectToRestricted req, res, next
|
|
|
|
getEntity entityName, entityId, loggedInUser, (error, entity, entityConfig) ->
|
|
return next(error) if error?
|
|
unless entity?
|
|
return AuthorizationMiddlewear.redirectToRestricted(req, res, next)
|
|
|
|
req.entity = entity
|
|
req.entityConfig = entityConfig
|
|
next()
|
|
|
|
getEntity = (entityName, entityId, userId, callback = (error, entity, entityConfig)->) ->
|
|
entityConfig = EntityConfigs[entityName]
|
|
unless entityConfig
|
|
return callback(new Errors.NotFoundError("No such entity: #{entityName}"))
|
|
|
|
UserMembershipHandler.getEntity entityId, entityConfig, userId, (error, entity)->
|
|
return callback(error) if error?
|
|
callback(null, entity, entityConfig)
|