Merge pull request #2521 from overleaf/ta-announcement-remove
Remove Announcements GitOrigin-RevId: 3fed602e89992ad5f4260134b87ade1e6e088cf7
This commit is contained in:
committed by
Copybot
parent
294418b4ee
commit
db27215760
@@ -1,6 +1,4 @@
|
||||
const settings = require('settings-sharelatex')
|
||||
const logger = require('logger-sharelatex')
|
||||
const request = require('request')
|
||||
const FaultTolerantRequest = require('../../infrastructure/FaultTolerantRequest')
|
||||
const Errors = require('../Errors/Errors')
|
||||
|
||||
@@ -61,18 +59,6 @@ const makeAnalyticsBackgroundRequest = function(userId, options, callback) {
|
||||
FaultTolerantRequest.backgroundRequest(options, callback)
|
||||
}
|
||||
|
||||
// make synchronous request to analytics without retries after checking and
|
||||
// preparing it.
|
||||
const makeAnalyticsRequest = function(userId, options, callback) {
|
||||
let { error, skip } = checkAnalyticsRequest(userId)
|
||||
if (error || skip) {
|
||||
return callback(error)
|
||||
}
|
||||
prepareAnalyticsRequest(options)
|
||||
|
||||
request(options, callback)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
identifyUser(userId, oldUserId, callback) {
|
||||
if (!callback) {
|
||||
@@ -138,25 +124,5 @@ module.exports = {
|
||||
}
|
||||
|
||||
makeAnalyticsBackgroundRequest(userId, opts, callback)
|
||||
},
|
||||
|
||||
getLastOccurrence(userId, event, callback) {
|
||||
const opts = {
|
||||
body: {
|
||||
event
|
||||
},
|
||||
json: true,
|
||||
method: 'POST',
|
||||
timeout: 1000,
|
||||
url: `/user/${userId}/event/last_occurrence`
|
||||
}
|
||||
makeAnalyticsRequest(userId, opts, function(err, response, body) {
|
||||
if (err != null) {
|
||||
logger.warn({ userId, err }, 'error getting last occurance of event')
|
||||
callback(err)
|
||||
} else {
|
||||
callback(null, body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS103: Rewrite code to no longer use __guard__
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const AnnouncementsHandler = require('./AnnouncementsHandler')
|
||||
const AuthenticationController = require('../Authentication/AuthenticationController')
|
||||
const logger = require('logger-sharelatex')
|
||||
const settings = require('settings-sharelatex')
|
||||
|
||||
module.exports = {
|
||||
getUndreadAnnouncements(req, res, next) {
|
||||
if (
|
||||
__guard__(
|
||||
__guard__(
|
||||
settings != null ? settings.apis : undefined,
|
||||
x1 => x1.analytics
|
||||
),
|
||||
x => x.url
|
||||
) == null ||
|
||||
settings.apis.blog.url == null
|
||||
) {
|
||||
return res.json([])
|
||||
}
|
||||
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
logger.log(
|
||||
{ user_id: user != null ? user._id : undefined },
|
||||
'getting unread announcements'
|
||||
)
|
||||
return AnnouncementsHandler.getUnreadAnnouncements(user, function(
|
||||
err,
|
||||
announcements
|
||||
) {
|
||||
if (err != null) {
|
||||
logger.warn(
|
||||
{ err, user_id: user._id },
|
||||
'unable to get unread announcements'
|
||||
)
|
||||
return next(err)
|
||||
} else {
|
||||
return res.json(announcements)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function __guard__(value, transform) {
|
||||
return typeof value !== 'undefined' && value !== null
|
||||
? transform(value)
|
||||
: undefined
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/* eslint-disable
|
||||
handle-callback-err,
|
||||
max-len,
|
||||
standard/no-callback-literal,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS103: Rewrite code to no longer use __guard__
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let AnnouncementsHandler
|
||||
const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
||||
const BlogHandler = require('../Blog/BlogHandler')
|
||||
const logger = require('logger-sharelatex')
|
||||
const settings = require('settings-sharelatex')
|
||||
const async = require('async')
|
||||
const _ = require('lodash')
|
||||
|
||||
module.exports = AnnouncementsHandler = {
|
||||
_domainSpecificAnnouncements(email) {
|
||||
const domainSpecific = _.filter(
|
||||
settings != null ? settings.domainAnnouncements : undefined,
|
||||
function(domainAnnouncment) {
|
||||
const matches = _.filter(
|
||||
domainAnnouncment.domains,
|
||||
domain => email.indexOf(domain) !== -1
|
||||
)
|
||||
return matches.length > 0 && domainAnnouncment.id != null
|
||||
}
|
||||
)
|
||||
return domainSpecific || []
|
||||
},
|
||||
|
||||
getUnreadAnnouncements(user, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(err, announcements) {}
|
||||
}
|
||||
if (user == null && user._id == null) {
|
||||
return callback(new Error('user not supplied'))
|
||||
}
|
||||
|
||||
const timestamp = user._id.toString().substring(0, 8)
|
||||
const userSignupDate = new Date(parseInt(timestamp, 16) * 1000)
|
||||
|
||||
return async.parallel(
|
||||
{
|
||||
lastEvent(cb) {
|
||||
return AnalyticsManager.getLastOccurrence(
|
||||
user._id,
|
||||
'announcement-alert-dismissed',
|
||||
cb
|
||||
)
|
||||
},
|
||||
announcements(cb) {
|
||||
return BlogHandler.getLatestAnnouncements(cb)
|
||||
}
|
||||
},
|
||||
function(err, results) {
|
||||
if (err != null) {
|
||||
logger.warn(
|
||||
{ err, user_id: user._id },
|
||||
'error getting unread announcements'
|
||||
)
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
let domainSpecific = AnnouncementsHandler._domainSpecificAnnouncements(
|
||||
user != null ? user.email : undefined
|
||||
)
|
||||
|
||||
domainSpecific = _.map(domainSpecific, function(domainAnnouncment) {
|
||||
try {
|
||||
domainAnnouncment.date = new Date(domainAnnouncment.date)
|
||||
return domainAnnouncment
|
||||
} catch (e) {
|
||||
return callback(e)
|
||||
}
|
||||
})
|
||||
|
||||
let { announcements } = results
|
||||
announcements = _.union(announcements, domainSpecific)
|
||||
announcements = _.sortBy(announcements, 'date').reverse()
|
||||
|
||||
const lastSeenBlogId = __guard__(
|
||||
__guard__(
|
||||
results != null ? results.lastEvent : undefined,
|
||||
x1 => x1.segmentation
|
||||
),
|
||||
x => x.blogPostId
|
||||
)
|
||||
|
||||
const announcementIndex = _.findIndex(
|
||||
announcements,
|
||||
announcement => announcement.id === lastSeenBlogId
|
||||
)
|
||||
|
||||
announcements = _.map(announcements, function(announcement, index) {
|
||||
let read
|
||||
if (announcement.date < userSignupDate) {
|
||||
read = true
|
||||
} else if (announcementIndex === -1) {
|
||||
read = false
|
||||
} else if (index >= announcementIndex) {
|
||||
read = true
|
||||
} else {
|
||||
read = false
|
||||
}
|
||||
announcement.read = read
|
||||
return announcement
|
||||
})
|
||||
|
||||
return callback(null, announcements)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function __guard__(value, transform) {
|
||||
return typeof value !== 'undefined' && value !== null
|
||||
? transform(value)
|
||||
: undefined
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/* eslint-disable
|
||||
max-len,
|
||||
no-unused-vars,
|
||||
standard/no-callback-literal,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let BlogHandler
|
||||
const request = require('request')
|
||||
const settings = require('settings-sharelatex')
|
||||
const _ = require('underscore')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
module.exports = BlogHandler = {
|
||||
getLatestAnnouncements(callback) {
|
||||
const blogUrl = `${settings.apis.blog.url}/blog/latestannouncements.json`
|
||||
const opts = {
|
||||
url: blogUrl,
|
||||
json: true,
|
||||
timeout: 1000
|
||||
}
|
||||
return request.get(opts, function(err, res, announcements) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
return callback(new Error('blog announcement returned non 200'))
|
||||
}
|
||||
announcements = _.map(announcements, function(announcement) {
|
||||
announcement.date = new Date(announcement.date)
|
||||
return announcement
|
||||
})
|
||||
return callback(err, announcements)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -323,8 +323,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
|
||||
chatMessageBgSaturation: '85%',
|
||||
chatMessageBgLightness: '40%',
|
||||
defaultFontFamily: 'lucida',
|
||||
defaultLineHeight: 'normal',
|
||||
renderAnnouncements: false
|
||||
defaultLineHeight: 'normal'
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
@@ -42,7 +42,6 @@ const BetaProgramController = require('./Features/BetaProgram/BetaProgramControl
|
||||
const SudoModeController = require('./Features/SudoMode/SudoModeController')
|
||||
const SudoModeMiddleware = require('./Features/SudoMode/SudoModeMiddleware')
|
||||
const AnalyticsRouter = require('./Features/Analytics/AnalyticsRouter')
|
||||
const AnnouncementsController = require('./Features/Announcements/AnnouncementsController')
|
||||
const MetaController = require('./Features/Metadata/MetaController')
|
||||
const TokenAccessController = require('./Features/TokenAccess/TokenAccessController')
|
||||
const Features = require('./infrastructure/Features')
|
||||
@@ -688,12 +687,6 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
||||
NotificationsController.markNotificationAsRead
|
||||
)
|
||||
|
||||
webRouter.get(
|
||||
'/announcements',
|
||||
AuthenticationController.requireLogin(),
|
||||
AnnouncementsController.getUndreadAnnouncements
|
||||
)
|
||||
|
||||
// Deprecated in favour of /internal/project/:project_id but still used by versioning
|
||||
privateApiRouter.get(
|
||||
'/project/:project_id/details',
|
||||
|
||||
@@ -16,46 +16,6 @@ block content
|
||||
}
|
||||
};
|
||||
|
||||
if uiConfig.renderAnnouncements
|
||||
.announcements(
|
||||
ng-controller="AnnouncementsController"
|
||||
ng-class="{ 'announcements-open': ui.isOpen }"
|
||||
ng-cloak
|
||||
)
|
||||
.announcements-backdrop(
|
||||
ng-if="ui.isOpen"
|
||||
ng-click="toggleAnnouncementsUI();"
|
||||
)
|
||||
a.announcements-btn(
|
||||
href
|
||||
ng-if="announcements.length"
|
||||
ng-click="toggleAnnouncementsUI();"
|
||||
ng-class="{ 'announcements-btn-open': ui.isOpen, 'announcements-btn-has-new': ui.newItems }"
|
||||
)
|
||||
span.announcements-badge(ng-if="ui.newItems") {{ ui.newItems }}
|
||||
.announcements-body(
|
||||
ng-if="ui.isOpen"
|
||||
)
|
||||
.announcements-scroller
|
||||
.announcement(
|
||||
ng-repeat="announcement in announcements | filter:(ui.newItems ? { read: false } : '') track by announcement.id"
|
||||
)
|
||||
h2.announcement-header {{ announcement.title }}
|
||||
p.announcement-description(ng-bind-html="announcement.excerpt")
|
||||
.announcement-meta
|
||||
p.announcement-date {{ announcement.date | date:"longDate" }}
|
||||
a.announcement-link(
|
||||
ng-href="{{ announcement.url }}"
|
||||
ng-click="logAnnouncementClick()",
|
||||
target="_blank"
|
||||
) Read more
|
||||
div.text-center(
|
||||
ng-if="ui.newItems > 0 && ui.newItems < announcements.length"
|
||||
)
|
||||
a.btn.btn-default.btn-sm(
|
||||
href
|
||||
ng-click="showAll();"
|
||||
) Show all
|
||||
main.content.content-alt.project-list-page(
|
||||
ng-controller="ProjectPageController"
|
||||
role="main"
|
||||
@@ -77,7 +37,7 @@ block content
|
||||
span(aria-hidden="true") ×
|
||||
span.sr-only #{translate("close")}
|
||||
.system-message-content(ng-bind-html="htmlContent")
|
||||
|
||||
|
||||
include ../translations/translation_message
|
||||
|
||||
.project-list-content(event-tracking=settings.overleaf ? "loads_v2_dash" : "", onboard=settings.overleaf ? "true" : "", event-tracking-trigger=settings.overleaf ? "load" : "", event-tracking-mb="true", event-segmentation="{location: 'dash', v2_onboard: true}")
|
||||
@@ -90,7 +50,7 @@ block content
|
||||
.project-list-main.col-md-10.col-xs-9
|
||||
include ./list/notifications
|
||||
include ./list/project-list
|
||||
|
||||
|
||||
.project-list-empty.row(ng-if="projects.length === 0")
|
||||
.project-list-empty-col.col-md-offset-2.col-md-8.col-md-offset-2.col-xs-8.col-xs-offset-2
|
||||
include ./list/empty-project-list
|
||||
|
||||
Reference in New Issue
Block a user