Просмотр исходного кода

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

Link to portal templates from project dash

GitOrigin-RevId: 303f65b9c5b85a23535479a7d06e70e75069db6c
Jessica Lawshe 7 лет назад
Родитель
Сommit
f02e3e604b

+ 19 - 1
services/web/app/coffee/Features/Project/ProjectController.coffee

@@ -32,6 +32,7 @@ crypto = require 'crypto'
 { V1ConnectionError } = require '../Errors/Errors'
 { V1ConnectionError } = require '../Errors/Errors'
 Features = require('../../infrastructure/Features')
 Features = require('../../infrastructure/Features')
 BrandVariationsHandler = require("../BrandVariations/BrandVariationsHandler")
 BrandVariationsHandler = require("../BrandVariations/BrandVariationsHandler")
+{ getUserAffiliations } = require("../Institutions/InstitutionsAPI")
 
 
 module.exports = ProjectController =
 module.exports = ProjectController =
 
 
@@ -198,6 +199,8 @@ module.exports = ProjectController =
 					return cb(error, hasPaidSubscription)
 					return cb(error, hasPaidSubscription)
 			user: (cb) ->
 			user: (cb) ->
 				User.findById user_id, "featureSwitches overleaf awareOfV2 features", cb
 				User.findById user_id, "featureSwitches overleaf awareOfV2 features", cb
+			userAffiliations: (cb) ->
+				getUserAffiliations user_id, cb
 			}, (err, results)->
 			}, (err, results)->
 				if err?
 				if err?
 					logger.err err:err, "error getting data for project list page"
 					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)->
 				notifications = require("underscore").map results.notifications, (notification)->
 					notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
 					notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
 					return notification
 					return notification
+				portalTemplates = ProjectController._buildPortalTemplatesList results.userAffiliations
 				projects = ProjectController._buildProjectList results.projects, results.v1Projects?.projects
 				projects = ProjectController._buildProjectList results.projects, results.v1Projects?.projects
 				user = results.user
 				user = results.user
+				userAffiliations = results.userAffiliations
 				warnings = ProjectController._buildWarningsList results.v1Projects
 				warnings = ProjectController._buildWarningsList results.v1Projects
 
 
 				# in v2 add notifications for matching university IPs
 				# in v2 add notifications for matching university IPs
@@ -226,7 +231,9 @@ module.exports = ProjectController =
 						projects: projects
 						projects: projects
 						tags: tags
 						tags: tags
 						notifications: notifications or []
 						notifications: notifications or []
+						portalTemplates: portalTemplates
 						user: user
 						user: user
+						userAffiliations: userAffiliations
 						hasSubscription: results.hasSubscription
 						hasSubscription: results.hasSubscription
 						isShowingV1Projects: results.v1Projects?
 						isShowingV1Projects: results.v1Projects?
 						warnings: warnings
 						warnings: warnings
@@ -309,7 +316,7 @@ module.exports = ProjectController =
 			user = results.user
 			user = results.user
 			subscription = results.subscription
 			subscription = results.subscription
 			brandVariation = results.brandVariation
 			brandVariation = results.brandVariation
-			
+
 			daysSinceLastUpdated =  (new Date() - project.lastUpdated) / 86400000
 			daysSinceLastUpdated =  (new Date() - project.lastUpdated) / 86400000
 			logger.log project_id:project_id, daysSinceLastUpdated:daysSinceLastUpdated, "got db results for loading editor"
 			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."
 			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
 		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)->
 defaultSettingsForAnonymousUser = (user_id)->
 	id : user_id
 	id : user_id
 	ace:
 	ace:

+ 12 - 2
services/web/app/views/project/list/side-bar.pug

@@ -26,7 +26,19 @@
 				ng-click="openUploadProjectModal()"
 				ng-click="openUploadProjectModal()"
 			) #{translate("upload_project")}
 			) #{translate("upload_project")}
 		!= moduleIncludes("newProjectMenu", locals)
 		!= 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)
 		if (templates)
+			//- templates is an express local var, via settings.templateLinks
 			li.divider
 			li.divider
 			li.dropdown-header #{translate("templates")}
 			li.dropdown-header #{translate("templates")}
 			each item in templates
 			each item in templates
@@ -137,5 +149,3 @@
 			
 			
 script.
 script.
 	window.userHasNoSubscription = #{!!(settings.enableSubscriptions && !hasSubscription)}
 	window.userHasNoSubscription = #{!!(settings.enableSubscriptions && !hasSubscription)}
-
-

+ 5 - 4
services/web/test/unit/coffee/Project/ProjectControllerTests.coffee

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