Merge pull request #2025 from overleaf/ta-metrics-admin

Admin Metrics

GitOrigin-RevId: 1179893b9b2148110b86caca12b057fccb04f3af
This commit is contained in:
Timothée Alby 2019-08-12 09:43:50 +02:00 committed by sharelatex
parent 67b68b0171
commit 7d1bab4e88
4 changed files with 29 additions and 2 deletions

View file

@ -122,6 +122,18 @@ module.exports = UserMembershipAuthorization = {
)
},
requireAdminMetricsStaffAccess(req, res, next) {
return requireAccessToEntity(
'admin',
'admin',
req,
res,
next,
'adminMetrics',
true
)
},
requireTemplateMetricsAccess(req, res, next) {
const templateId = req.params.id
return request(
@ -202,6 +214,12 @@ module.exports = UserMembershipAuthorization = {
res,
next
)
} else if (req.query.resource_type === 'admin') {
return UserMembershipAuthorization.requireAdminMetricsStaffAccess(
req,
res,
next
)
}
return requireAccessToEntity(
req.query.resource_type,
@ -294,6 +312,9 @@ var getEntity = function(
if (!entityConfig) {
return callback(new Errors.NotFoundError(`No such entity: ${entityName}`))
}
if (!entityConfig.modelName) {
return callback(null, { id: entityName }, entityConfig, true)
}
return UserMembershipHandler.getEntity(
entityId,

View file

@ -127,5 +127,10 @@ module.exports = {
primaryKey: 'slug',
access: 'managerIds'
}
},
admin: {
// for metrics only
modelName: null
}
}

View file

@ -28,7 +28,7 @@ module.exports = UserMembershipsHandler = {
const entityConfigs = []
for (let key in UserMembershipEntityConfigs) {
const entityConfig = UserMembershipEntityConfigs[key]
if (entityConfig.fields.write != null) {
if (entityConfig.fields && entityConfig.fields.write != null) {
entityConfigs.push(entityConfig)
}
}

View file

@ -42,7 +42,8 @@ const UserSchema = new Schema({
institutionMetrics: { type: Boolean, default: false },
institutionManagement: { type: Boolean, default: false },
groupMetrics: { type: Boolean, default: false },
groupManagement: { type: Boolean, default: false }
groupManagement: { type: Boolean, default: false },
adminMetrics: { type: Boolean, default: false }
},
signUpDate: {
type: Date,