-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laushinka/let people unsubscribe 4761 #5281
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
components/server/src/user/newsletter-subscription-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import * as express from 'express'; | ||
import { inject, injectable } from "inversify"; | ||
import { UserDB } from "@gitpod/gitpod-db/lib"; | ||
import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics"; | ||
|
||
@injectable() | ||
export class NewsletterSubscriptionController { | ||
@inject(UserDB) protected readonly userDb: UserDB; | ||
@inject(IAnalyticsWriter) protected readonly analytics: IAnalyticsWriter; | ||
|
||
get apiRouter(): express.Router { | ||
const router = express.Router(); | ||
|
||
router.get("/unsubscribe", async (req: express.Request, res: express.Response) => { | ||
const email: string = req.query.email; | ||
const newsletterType: string = req.query.type; | ||
const acceptedNewsletterTypes: string[] = ["changelog", "devx"]; | ||
const newsletterProperties: {[key:string]: {[key: string]: string}} = { | ||
changelog: { | ||
property: "unsubscribed_changelog", | ||
value: "allowsChangelogMail" | ||
}, | ||
devx: { | ||
property: "unsubscribed_devx", | ||
value: "allowsDevXMail" | ||
} | ||
} | ||
|
||
if (!acceptedNewsletterTypes.includes(newsletterType)) { | ||
res.sendStatus(422); | ||
return; | ||
} | ||
|
||
try { | ||
// Not all newsletter subscribers are users, | ||
// therefore the email address is our starting point | ||
const user = (await this.userDb.findUsersByEmail(email))[0]; | ||
const successPageUrl: string = 'https://www.gitpod.io/unsubscribe'; | ||
|
||
if (user && user.additionalData && user.additionalData.emailNotificationSettings) { | ||
await this.userDb.updateUserPartial({ | ||
...user, | ||
additionalData: { | ||
...user.additionalData, | ||
emailNotificationSettings: { | ||
...user.additionalData.emailNotificationSettings, | ||
[newsletterProperties[newsletterType].value]: false | ||
} | ||
} | ||
}); | ||
this.analytics.identify({ | ||
userId: user.id, | ||
traits: { | ||
[newsletterProperties[newsletterType].property]: true | ||
} | ||
}); | ||
res.redirect(successPageUrl); | ||
} | ||
|
||
else { | ||
this.analytics.identify({ | ||
userId: email, | ||
traits: { | ||
[newsletterProperties[newsletterType].property]: true | ||
} | ||
}); | ||
res.redirect(successPageUrl); | ||
} | ||
} catch (error) { | ||
res.send({ | ||
err: error.status, | ||
message: error.message | ||
}); | ||
return; | ||
} | ||
}) | ||
|
||
return router; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we would like to use this API to subscribe newsletter users so that they are automatically attached to their user accounts if a the email for the newsletter signup matches any user's primary email. is it ok for you to extend the scope of this PR to include a
/subscribe
endpoint that signs up a known or unknown user for a specified subscription list?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep the existing scope of this ticket for reasons of: 1) planning and 2) transparency :) When tickets are approved and put to in progress, I assume there are already plans and estimations of how much effort the current ticket/board would take. Changing the scope might change the planning for the rest of the board. Secondly, a changing scope almost at the end of the work might not be known to the stakeholders of the board.
However, I am still learning how the team usually manages their projects so I will tag @JanKoehnlein here for his thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open another ticket for @jakobhero's request. I feel like it has to be discussed in terms of security and GDPR as well.