diff --git a/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee b/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee index da1a6c4957..b9f7500809 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsBuilder.coffee @@ -3,6 +3,8 @@ NotificationsHandler = require("./NotificationsHandler") module.exports = + # Note: notification keys should be url-safe + groupPlan: (user, licence)-> key : "join-sub-#{licence.subscription_id}" create: (callback = ->)-> @@ -26,4 +28,4 @@ module.exports = logger.log {user_id: user._id, project_id: project._id, invite_id: invite._id, key: @key}, "creating project invite notification for user" NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, callback read: (callback=()->) -> - NotificationsHandler.markAsReadWithKey user._id, @key, callback + NotificationsHandler.markAsReadByKeyOnly @key, callback diff --git a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee index a7cf6a4672..9a7af1bdd1 100644 --- a/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee +++ b/services/web/app/coffee/Features/Notifications/NotificationsHandler.coffee @@ -61,3 +61,13 @@ module.exports = timeout:oneSecond logger.log user_id:user_id, notification_id:notification_id, "sending mark notification as read to notifications api" makeRequest opts, callback + + # removes notification by key, without regard for user_id, + # should not be exposed to user via ui/router + markAsReadByKeyOnly: (key, callback)-> + opts = + uri: "#{settings.apis.notifications?.url}/notification/key/#{key}" + method: "DELETE" + timeout: oneSecond + logger.log {key:key}, "sending mark notification as read with key-only to notifications api" + makeRequest opts, callback diff --git a/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee b/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee index cfca6dfebe..ac1d57d1f5 100644 --- a/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Notifications/NotificationsHandlerTests.coffee @@ -68,4 +68,17 @@ describe 'NotificationsHandler', -> args.timeout.should.equal 1000 expectedJson = {key:@key, templateKey:@templateKey, messageOpts:@messageOpts} assert.deepEqual(args.json, expectedJson) - done() \ No newline at end of file + done() + + describe "markAsReadByKeyOnly", -> + beforeEach -> + @key = "some key here" + + it 'should send a delete request when a delete has been received to mark a notification', (done)-> + @handler.markAsReadByKeyOnly @key, => + opts = + uri: "#{notificationUrl}/notification/key/#{@key}" + timeout:1000 + method: "DELETE" + @request.calledWith(opts).should.equal true + done()