mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-03 19:13:35 +00:00
Merge pull request #1154 from sharelatex/ta-display-institution-name
display institution name on managment and metrics pages GitOrigin-RevId: 302bffee358d9d5090877ca833584f50afc0ff7b
This commit is contained in:
parent
dd41a50377
commit
bcd7a740ec
5 changed files with 39 additions and 11 deletions
|
@ -8,16 +8,18 @@ logger = require("logger-sharelatex")
|
|||
module.exports =
|
||||
index: (req, res, next)->
|
||||
{ entity, entityConfig } = req
|
||||
UserMembershipHandler.getUsers entity, entityConfig, (error, users)->
|
||||
entity.fetchV1Data (error, entity) ->
|
||||
return next(error) if error?
|
||||
entityPrimaryKey = entity[entityConfig.fields.primaryKey].toString()
|
||||
entityName = entity[entityConfig.fields.name] if entityConfig.fields.name
|
||||
res.render "user_membership/index",
|
||||
name: entityName
|
||||
users: users
|
||||
groupSize: entity.membersLimit if entityConfig.hasMembersLimit
|
||||
translations: entityConfig.translations
|
||||
paths: entityConfig.pathsFor(entityPrimaryKey)
|
||||
UserMembershipHandler.getUsers entity, entityConfig, (error, users)->
|
||||
return next(error) if error?
|
||||
entityPrimaryKey = entity[entityConfig.fields.primaryKey].toString()
|
||||
entityName = entity[entityConfig.fields.name] if entityConfig.fields.name
|
||||
res.render "user_membership/index",
|
||||
name: entityName
|
||||
users: users
|
||||
groupSize: entity.membersLimit if entityConfig.hasMembersLimit
|
||||
translations: entityConfig.translations
|
||||
paths: entityConfig.pathsFor(entityPrimaryKey)
|
||||
|
||||
add: (req, res, next)->
|
||||
{ entity, entityConfig } = req
|
||||
|
|
|
@ -54,6 +54,7 @@ module.exports =
|
|||
read: ['managerIds']
|
||||
write: 'managerIds'
|
||||
access: 'managerIds'
|
||||
name: 'name'
|
||||
translations:
|
||||
title: 'institution_account'
|
||||
subtitle: 'managers_management'
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
mongoose = require 'mongoose'
|
||||
Schema = mongoose.Schema
|
||||
ObjectId = Schema.ObjectId
|
||||
settings = require 'settings-sharelatex'
|
||||
request = require 'request'
|
||||
|
||||
InstitutionSchema = new Schema
|
||||
v1Id: { type: Number, required: true }
|
||||
managerIds: [ type:ObjectId, ref:'User' ]
|
||||
|
||||
# fetch institution's data from v1 API. Errors are ignored
|
||||
InstitutionSchema.method 'fetchV1Data', (callback = (error, institution)->) ->
|
||||
url = "#{settings.apis.v1.url}/universities/list/#{this.v1Id}"
|
||||
request.get url, (error, response, body) =>
|
||||
try parsedBody = JSON.parse(body) catch e
|
||||
this.name = parsedBody?.name
|
||||
this.countryCode = parsedBody?.country_code
|
||||
this.departments = parsedBody?.departments
|
||||
callback(null, this)
|
||||
|
||||
mongoose.model 'Institution', InstitutionSchema
|
||||
exports.Institution = mongoose.model 'Institution'
|
||||
exports.InstitutionSchema = InstitutionSchema
|
||||
|
|
|
@ -36,6 +36,10 @@ SubscriptionSchema.statics.findAndModify = (query, update, callback)->
|
|||
this.update query, update, ->
|
||||
self.findOne query, callback
|
||||
|
||||
# Subscriptions have no v1 data to fetch
|
||||
SubscriptionSchema.method 'fetchV1Data', (callback = (error, subscription)->) ->
|
||||
callback(null, this)
|
||||
|
||||
conn = mongoose.createConnection(Settings.mongo.url, {
|
||||
server: {poolSize: Settings.mongo.poolSize || 10},
|
||||
config: {autoIndex: false}
|
||||
|
|
|
@ -18,8 +18,16 @@ describe "UserMembershipController", ->
|
|||
@req.params.id = 'mock-entity-id'
|
||||
@user = _id: 'mock-user-id'
|
||||
@newUser = _id: 'mock-new-user-id', email: 'new-user-email@foo.bar'
|
||||
@subscription = { _id: 'mock-subscription-id'}
|
||||
@institution = _id: 'mock-institution-id', v1Id: 123
|
||||
@subscription =
|
||||
_id: 'mock-subscription-id'
|
||||
fetchV1Data: (callback) => callback(null, @subscription)
|
||||
@institution =
|
||||
_id: 'mock-institution-id'
|
||||
v1Id: 123
|
||||
fetchV1Data: (callback) =>
|
||||
institution = Object.assign({}, @institution)
|
||||
institution.name = 'Test Institution Name'
|
||||
callback(null, institution)
|
||||
@users = [
|
||||
{ _id: 'mock-member-id-1', email: 'mock-email-1@foo.com' }
|
||||
{ _id: 'mock-member-id-2', email: 'mock-email-2@foo.com' }
|
||||
|
@ -79,6 +87,7 @@ describe "UserMembershipController", ->
|
|||
@req.entityConfig = EntityConfigs.institution
|
||||
@UserMembershipController.index @req, render: (viewPath, viewParams) =>
|
||||
expect(viewPath).to.equal 'user_membership/index'
|
||||
expect(viewParams.name).to.equal 'Test Institution Name'
|
||||
expect(viewParams.groupSize).to.equal undefined
|
||||
expect(viewParams.translations.title).to.equal 'institution_account'
|
||||
expect(viewParams.paths.exportMembers).to.be.undefined
|
||||
|
|
Loading…
Reference in a new issue