Parcourir la source

correctly create and display ip matched affiliations

hugh-obrien il y a 8 ans
Parent
commit
38faa5c25e

+ 24 - 11
services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee

@@ -33,14 +33,27 @@ module.exports =
 			NotificationsHandler.markAsReadByKeyOnly @key, callback
 			NotificationsHandler.markAsReadByKeyOnly @key, callback
 
 
 	ipMatcherAffiliation: (userId, ip) ->
 	ipMatcherAffiliation: (userId, ip) ->
-		return null unless settings?.apis?.v1?.url # service is not configured
-		request {
-			method: 'GET'
-			url: "#{settings.apis.v1.url}/api/v2/users/ip_matcher/#{userId}"
-			auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }
-			body: { ip: ip }
-			json: true
-			timeout: 20 * 1000
-		}, (error, response, body) ->
-			return error if error?
-			return null if response.statusCode == 204
+		key: "ip-matched-affiliation-#{ip}"
+		create: (callback=()->) ->
+			return null unless settings?.apis?.v1?.url # service is not configured
+			_key = @key
+			request {
+				method: 'GET'
+				url: "#{settings.apis.v1.url}/api/v2/users/ip_matcher/#{userId}"
+				auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }
+				body: { ip: ip }
+				json: true
+				timeout: 20 * 1000
+			}, (error, response, body) ->
+				return error if error?
+				return null if response.statusCode == 204
+
+				messageOpts =
+					university_id: body.university_id
+					university_name: body.university_name
+					content: body.ad_copy
+				logger.log user_id:userId, key:_key, "creating notification key for user"
+				NotificationsHandler.createNotification userId, _key, "notification_ip_matched_affiliation", messageOpts, null, callback
+
+		read: (callback = ->)->
+			NotificationsHandler.markAsReadWithKey userId, @key, callback

+ 3 - 1
services/web/app/coffee/Features/Notifications/NotificationsController.coffee

@@ -15,7 +15,9 @@ module.exports =
 
 
 		# in v2 add notifications for matching university IPs
 		# in v2 add notifications for matching university IPs
 		if Settings.overleaf?
 		if Settings.overleaf?
-			NotificationsBuilder.ipMatcherAffiliation(user_id, ip)
+			NotificationsBuilder.ipMatcherAffiliation(user_id, ip).create((err) ->
+				return err
+			)
 
 
 		NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
 		NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
 			unreadNotifications = _.map unreadNotifications, (notification)->
 			unreadNotifications = _.map unreadNotifications, (notification)->

+ 10 - 0
services/web/app/views/project/list/notifications.pug

@@ -60,6 +60,16 @@ span(ng-controller="NotificationsController").userNotifications
 									button(ng-click="dismiss(notification)").close.pull-right
 									button(ng-click="dismiss(notification)").close.pull-right
 										span(aria-hidden="true") ×
 										span(aria-hidden="true") ×
 										span.sr-only #{translate("close")}
 										span.sr-only #{translate("close")}
+						.alert.alert-info(ng-switch-when="notification_ip_matched_affiliation")
+							div.notification_inner
+								.notification_body
+									| Add an email for: {{ notification.messageOpts.university_name }}
+									a.pull-right.btn.btn-sm.btn-info(href="/user/settings")
+										| Add Affiliation
+								span().notification_close
+									button(ng-click="dismiss(notification)").close.pull-right
+										span(aria-hidden="true") ×
+										span.sr-only #{translate("close")}
 						.alert.alert-info(ng-switch-default)
 						.alert.alert-info(ng-switch-default)
 							div.notification_inner
 							div.notification_inner
 								span(ng-bind-html="notification.html").notification_body
 								span(ng-bind-html="notification.html").notification_body