From f02e3e604beb586abda79d115599e4204cf0141d Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 3 Dec 2018 12:58:26 -0600 Subject: [PATCH] Merge pull request #1172 from sharelatex/jel-portal-templates-link Link to portal templates from project dash GitOrigin-RevId: 303f65b9c5b85a23535479a7d06e70e75069db6c --- .../Features/Project/ProjectController.coffee | 20 ++++++++++++++++++- .../web/app/views/project/list/side-bar.pug | 14 +++++++++++-- .../Project/ProjectControllerTests.coffee | 9 +++++---- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index b3b8e9a6d4..e33d143f0e 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -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: diff --git a/services/web/app/views/project/list/side-bar.pug b/services/web/app/views/project/list/side-bar.pug index 7896734a6d..88a0fa2a34 100644 --- a/services/web/app/views/project/list/side-bar.pug +++ b/services/web/app/views/project/list/side-bar.pug @@ -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)} - - diff --git a/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee b/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee index 67a37cff6c..cce483dbac 100644 --- a/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee @@ -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 ] - -