mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Call university ip matcher api when checking notifications
This commit is contained in:
parent
d432b6799f
commit
fa23ea75b8
2 changed files with 25 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
NotificationsHandler = require("./NotificationsHandler")
|
NotificationsHandler = require("./NotificationsHandler")
|
||||||
|
request = require "request"
|
||||||
|
settings = require "settings-sharelatex"
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
|
@ -29,3 +31,16 @@ module.exports =
|
||||||
NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, invite.expires, callback
|
NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, invite.expires, callback
|
||||||
read: (callback=()->) ->
|
read: (callback=()->) ->
|
||||||
NotificationsHandler.markAsReadByKeyOnly @key, callback
|
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
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
NotificationsHandler = require("./NotificationsHandler")
|
NotificationsHandler = require("./NotificationsHandler")
|
||||||
|
NotificationsBuilder = require("./NotificationsBuilder")
|
||||||
AuthenticationController = require("../Authentication/AuthenticationController")
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
||||||
|
Settings = require 'settings-sharelatex'
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
getAllUnreadNotifications: (req, res)->
|
getAllUnreadNotifications: (req, res)->
|
||||||
|
ip = req.headers['x-forwarded-for'] ||
|
||||||
|
req.connection.remoteAddress ||
|
||||||
|
req.socket.remoteAddress
|
||||||
user_id = AuthenticationController.getLoggedInUserId(req)
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
||||||
|
|
||||||
|
# in v2 add notifications for matching university IPs
|
||||||
|
if Settings.overleaf?
|
||||||
|
NotificationsBuilder.ipMatcherAffiliation(user_id, ip)
|
||||||
|
|
||||||
NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
|
NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
|
||||||
unreadNotifications = _.map unreadNotifications, (notification)->
|
unreadNotifications = _.map unreadNotifications, (notification)->
|
||||||
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
|
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
|
||||||
|
|
Loading…
Reference in a new issue