Merge pull request #1172 from sharelatex/jel-portal-templates-link

Link to portal templates from project dash

GitOrigin-RevId: 303f65b9c5b85a23535479a7d06e70e75069db6c
This commit is contained in:
Jessica Lawshe 2018-12-03 12:58:26 -06:00 committed by sharelatex
parent fc069c1752
commit f02e3e604b
3 changed files with 36 additions and 7 deletions

View file

@ -32,6 +32,7 @@ crypto = require 'crypto'
{ V1ConnectionError } = require '../Errors/Errors'
Features = require('../../infrastructure/Features')
BrandVariationsHandler = require("../BrandVariations/BrandVariationsHandler")
{ getUserAffiliations } = require("../Institutions/InstitutionsAPI")
module.exports = ProjectController =
@ -198,6 +199,8 @@ module.exports = ProjectController =
return cb(error, hasPaidSubscription)
user: (cb) ->
User.findById user_id, "featureSwitches overleaf awareOfV2 features", cb
userAffiliations: (cb) ->
getUserAffiliations user_id, cb
}, (err, results)->
if err?
logger.err err:err, "error getting data for project list page"
@ -208,8 +211,10 @@ module.exports = ProjectController =
notifications = require("underscore").map results.notifications, (notification)->
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
return notification
portalTemplates = ProjectController._buildPortalTemplatesList results.userAffiliations
projects = ProjectController._buildProjectList results.projects, results.v1Projects?.projects
user = results.user
userAffiliations = results.userAffiliations
warnings = ProjectController._buildWarningsList results.v1Projects
# in v2 add notifications for matching university IPs
@ -226,7 +231,9 @@ module.exports = ProjectController =
projects: projects
tags: tags
notifications: notifications or []
portalTemplates: portalTemplates
user: user
userAffiliations: userAffiliations
hasSubscription: results.hasSubscription
isShowingV1Projects: results.v1Projects?
warnings: warnings
@ -309,7 +316,7 @@ module.exports = ProjectController =
user = results.user
subscription = results.subscription
brandVariation = results.brandVariation
daysSinceLastUpdated = (new Date() - project.lastUpdated) / 86400000
logger.log project_id:project_id, daysSinceLastUpdated:daysSinceLastUpdated, "got db results for loading editor"
@ -468,6 +475,17 @@ module.exports = ProjectController =
warnings.push "Looks like you've got a lot of V1 projects! Some of them may be hidden on V2. To view them all, use the V1 dashboard."
return warnings
_buildPortalTemplatesList: (affiliations = []) ->
portalTemplates = []
for aff in affiliations
if aff.portal && aff.portal.slug && aff.portal.templates_count && aff.portal.templates_count > 0
portalPath = if aff.institution.isUniversity then '/edu/' else '/org/'
portalTemplates.push({
name: aff.institution.name
url: Settings.siteUrl + portalPath + aff.portal.slug
})
return portalTemplates
defaultSettingsForAnonymousUser = (user_id)->
id : user_id
ace:

View file

@ -26,7 +26,19 @@
ng-click="openUploadProjectModal()"
) #{translate("upload_project")}
!= moduleIncludes("newProjectMenu", locals)
if portalTemplates.length > 0
//- portalTemplates is set in ProjectController
li.divider
li.dropdown-header #{translate("institution")} #{translate("templates")}
for portal in portalTemplates
li
a.menu-indent(href=portal.url + "#templates") #{portal.name}
if (templates)
//- templates is an express local var, via settings.templateLinks
li.divider
li.dropdown-header #{translate("templates")}
each item in templates
@ -137,5 +149,3 @@
script.
window.userHasNoSubscription = #{!!(settings.enableSubscriptions && !hasSubscription)}

View file

@ -22,7 +22,7 @@ describe "ProjectController", ->
chat:
url:"chat.com"
siteUrl: "mysite.com"
@brandVariationDetails =
@brandVariationDetails =
id: "12"
active: true
brand_name: "The journal"
@ -84,8 +84,9 @@ describe "ProjectController", ->
fire: sinon.stub()
@Features =
hasFeature: sinon.stub()
@BrandVariationsHandler =
@BrandVariationsHandler =
getBrandVariationById: sinon.stub().callsArgWith 1, null, @brandVariationDetails
@getUserAffiliations = sinon.stub().callsArgWith(1, null, [])
@ProjectController = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
@ -121,6 +122,8 @@ describe "ProjectController", ->
"../Notifications/NotificationsBuilder":@NotificationBuilder
"../User/UserGetter": @UserGetter
"../BrandVariations/BrandVariationsHandler": @BrandVariationsHandler
'../Institutions/InstitutionsAPI':
getUserAffiliations: @getUserAffiliations
@projectName = "£12321jkj9ujkljds"
@req =
@ -736,5 +739,3 @@ describe "ProjectController", ->
false,
false
]