mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #5306 from overleaf/jpa-clear-institution-notifications
[web] add a new script for clearing institution notifications GitOrigin-RevId: d102b484c4fb9816832b48c2dfa66953bc996667
This commit is contained in:
@@ -35,6 +35,8 @@ app.delete(
|
||||
)
|
||||
app.delete('/user/:user_id', controller.removeNotificationKey)
|
||||
app.delete('/key/:key', controller.removeNotificationByKeyOnly)
|
||||
app.get('/key/:key/count', controller.countNotificationsByKeyOnly)
|
||||
app.delete('/key/:key/bulk', controller.deleteUnreadNotificationsByKeyOnlyBulk)
|
||||
|
||||
app.get('/status', (req, res) => res.send('notifications sharelatex up'))
|
||||
|
||||
|
||||
@@ -112,6 +112,22 @@ module.exports = Notifications = {
|
||||
db.notifications.updateOne(searchOps, updateOperation, callback)
|
||||
},
|
||||
|
||||
countNotificationsByKeyOnly(notificationKey, callback) {
|
||||
const searchOps = { key: notificationKey, templateKey: { $exists: true } }
|
||||
db.notifications.count(searchOps, callback)
|
||||
},
|
||||
|
||||
deleteUnreadNotificationsByKeyOnlyBulk(notificationKey, callback) {
|
||||
if (typeof notificationKey !== 'string') {
|
||||
throw new Error('refusing to bulk delete arbitrary notifications')
|
||||
}
|
||||
const searchOps = { key: notificationKey, templateKey: { $exists: true } }
|
||||
db.notifications.deleteMany(searchOps, (err, result) => {
|
||||
if (err) return callback(err)
|
||||
callback(null, result.deletedCount)
|
||||
})
|
||||
},
|
||||
|
||||
// hard delete of doc, rather than removing the templateKey
|
||||
deleteNotificationByKeyOnly(notification_key, callback) {
|
||||
const searchOps = { key: notification_key }
|
||||
|
||||
@@ -84,4 +84,29 @@ module.exports = {
|
||||
(err, notifications) => res.sendStatus(200)
|
||||
)
|
||||
},
|
||||
|
||||
countNotificationsByKeyOnly(req, res) {
|
||||
const notificationKey = req.params.key
|
||||
Notifications.countNotificationsByKeyOnly(notificationKey, (err, count) => {
|
||||
if (err) {
|
||||
logger.err({ err, notificationKey }, 'cannot count by key')
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
res.json({ count })
|
||||
})
|
||||
},
|
||||
|
||||
deleteUnreadNotificationsByKeyOnlyBulk(req, res) {
|
||||
const notificationKey = req.params.key
|
||||
Notifications.deleteUnreadNotificationsByKeyOnlyBulk(
|
||||
notificationKey,
|
||||
(err, count) => {
|
||||
if (err) {
|
||||
logger.err({ err, notificationKey }, 'cannot bulk remove by key')
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
res.json({ count })
|
||||
}
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user