use new annoncments feature for case study info

This commit is contained in:
Henry Oswald
2017-01-24 16:03:05 +00:00
parent 2341a8481a
commit 13d21b881f
7 changed files with 65 additions and 44 deletions
@@ -9,9 +9,9 @@ module.exports =
if !settings?.apis?.analytics?.url? or !settings.apis.blog.url?
return res.json []
user_id = AuthenticationController.getLoggedInUserId(req)
logger.log {user_id}, "getting unread announcements"
AnnouncementsHandler.getUnreadAnnouncements user_id, (err, announcements)->
user = AuthenticationController.getSessionUser(req)
logger.log {user_id:user?._id}, "getting unread announcements"
AnnouncementsHandler.getUnreadAnnouncements user, (err, announcements)->
if err?
logger.err {err, user_id}, "unable to get unread announcements"
next(err)
@@ -5,20 +5,44 @@ _ = require("lodash")
logger = require("logger-sharelatex")
settings = require("settings-sharelatex")
module.exports =
getUnreadAnnouncements : (user_id, callback = (err, announcements)->)->
module.exports = AnnouncementsHandler =
_domainSpecificAnnouncements : (email)->
domainSpecific = _.filter settings?.domainAnnouncmentsToShow, (domainAnnouncment)->
matches = _.filter domainAnnouncment.domains, (domain)->
return email.indexOf(domain) != -1
return matches.length > 0
return domainSpecific or []
getUnreadAnnouncements : (user, callback = (err, announcements)->)->
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)
announcements = _.sortBy(results.announcements, "date").reverse()
domainSpecific = AnnouncementsHandler._domainSpecificAnnouncements(user?.email)
domainSpecific = _.map domainSpecific, (domainAnnouncment)->
try
domainAnnouncment.date = new Date(domainAnnouncment.date)
return domainAnnouncment
catch e
return callback(e)
announcements = results.announcements
announcements = _.union announcements, domainSpecific
announcements = _.sortBy(announcements, "date").reverse()
lastSeenBlogId = results?.lastEvent?.segmentation?.blogPostId
@@ -35,6 +59,6 @@ module.exports =
announcement.read = read
return announcement
logger.log announcementsLength:announcements?.length, user_id:user_id, "returning announcements"
logger.log announcementsLength:announcements?.length, user_id:user?._id, "returning announcements"
callback null, announcements
@@ -190,24 +190,6 @@ module.exports = (app, webRouter, apiRouter)->
res.locals.getSessionUser = ->
return AuthenticationController.getSessionUser(req)
res.locals.caseStudyToShow = ->
Settings.caseStudysToShow = [
{
url:"http://www.sharelatex.com/i/university/indiana",
domains: ["sharelatex.com", 'chicargo.edu'],
title: "Indiana University Case Study",
logo:"/img/crests/logo/iu.png"
}
]
caseStudy = _.filter Settings.caseStudysToShow, (caseStudy)->
matches = _.filter caseStudy.domains, (domain)->
email = AuthenticationController.getSessionUser(req)?.email
return email.indexOf(domain) != -1
return matches.length > 0
return caseStudy?[0] or {}
next()
webRouter.use (req, res, next) ->
-1
View File
@@ -11,7 +11,6 @@ block content
projects: !{JSON.stringify(projects).replace(/\//g, '\\/')},
tags: !{JSON.stringify(tags).replace(/\//g, '\\/')},
notifications: !{JSON.stringify(notifications).replace(/\//g, '\\/')},
caseStudy: !{JSON.stringify(caseStudyToShow())}
};
window.algolia = {
institutions: {
@@ -94,7 +94,7 @@
- if (showUserDetailsArea)
span(ng-controller="LeftHandMenuPromoController", ng-cloak)
.row-spaced#userProfileInformation(ng-if="hasProjects && !showCaseStudy")
.row-spaced#userProfileInformation(ng-if="hasProjects")
div(ng-controller="UserProfileController")
hr(ng-show="percentComplete < 100")
.text-centered.user-profile(ng-show="percentComplete < 100")
@@ -108,13 +108,6 @@
ng-click="openUserProfileModal()"
) #{translate("complete")}
.row-spaced(ng-if="hasProjects && showCaseStudy", ng-cloak).text-centered
hr
a(href="{{caseStudy.url}}")
p.small read about:
p
img(src="{{caseStudy.logo}}")
a(href="{{caseStudy.url}}") {{caseStudy.title}}
.row-spaced(ng-if="hasProjects && userHasNoSubscription", ng-cloak).text-centered
hr
@@ -7,6 +7,3 @@ define [
$scope.hasProjects = window.data.projects.length > 0
$scope.userHasNoSubscription = window.userHasNoSubscription
$scope.showCaseStudy = window.data.caseStudy?.url?
$scope.caseStudy = window.data.caseStudy
@@ -10,7 +10,9 @@ expect = require("chai").expect
describe 'AnnouncementsHandler', ->
beforeEach ->
@user_id = "some_id"
@user =
_id:"some_id"
email: "someone@gmail.com"
@AnalyticsManager =
getLastOccurance: sinon.stub()
@BlogHandler =
@@ -44,7 +46,7 @@ describe 'AnnouncementsHandler', ->
it "should mark all announcements as read is false", (done)->
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, [])
@handler.getUnreadAnnouncements @user_id, (err, announcements)=>
@handler.getUnreadAnnouncements @user, (err, announcements)=>
announcements[0].read.should.equal false
announcements[1].read.should.equal false
announcements[2].read.should.equal false
@@ -53,7 +55,7 @@ describe 'AnnouncementsHandler', ->
it "should should be sorted again to ensure correct order", (done)->
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, [])
@handler.getUnreadAnnouncements @user_id, (err, announcements)=>
@handler.getUnreadAnnouncements @user, (err, announcements)=>
announcements[3].should.equal @stubbedAnnouncements[2]
announcements[2].should.equal @stubbedAnnouncements[3]
announcements[1].should.equal @stubbedAnnouncements[1]
@@ -62,7 +64,7 @@ describe 'AnnouncementsHandler', ->
it "should return older ones marked as read as well", (done)->
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, {segmentation:{blogPostId:"/2014/04/12/title-date-irrelivant"}})
@handler.getUnreadAnnouncements @user_id, (err, announcements)=>
@handler.getUnreadAnnouncements @user, (err, announcements)=>
announcements[0].id.should.equal @stubbedAnnouncements[0].id
announcements[0].read.should.equal false
@@ -79,7 +81,7 @@ describe 'AnnouncementsHandler', ->
it "should return all of them marked as read", (done)->
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, {segmentation:{blogPostId:"/2016/11/01/introducting-latex-code-checker"}})
@handler.getUnreadAnnouncements @user_id, (err, announcements)=>
@handler.getUnreadAnnouncements @user, (err, announcements)=>
announcements[0].read.should.equal true
announcements[1].read.should.equal true
announcements[2].read.should.equal true
@@ -87,3 +89,27 @@ describe 'AnnouncementsHandler', ->
done()
describe "with custom domain announcements", ->
beforeEach ->
@stubbedDomainSpecificAnn = [
{
domains: ["gmail.com", 'yahoo.edu']
title: "some message"
excerpt: "read this"
url:"http://www.sharelatex.com/i/somewhere"
id:"iaaa"
date: new Date(1308369600000).toString()
}
]
@handler._domainSpecificAnnouncements = sinon.stub().returns(@stubbedDomainSpecificAnn)
it "should insert the domain specific in the correct place", (done)->
@AnalyticsManager.getLastOccurance.callsArgWith(2, null, [])
@handler.getUnreadAnnouncements @user, (err, announcements)=>
announcements[4].should.equal @stubbedAnnouncements[2]
announcements[3].should.equal @stubbedAnnouncements[3]
announcements[2].should.equal @stubbedAnnouncements[1]
announcements[1].should.equal @stubbedDomainSpecificAnn[0]
announcements[0].should.equal @stubbedAnnouncements[0]
done()