mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-27 01:47:52 +00:00
add mark key endpoint
This commit is contained in:
parent
6291a8d2cf
commit
c3514fd453
6 changed files with 61 additions and 17 deletions
|
@ -22,7 +22,8 @@ app.configure ()->
|
||||||
|
|
||||||
app.post '/user/:user_id', controller.addNotification
|
app.post '/user/:user_id', controller.addNotification
|
||||||
app.get '/user/:user_id', controller.getUserNotifications
|
app.get '/user/:user_id', controller.getUserNotifications
|
||||||
app.del '/user/:user_id/notification/:notification_id', controller.removeNotification
|
app.del '/user/:user_id/notification/:notification_id', controller.removeNotificationId
|
||||||
|
app.del '/user/:user_id', controller.removeNotificationKey
|
||||||
|
|
||||||
app.get '/status', (req, res)->
|
app.get '/status', (req, res)->
|
||||||
res.send('notifications sharelatex up')
|
res.send('notifications sharelatex up')
|
||||||
|
|
|
@ -41,6 +41,10 @@ module.exports =
|
||||||
return callback(err)
|
return callback(err)
|
||||||
else
|
else
|
||||||
notification_id = body[1][0]._id
|
notification_id = body[1][0]._id
|
||||||
|
notification_key = body[1][0].key
|
||||||
opts = getOpts("/notification/#{notification_id}")
|
opts = getOpts("/notification/#{notification_id}")
|
||||||
request.del opts, (err, res, body)->
|
request.del opts, (err, res, body)->
|
||||||
db.notifications.remove {_id:ObjectId(notification_id)}, callback
|
opts = getOpts("")
|
||||||
|
opts.json = {key: notification_key}
|
||||||
|
request.del opts, (err, res, body)->
|
||||||
|
db.notifications.remove {_id:ObjectId(notification_id)}, callback
|
||||||
|
|
|
@ -29,10 +29,18 @@ module.exports =
|
||||||
templateKey: notification.templateKey
|
templateKey: notification.templateKey
|
||||||
db.notifications.insert(doc, callback)
|
db.notifications.insert(doc, callback)
|
||||||
|
|
||||||
removeNotification: (user_id, notification_id, callback)->
|
removeNotificationId: (user_id, notification_id, callback)->
|
||||||
searchOps =
|
searchOps =
|
||||||
user_id:ObjectId(user_id)
|
user_id:ObjectId(user_id)
|
||||||
_id:ObjectId(notification_id)
|
_id:ObjectId(notification_id)
|
||||||
updateOperation =
|
updateOperation =
|
||||||
"$unset": {templateKey:true}
|
"$unset": {templateKey:true}
|
||||||
db.notifications.update searchOps, updateOperation, callback
|
db.notifications.update searchOps, updateOperation, callback
|
||||||
|
|
||||||
|
removeNotificationKey: (user_id, notification_key, callback)->
|
||||||
|
searchOps =
|
||||||
|
user_id:ObjectId(user_id)
|
||||||
|
key: notification_key
|
||||||
|
updateOperation =
|
||||||
|
"$unset": {templateKey:true}
|
||||||
|
db.notifications.update searchOps, updateOperation, callback
|
||||||
|
|
|
@ -19,8 +19,14 @@ module.exports =
|
||||||
else
|
else
|
||||||
res.send()
|
res.send()
|
||||||
|
|
||||||
removeNotification: (req, res)->
|
removeNotificationId: (req, res)->
|
||||||
logger.log user_id: req.params.user_id, notification_id: req.params.notification_id, "mark notification as read"
|
logger.log user_id: req.params.user_id, notification_id: req.params.notification_id, "mark id notification as read"
|
||||||
metrics.inc "removeNotification"
|
metrics.inc "removeNotificationId"
|
||||||
Notifications.removeNotification req.params.user_id, req.params.notification_id, (err, notifications)->
|
Notifications.removeNotificationId req.params.user_id, req.params.notification_id, (err, notifications)->
|
||||||
|
res.send()
|
||||||
|
|
||||||
|
removeNotificationKey: (req, res)->
|
||||||
|
logger.log user_id: req.params.user_id, notification_key: req.body.key, "mark key notification as read"
|
||||||
|
metrics.inc "removeNotificationKey"
|
||||||
|
Notifications.removeNotificationKey req.params.user_id, req.body.key, (err, notifications)->
|
||||||
res.send()
|
res.send()
|
||||||
|
|
|
@ -7,8 +7,9 @@ assert = require('assert')
|
||||||
|
|
||||||
user_id = "51dc93e6fb625a261300003b"
|
user_id = "51dc93e6fb625a261300003b"
|
||||||
notification_id = "fb625a26f09d"
|
notification_id = "fb625a26f09d"
|
||||||
|
notification_key = "my-notification-key"
|
||||||
|
|
||||||
describe 'Notifications controller', ->
|
describe 'Notifications Controller', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
self = @
|
self = @
|
||||||
@notifications = {}
|
@notifications = {}
|
||||||
|
@ -18,7 +19,7 @@ describe 'Notifications controller', ->
|
||||||
'metrics-sharelatex':
|
'metrics-sharelatex':
|
||||||
inc: sinon.stub()
|
inc: sinon.stub()
|
||||||
|
|
||||||
@stubbedNotification = [{key:"notification-key", messageOpts:"some info", templateKey:"template-key"}]
|
@stubbedNotification = [{key: notification_key, messageOpts:"some info", templateKey:"template-key"}]
|
||||||
|
|
||||||
describe "getUserNotifications", ->
|
describe "getUserNotifications", ->
|
||||||
it 'should ask the notifications for the users notifications', (done)->
|
it 'should ask the notifications for the users notifications', (done)->
|
||||||
|
@ -42,13 +43,24 @@ describe 'Notifications controller', ->
|
||||||
@notifications.addNotification.calledWith(user_id, @stubbedNotification).should.equal true
|
@notifications.addNotification.calledWith(user_id, @stubbedNotification).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "removeNotification", ->
|
describe "removeNotificationId", ->
|
||||||
it "should tell the notifications to mark the notification as read", (done)->
|
it "should tell the notifications to mark the notification Id as read", (done)->
|
||||||
@notifications.removeNotification = sinon.stub().callsArgWith(2)
|
@notifications.removeNotificationId = sinon.stub().callsArgWith(2)
|
||||||
req =
|
req =
|
||||||
params:
|
params:
|
||||||
user_id: user_id
|
user_id: user_id
|
||||||
notification_id: notification_id
|
notification_id: notification_id
|
||||||
@controller.removeNotification req, send:(result)=>
|
@controller.removeNotificationId req, send:(result)=>
|
||||||
@notifications.removeNotification.calledWith(user_id, notification_id).should.equal true
|
@notifications.removeNotificationId.calledWith(user_id, notification_id).should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
describe "removeNotificationKey", ->
|
||||||
|
it "should tell the notifications to mark the notification Key as read", (done)->
|
||||||
|
@notifications.removeNotificationKey = sinon.stub().callsArgWith(2)
|
||||||
|
req =
|
||||||
|
params:
|
||||||
|
user_id: user_id
|
||||||
|
body: {key: notification_key}
|
||||||
|
@controller.removeNotificationKey req, send:(result)=>
|
||||||
|
@notifications.removeNotificationKey.calledWith(user_id, notification_key).should.equal true
|
||||||
done()
|
done()
|
|
@ -10,7 +10,7 @@ user_id = "51dc93e6fb625a261300003b"
|
||||||
notification_id = "fb625a26f09d"
|
notification_id = "fb625a26f09d"
|
||||||
notification_key = "notification-key"
|
notification_key = "notification-key"
|
||||||
|
|
||||||
describe 'creating a user', ->
|
describe 'Notifications Tests', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
self = @
|
self = @
|
||||||
@findStub = sinon.stub()
|
@findStub = sinon.stub()
|
||||||
|
@ -60,11 +60,11 @@ describe 'creating a user', ->
|
||||||
@insertStub.calledWith(@stubbedNotification).should.equal false
|
@insertStub.calledWith(@stubbedNotification).should.equal false
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'removeNotification', ->
|
describe 'removeNotificationId', ->
|
||||||
it 'should mark the notification id as read', (done)->
|
it 'should mark the notification id as read', (done)->
|
||||||
@updateStub.callsArgWith(2, null)
|
@updateStub.callsArgWith(2, null)
|
||||||
|
|
||||||
@notifications.removeNotification user_id, notification_id, (err)=>
|
@notifications.removeNotificationId user_id, notification_id, (err)=>
|
||||||
searchOps =
|
searchOps =
|
||||||
user_id:ObjectId(user_id)
|
user_id:ObjectId(user_id)
|
||||||
_id:ObjectId(notification_id)
|
_id:ObjectId(notification_id)
|
||||||
|
@ -72,3 +72,16 @@ describe 'creating a user', ->
|
||||||
"$unset": {templateKey:true}
|
"$unset": {templateKey:true}
|
||||||
@updateStub.calledWith(searchOps, updateOperation).should.equal true
|
@updateStub.calledWith(searchOps, updateOperation).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe 'removeNotificationKey', ->
|
||||||
|
it 'should mark the notification key as read', (done)->
|
||||||
|
@updateStub.callsArgWith(2, null)
|
||||||
|
|
||||||
|
@notifications.removeNotificationKey user_id, notification_key, (err)=>
|
||||||
|
searchOps =
|
||||||
|
user_id:ObjectId(user_id)
|
||||||
|
key: notification_key
|
||||||
|
updateOperation =
|
||||||
|
"$unset": {templateKey:true}
|
||||||
|
@updateStub.calledWith(searchOps, updateOperation).should.equal true
|
||||||
|
done()
|
Loading…
Add table
Reference in a new issue