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

use new routes and params from v1 ip matcher endpoint

hugh-obrien 8 лет назад
Родитель
Сommit
d950e14b3f

+ 4 - 4
services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee

@@ -39,7 +39,7 @@ module.exports =
 			_key = @key
 			_key = @key
 			request {
 			request {
 				method: 'GET'
 				method: 'GET'
-				url: "#{settings.apis.v1.url}/api/v2/users/ip_matcher/#{userId}"
+				url: "#{settings.apis.v1.url}/api/v2/users/#{userId}/ip_matcher"
 				auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }
 				auth: { user: settings.apis.v1.user, pass: settings.apis.v1.pass }
 				body: { ip: ip }
 				body: { ip: ip }
 				json: true
 				json: true
@@ -49,9 +49,9 @@ module.exports =
 				return null if response.statusCode == 204
 				return null if response.statusCode == 204
 
 
 				messageOpts =
 				messageOpts =
-					university_id: body.university_id
-					university_name: body.university_name
-					content: body.ad_copy
+					university_id: body.id
+					university_name: body.name
+					content: body.enrolment_ad_html
 				logger.log user_id:userId, key:_key, "creating notification key for user"
 				logger.log user_id:userId, key:_key, "creating notification key for user"
 				NotificationsHandler.createNotification userId, _key, "notification_ip_matched_affiliation", messageOpts, null, callback
 				NotificationsHandler.createNotification userId, _key, "notification_ip_matched_affiliation", messageOpts, null, callback
 
 

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

@@ -2,7 +2,9 @@ NotificationsHandler = require("./NotificationsHandler")
 NotificationsBuilder = require("./NotificationsBuilder")
 NotificationsBuilder = require("./NotificationsBuilder")
 AuthenticationController = require("../Authentication/AuthenticationController")
 AuthenticationController = require("../Authentication/AuthenticationController")
 Settings = require 'settings-sharelatex'
 Settings = require 'settings-sharelatex'
+UserGetter = require("../User/UserGetter")
 logger = require("logger-sharelatex")
 logger = require("logger-sharelatex")
+async = require "async"
 _ = require("underscore")
 _ = require("underscore")
 
 
 module.exports =
 module.exports =
@@ -15,9 +17,15 @@ 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).create((err) ->
-				return err
-			)
+			UserGetter.getUser user_id, { 'lastLoginIp': 1 }, (error, user) ->
+				console.log(user.lastLoginIp)
+				if ip != user.lastLoginIp
+					async.series ([
+						() ->
+							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)->

+ 2 - 1
services/web/app/views/project/list/notifications.pug

@@ -63,7 +63,8 @@ span(ng-controller="NotificationsController").userNotifications
 						.alert.alert-info(ng-switch-when="notification_ip_matched_affiliation")
 						.alert.alert-info(ng-switch-when="notification_ip_matched_affiliation")
 							div.notification_inner
 							div.notification_inner
 								.notification_body
 								.notification_body
-									| Add an email for: {{ notification.messageOpts.university_name }}
+									| Add an email for 
+									strong {{ notification.messageOpts.university_name }}
 									a.pull-right.btn.btn-sm.btn-info(href="/user/settings")
 									a.pull-right.btn.btn-sm.btn-info(href="/user/settings")
 										| Add Affiliation
 										| Add Affiliation
 								span().notification_close
 								span().notification_close