Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
Add channel parameter to 3 subscription related redirect Urls; fixes #65
Browse files Browse the repository at this point in the history
  • Loading branch information
f-w committed Jan 29, 2020
1 parent e64153d commit f8bc363
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions common/models/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ module.exports = function(Subscription) {
if (anonymousUnsubscription.acknowledgements.onScreen.redirectUrl) {
var redirectUrl =
anonymousUnsubscription.acknowledgements.onScreen.redirectUrl
redirectUrl += `?channel=${this.channel}`
return await options.httpContext.res.redirect(redirectUrl)
} else {
options.httpContext.res.setHeader('Content-Type', 'text/plain')
Expand Down Expand Up @@ -530,7 +531,8 @@ module.exports = function(Subscription) {
if (anonymousUnsubscription.acknowledgements.onScreen.redirectUrl) {
var redirectUrl =
anonymousUnsubscription.acknowledgements.onScreen.redirectUrl
redirectUrl += '?err=' + encodeURIComponent(error)
redirectUrl += `?channel=${this.channel}`
redirectUrl += '&err=' + encodeURIComponent(error)
return await options.httpContext.res.redirect(redirectUrl)
} else {
options.httpContext.res.setHeader('Content-Type', 'text/plain')
Expand All @@ -556,7 +558,7 @@ module.exports = function(Subscription) {
this.serviceName
)

async function handleConfirmationAcknowledgement(err, message) {
let handleConfirmationAcknowledgement = async (err, message) => {
if (!mergedSubscriptionConfig.confirmationAcknowledgements) {
if (err) {
throw err
Expand All @@ -566,8 +568,9 @@ module.exports = function(Subscription) {
var redirectUrl =
mergedSubscriptionConfig.confirmationAcknowledgements.redirectUrl
if (redirectUrl) {
redirectUrl += `?channel=${this.channel}`
if (err) {
redirectUrl += '?err=' + encodeURIComponent(err.toString())
redirectUrl += '&err=' + encodeURIComponent(err.toString())
}
return await options.httpContext.res.redirect(redirectUrl)
} else {
Expand Down Expand Up @@ -665,6 +668,7 @@ module.exports = function(Subscription) {
)
if (anonymousUndoUnsubscription.redirectUrl) {
var redirectUrl = anonymousUndoUnsubscription.redirectUrl
redirectUrl += `?channel=${this.channel}`
return await options.httpContext.res.redirect(redirectUrl)
} else {
options.httpContext.res.setHeader('Content-Type', 'text/plain')
Expand Down Expand Up @@ -696,7 +700,8 @@ module.exports = function(Subscription) {
} catch (err) {
if (anonymousUndoUnsubscription.redirectUrl) {
var redirectUrl = anonymousUndoUnsubscription.redirectUrl
redirectUrl += '?err=' + encodeURIComponent(err.message || err)
redirectUrl += `?channel=${this.channel}`
redirectUrl += '&err=' + encodeURIComponent(err.message || err)
return await options.httpContext.res.redirect(redirectUrl)
} else {
options.httpContext.res.setHeader('Content-Type', 'text/plain')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notification",
"version": "1.12.0",
"version": "1.13.5",
"dbSchemaVersion": "0.6.0",
"main": "server/server.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions spec/app/subscription.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ describe('DELETE /subscriptions/{id}', function() {
)
.set('Accept', 'application/json')
expect(res.statusCode).toBe(302)
expect(res.header.location).toBe('http://nowhere')
expect(res.header.location).toBe('http://nowhere?channel=email')
res = await app.models.Subscription.findById(data[3].id)
expect(res.state).toBe('deleted')
})
Expand Down Expand Up @@ -768,7 +768,7 @@ describe('DELETE /subscriptions/{id}', function() {
)
.set('Accept', 'application/json')
expect(res.statusCode).toBe(302)
expect(res.header.location).toBe('http://nowhere?err=Error%3A%20Forbidden')
expect(res.header.location).toBe('http://nowhere?channel=email&err=Error%3A%20Forbidden')
})

it('should display onScreen acknowledgements failureMessage', async function() {
Expand Down Expand Up @@ -1023,7 +1023,7 @@ describe('GET /subscriptions/{id}/unsubscribe/undo', function() {
'/unsubscribe/undo?unsubscriptionCode=50032'
)
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('http://nowhere')
expect(res.headers.location).toBe('http://nowhere?channel=email')
res = await app.models.Subscription.findById(data[0].id)
expect(res.state).toBe('confirmed')
})
Expand Down

0 comments on commit f8bc363

Please sign in to comment.