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

user notifications auto created on login for joinging groups

Henry Oswald 10 лет назад
Родитель
Сommit
c8084406d3

+ 2 - 1
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) ->

+ 2 - 2
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

+ 1 - 0
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)->

+ 0 - 4
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)->

+ 12 - 0
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()