mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add check for id to exist in domain announcments
null check user at start of getUnreadAnnouncements fix spelling mistake
This commit is contained in:
parent
69ab275404
commit
1280a2313d
2 changed files with 54 additions and 7 deletions
|
@ -1,9 +1,9 @@
|
||||||
AnalyticsManager = require("../Analytics/AnalyticsManager")
|
AnalyticsManager = require("../Analytics/AnalyticsManager")
|
||||||
BlogHandler = require("../Blog/BlogHandler")
|
BlogHandler = require("../Blog/BlogHandler")
|
||||||
async = require("async")
|
|
||||||
_ = require("lodash")
|
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
settings = require("settings-sharelatex")
|
settings = require("settings-sharelatex")
|
||||||
|
async = require("async")
|
||||||
|
_ = require("lodash")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,22 +13,25 @@ module.exports = AnnouncementsHandler =
|
||||||
|
|
||||||
|
|
||||||
_domainSpecificAnnouncements : (email)->
|
_domainSpecificAnnouncements : (email)->
|
||||||
domainSpecific = _.filter settings?.domainAnnouncmentsToShow, (domainAnnouncment)->
|
domainSpecific = _.filter settings?.domainAnnouncementsToShow, (domainAnnouncment)->
|
||||||
matches = _.filter domainAnnouncment.domains, (domain)->
|
matches = _.filter domainAnnouncment.domains, (domain)->
|
||||||
return email.indexOf(domain) != -1
|
return email.indexOf(domain) != -1
|
||||||
return matches.length > 0
|
return matches.length > 0 and domainAnnouncment.id?
|
||||||
return domainSpecific or []
|
return domainSpecific or []
|
||||||
|
|
||||||
|
|
||||||
getUnreadAnnouncements : (user, callback = (err, announcements)->)->
|
getUnreadAnnouncements : (user, callback = (err, announcements)->)->
|
||||||
|
if !user? and !user._id?
|
||||||
|
return callback("user not supplied")
|
||||||
|
|
||||||
async.parallel {
|
async.parallel {
|
||||||
lastEvent: (cb)->
|
lastEvent: (cb)->
|
||||||
AnalyticsManager.getLastOccurance user?._id, "announcement-alert-dismissed", cb
|
AnalyticsManager.getLastOccurance user._id, "announcement-alert-dismissed", cb
|
||||||
announcements: (cb)->
|
announcements: (cb)->
|
||||||
BlogHandler.getLatestAnnouncements cb
|
BlogHandler.getLatestAnnouncements cb
|
||||||
}, (err, results)->
|
}, (err, results)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, user_id:user?._id, "error getting unread announcements"
|
logger.err err:err, user_id:user._id, "error getting unread announcements"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
|
||||||
domainSpecific = AnnouncementsHandler._domainSpecificAnnouncements(user?.email)
|
domainSpecific = AnnouncementsHandler._domainSpecificAnnouncements(user?.email)
|
||||||
|
|
|
@ -17,13 +17,14 @@ describe 'AnnouncementsHandler', ->
|
||||||
getLastOccurance: sinon.stub()
|
getLastOccurance: sinon.stub()
|
||||||
@BlogHandler =
|
@BlogHandler =
|
||||||
getLatestAnnouncements:sinon.stub()
|
getLatestAnnouncements:sinon.stub()
|
||||||
|
@settings = {}
|
||||||
@handler = SandboxedModule.require modulePath, requires:
|
@handler = SandboxedModule.require modulePath, requires:
|
||||||
"../Analytics/AnalyticsManager":@AnalyticsManager
|
"../Analytics/AnalyticsManager":@AnalyticsManager
|
||||||
"../Blog/BlogHandler":@BlogHandler
|
"../Blog/BlogHandler":@BlogHandler
|
||||||
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
|
|
||||||
|
|
||||||
describe "getUnreadAnnouncements", ->
|
describe "getUnreadAnnouncements", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@stubbedAnnouncements = [
|
@stubbedAnnouncements = [
|
||||||
|
@ -113,3 +114,46 @@ describe 'AnnouncementsHandler', ->
|
||||||
announcements[1].should.equal @stubbedDomainSpecificAnn[0]
|
announcements[1].should.equal @stubbedDomainSpecificAnn[0]
|
||||||
announcements[0].should.equal @stubbedAnnouncements[0]
|
announcements[0].should.equal @stubbedAnnouncements[0]
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "_domainSpecificAnnouncements", ->
|
||||||
|
beforeEach ->
|
||||||
|
@settings.domainAnnouncementsToShow = [
|
||||||
|
{
|
||||||
|
domains: ["gmail.com", 'yahoo.edu']
|
||||||
|
title: "some message"
|
||||||
|
excerpt: "read this"
|
||||||
|
url:"http://www.sharelatex.com/i/somewhere"
|
||||||
|
id:"id1"
|
||||||
|
date: new Date(1308369600000).toString()
|
||||||
|
}, {
|
||||||
|
domains: ["gmail.com", 'yahoo.edu']
|
||||||
|
title: "some message"
|
||||||
|
excerpt: "read this"
|
||||||
|
url:"http://www.sharelatex.com/i/somewhere"
|
||||||
|
date: new Date(1308369600000).toString()
|
||||||
|
}, {
|
||||||
|
domains: ["gmail.com", 'yahoo.edu']
|
||||||
|
title: "some message"
|
||||||
|
excerpt: "read this"
|
||||||
|
url:"http://www.sharelatex.com/i/somewhere"
|
||||||
|
id:"id3"
|
||||||
|
date: new Date(1308369600000).toString()
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
it "should filter announcments which don't have an id", (done) ->
|
||||||
|
result = @handler._domainSpecificAnnouncements "someone@gmail.com"
|
||||||
|
result.length.should.equal 2
|
||||||
|
result[0].id.should.equal "id1"
|
||||||
|
result[1].id.should.equal "id3"
|
||||||
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
it "should match on domain", (done) ->
|
||||||
|
@settings.domainAnnouncementsToShow[2].domains = ["yahoo.com"]
|
||||||
|
result = @handler._domainSpecificAnnouncements "someone@gmail.com"
|
||||||
|
result.length.should.equal 1
|
||||||
|
result[0].id.should.equal "id1"
|
||||||
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue