1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-17 18:39:08 +00:00

correctly create and display ip matched affiliations

This commit is contained in:
hugh-obrien 2018-09-02 15:22:45 +01:00
parent fa23ea75b8
commit 38faa5c25e
3 changed files with 37 additions and 12 deletions
services/web/app

View file

@ -33,14 +33,27 @@ module.exports =
NotificationsHandler.markAsReadByKeyOnly @key, callback
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

View file

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

View file

@ -60,6 +60,16 @@ span(ng-controller="NotificationsController").userNotifications
button(ng-click="dismiss(notification)").close.pull-right
span(aria-hidden="true") ×
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)
div.notification_inner
span(ng-bind-html="notification.html").notification_body