From c8084406d3b77b7f707e6a73da3f31da0aa02160 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 17 Feb 2016 16:24:09 +0000 Subject: [PATCH] user notifications auto created on login for joinging groups --- .../Authentication/AuthenticationController.coffee | 3 ++- .../Notifications/NotificationsBuilder.coffee | 4 ++-- .../Notifications/NotificationsHandler.coffee | 1 + .../Subscription/SubscriptionDomainHandler.coffee | 4 ---- .../web/app/coffee/Features/User/UserHandler.coffee | 12 ++++++++++++ 5 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 services/web/app/coffee/Features/User/UserHandler.coffee diff --git a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee index 3ab18bbf0c..312b441158 100644 --- a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee +++ b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee @@ -8,7 +8,7 @@ querystring = require('querystring') Url = require("url") Settings = require "settings-sharelatex" basicAuth = require('basic-auth-connect') - +UserHandler = require("../User/UserHandler") module.exports = AuthenticationController = login: (req, res, next = (error) ->) -> @@ -29,6 +29,7 @@ module.exports = AuthenticationController = AuthenticationManager.authenticate email: email, password, (error, user) -> return next(error) if error? if user? + UserHandler.setupLoginData user, -> LoginRateLimiter.recordSuccessfulLogin email AuthenticationController._recordSuccessfulLogin user._id AuthenticationController.establishUserSession req, user, (error) -> diff --git a/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee b/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee index c68e265920..314142b3af 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee @@ -10,7 +10,7 @@ module.exports = messageOpts = groupName: licence.name subscription_id: licence.subscription_id - NotificationsHandler.createNotification user._id, key, "joinSubscriptionInvite", messageOpts, callback + NotificationsHandler.createNotification user._id, @key, "notification_group_invite", messageOpts, callback read: (callback = ->)-> - NotificationsHandler.markAsReadWithKey user._id, key, callback + NotificationsHandler.markAsReadWithKey user._id, @key, callback diff --git a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee index d621040f69..fe75573c50 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee @@ -30,6 +30,7 @@ module.exports = messageOpts:messageOpts templateKey:templateKey } + logger.log opts:opts, "creating notification for user" request.post opts, callback markAsReadWithKey: (user_id, key, callback)-> diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee index cdd83682a1..3877b93cfd 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionDomainHandler.coffee @@ -3,7 +3,6 @@ async = require("async") _ = require("underscore") settings = require("settings-sharelatex") SubscriptionGroupHandler = require("./SubscriptionGroupHandler") -_s = require("underscore.string") module.exports = SubscriptionDomainHandler = @@ -34,16 +33,13 @@ module.exports = SubscriptionDomainHandler = else return undefined - autoAllocate: (user, callback = ->)-> licence = SubscriptionDomainHandler._findDomainLicence(user.email) - # if licence? SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback else callback() - _findDomainLicence: (email)-> licence = _.find settings.domainLicences, (licence)-> _.find licence.domains, (domain)-> diff --git a/services/web/app/coffee/Features/User/UserHandler.coffee b/services/web/app/coffee/Features/User/UserHandler.coffee new file mode 100644 index 0000000000..68001d0f77 --- /dev/null +++ b/services/web/app/coffee/Features/User/UserHandler.coffee @@ -0,0 +1,12 @@ +SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler") +NotificationsBuilder = require("../Notifications/NotificationsBuilder") + + +module.exports = + + setupLoginData: (user, callback = ->)-> + licence = SubscriptionDomainHandler.getLicenceUserCanJoin user + if licence? + NotificationsBuilder.groupPlan(user, licence).create(callback) + else + return callback()