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")
|
||||
BlogHandler = require("../Blog/BlogHandler")
|
||||
async = require("async")
|
||||
_ = require("lodash")
|
||||
logger = require("logger-sharelatex")
|
||||
settings = require("settings-sharelatex")
|
||||
async = require("async")
|
||||
_ = require("lodash")
|
||||
|
||||
|
||||
|
||||
|
@ -13,22 +13,25 @@ module.exports = AnnouncementsHandler =
|
|||
|
||||
|
||||
_domainSpecificAnnouncements : (email)->
|
||||
domainSpecific = _.filter settings?.domainAnnouncmentsToShow, (domainAnnouncment)->
|
||||
domainSpecific = _.filter settings?.domainAnnouncementsToShow, (domainAnnouncment)->
|
||||
matches = _.filter domainAnnouncment.domains, (domain)->
|
||||
return email.indexOf(domain) != -1
|
||||
return matches.length > 0
|
||||
return matches.length > 0 and domainAnnouncment.id?
|
||||
return domainSpecific or []
|
||||
|
||||
|
||||
getUnreadAnnouncements : (user, callback = (err, announcements)->)->
|
||||
if !user? and !user._id?
|
||||
return callback("user not supplied")
|
||||
|
||||
async.parallel {
|
||||
lastEvent: (cb)->
|
||||
AnalyticsManager.getLastOccurance user?._id, "announcement-alert-dismissed", cb
|
||||
AnalyticsManager.getLastOccurance user._id, "announcement-alert-dismissed", cb
|
||||
announcements: (cb)->
|
||||
BlogHandler.getLatestAnnouncements cb
|
||||
}, (err, results)->
|
||||
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)
|
||||
|
||||
domainSpecific = AnnouncementsHandler._domainSpecificAnnouncements(user?.email)
|
||||
|
|
|
@ -17,13 +17,14 @@ describe 'AnnouncementsHandler', ->
|
|||
getLastOccurance: sinon.stub()
|
||||
@BlogHandler =
|
||||
getLatestAnnouncements:sinon.stub()
|
||||
@settings = {}
|
||||
@handler = SandboxedModule.require modulePath, requires:
|
||||
"../Analytics/AnalyticsManager":@AnalyticsManager
|
||||
"../Blog/BlogHandler":@BlogHandler
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
|
||||
|
||||
describe "getUnreadAnnouncements", ->
|
||||
beforeEach ->
|
||||
@stubbedAnnouncements = [
|
||||
|
@ -113,3 +114,46 @@ describe 'AnnouncementsHandler', ->
|
|||
announcements[1].should.equal @stubbedDomainSpecificAnn[0]
|
||||
announcements[0].should.equal @stubbedAnnouncements[0]
|
||||
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