Commit Graph

6002 Commits

Author SHA1 Message Date
Hannah Wolfe
1fbb8a219f
Removed API versioning from webhooks
refs: https://github.com/TryGhost/Toolbox/issues/229
refs: https://github.com/TryGhost/Toolbox/issues/283

- we are getting rid of the concept of having multiple api versions in a single ghost install
- we'll update webhooks to return a content version
- we're also looking into if we need some sort of accept-version type logic
2022-04-28 15:37:09 +01:00
Hannah Wolfe
923d436f11
Removed API versioning from email serialization
refs: https://github.com/TryGhost/Toolbox/issues/229

- we are getting rid of the concept of having multiple api versions in a single ghost install
- we no longer need to worry about what version of the API we should use to send content
- this, as with all of our api versioning logic, was questionable anyway, and mostly just unnecessary complexity
2022-04-28 15:37:06 +01:00
Hannah Wolfe
5eaa1938c7
Removed versioned confg from URL Service
refs: https://github.com/TryGhost/Toolbox/issues/228
refs: https://github.com/TryGhost/Toolbox/issues/229

- we are getting rid of the concept of having multiple api versions in a single ghost install
- this means the url service doesn't need to be versioned any more
2022-04-28 15:35:28 +01:00
Hannah Wolfe
608258747a
Removed versioned routing configs
refs: https://github.com/TryGhost/Toolbox/issues/228

- we are getting rid of the concept of having multiple api versions in a single ghost install
- we no longer need versioned routing configs
2022-04-28 15:35:28 +01:00
Hannah Wolfe
8bd9169298
Removed res.locals.apiVersion
- we are getting rid of the concept of having multiple api versions in a single ghost install
- we no longer need to pass the apiVersion around using res.locals
- To simplify code that uses our frontend proxy the proxy now _only_ exposes canary
2022-04-28 15:35:28 +01:00
Hannah Wolfe
4332546a56
Removed theme engines API versioning concept
refs: https://github.com/TryGhost/Toolbox/issues/228

- we are getting rid of the concept of api versions from Ghost
- this means getting rid of them from the frontend as well, and from themes
2022-04-28 15:35:27 +01:00
Hannah Wolfe
9a0d143fb1 Disabled version compatibility emails temporarily
refs: https://github.com/TryGhost/Toolbox/issues/292

- we shouldn't send these emails in 4.x
2022-04-28 15:22:05 +01:00
Rishabh Garg
c7b247a079
Added member endpoints for managing newsletter subscriptions (#14624)
refs TryGhost/Team#1495

With multiple newsletters, members are allowed to manage their newsletter pref via email unsubscribe link with member uuid. Since Portal needs to manage member's newsletter pref via their UUID, we need new endpoints on members that allow fetch/update of newsletter subscriptions via only uuid. The endpoints return only limited data for a member that are needed for the UI.

- adds endpoint to fetch newsletter subscriptions for member via uuid
- adds endpoint to update newsletter subscriptions for member via uuid
2022-04-28 17:14:17 +05:30
Aileen Nowak
7dead9be5c Set importer context for members importer
no issue
needs 82eb861955

Set the context to `importer` for any members importer actions which will determine the correct source of origin in the members events table
2022-04-28 12:10:44 +01:00
CommanderRoot
adc0805dce
replaced deprecated String.prototype.substr() (#14367)
- `.substr()` is deprecated so we replace it with .slice() which works similarly but isn't deprecated

Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
2022-04-28 11:49:12 +01:00
Matt Hanley
923477eb6f Fixed issue with creation of multiple newsletters
- Newsletter defaults were a static object with the default UUID resolved once
- This caused conflicts on subsequent create requests
- Defaults are now resolved as a function so each call gets a new UUID
2022-04-28 11:30:20 +01:00
Renovate Bot
b58e7af65e Updated dependency express-jwt to v7
- also requires a small change to the imports to reflect an API change
2022-04-28 11:15:04 +01:00
Simon Backx
efdc42c257
Fixed bulk unsubscribe and updated member import tests (#14610)
refs https://github.com/TryGhost/Team/issues/1567

**Changes in members-api**
- Compare changes: https://github.com/TryGhost/Members/compare/%40tryghost/members-api%406.1.0...%40tryghost/members-api%406.2.2
- Fixed bulk unsubscribe
- Deletes the newsletter relations instead of setting subscribed to false

**Test fail fix**
refs https://github.com/TryGhost/Ghost/pull/14621
refs https://ghost.slack.com/archives/C02G9E68C/p1651126990299689?thread_ts=1651072733.859939&cid=C02G9E68C

- Events didn't always have the same created_at as created members
- This caused a test to fail randomly in the main repo

**Changes**
- Added required helpers for members-api package
- Version bumps of other packages are only tooling related

**Tests**
- Tests if member import still works with the legacy `subscribed` flag
- Updated member importer to use multipleNewsletters flag
- Dropped legacy members tests
2022-04-28 09:50:05 +02:00
Daniel Lockyer
7583d379be
Revert "Dropped nullable from subscribe events' newsletter id (#14598)"
This reverts commit dc12e6490a.
2022-04-27 20:01:32 +01:00
Thibaut Patel
f5bd647100
Updated emails to use newsletter settings (#14588)
refs https://github.com/TryGhost/Team/issues/1550

- Updated email template and seder options to use the settings specified for the related newsletter
- Falls back to the default newsletter, and uses the default newsletter settings for the publishing preview because we only assign a newsletter at the point a post is published

Co-authored-by: Thibaut Patel <thibaut.patel@gmail.com>
Co-authored-by: Matt Hanley <git@matthanley.co.uk>
2022-04-27 18:48:36 +01:00
Fabien 'egg' O'Carroll
810c3077e8
Wired up LimitService to NewsletterService (#14602)
refs https://github.com/TryGhost/Team/issues/1549

This allows us to restrict certain sites to a single newsletter
2022-04-27 17:44:16 +01:00
Simon Backx
dc12e6490a
Dropped nullable from subscribe events' newsletter id (#14598)
refs https://github.com/TryGhost/Team/issues/1478

- Depends on https://github.com/TryGhost/Ghost/pull/14597
- Column shouldn't be nullable now it is filled correctly
2022-04-27 17:52:31 +02:00
Simon Backx
d05c6f84ca
Added migration that backfills newsletter_id on all subscribe events (#14597)
refs https://github.com/TryGhost/Team/issues/1478

Sets the newsletter_id to the id of the default newsletter.
2022-04-27 17:52:06 +02:00
Simon Backx
2cf76cb031
Added newsletter relation to subscribe events (#14585)
refs https://github.com/TryGhost/Team/issues/1478

**Changes**
- Added the newsletter relation to subscribe events

**Changes in `members-api`**
- Compare: https://github.com/TryGhost/Members/compare/%40tryghost/members-api%406.0.0-alpha.0...%40tryghost/members-api%406.0.0
- Makes sure the newsletter relation is returned in the activity feed for susbcribe events (aka newsletter events).

**Tests**
- Added first test for activity feed to check if the newsletter relation is correctly fetched
2022-04-27 16:44:27 +02:00
Fabien 'egg' O'Carroll
d94859f2e5
Added /stats/subscriptions API (#14547)
refs https://github.com/TryGhost/Team/issues/1505
refs https://github.com/TryGhost/Team/issues/1466

Exposes an API for historical counts broken down by tier and cadence.

Counts backwards from the current stats like MRR to minimize inaccruate
data due to missing/superfluous events.
2022-04-27 14:53:32 +01:00
Rishabh Garg
756f86dbdc
Added uuid to newsletter schema (#14600)
refs https://github.com/TryGhost/Team/issues/1561

With multiple newsletters, unsubscribe links will also need to have a unique reference to the newsletter that the email is for, so that we can unsubscribe members from the particular newsletter automatically when they click on the link.
As our existing pattern for members is to use UUID as the external unique reference, this change adds UUID to newsletter schema and populates the existing newsletters with a UUID value.

- adds new `uuid` column to newsletter schema
- updates newsletter model to add default uuid
- updates default newsletter migration to add `uuid`
- drops nullable on `uuid` column later in migrations once we have populated existing newsletters
2022-04-27 19:20:25 +05:30
Hannah Wolfe
61dc52972f Added validations to table creation
- These are not enforced at the DB level, so don't matter here, but adding for consistency / cleanliness
2022-04-26 15:51:02 +01:00
Hannah Wolfe
37a684c2c5 Added explicit enum to newsletters.status
closes: https://github.com/TryGhost/Team/issues/1553

- we want to be explicit in what values are supported
- we want the values that are supported to be supported to also be explicit and clear
- without this API users can set the value to anything and the active/not active logic will work, until such time as we introduce further statuses
- this means introducing a new status could be a potential breaking change and lands us in horrible hot water
2022-04-26 15:51:02 +01:00
Rishabh Garg
4f3743bb60
Added cache invalidation on updating newsletters (#14587)
- allows portal/apis to not show stale newsletter information
2022-04-26 18:06:41 +05:30
Matt Hanley
c1d4d9ccc6 Reinstated transaction for creating and assigning members to newsletters 2022-04-26 13:13:54 +01:00
Hannah Wolfe
327c209a74 🐛 Added default sort order for members.browse
refs: https://github.com/TryGhost/Team/issues/1557

- There is currently no default order for the members API
- This is done at the API level purely for the endpoint, not in the model using orderDefaultOptions
- This is because orderDefaultOptions affects findPage and findPage is wrapped by membersAPI.members.list
- That in turn is used in multiple places, e.g. getting member counts for emails and getting members for exports
- There is currently no created_at DESC index on the table, so we don't to impact performance too much
- This ensures it's only affected when paginating
2022-04-26 13:02:27 +01:00
Simon Backx
32b0f69e55 Added newsletters to subscribe events (#14579)
refs https://github.com/TryGhost/Team/issues/1478

- Moved all admin API members tests to enable the multiple newsletters flag
- Checks if the susbcribe events are added correctly when adding or removing newsletters
- Checks if susbcribe events are added for default newsletters
2022-04-26 12:31:34 +01:00
Thibaut Patel
7422f3e64d Moved to using newsletter design settings in email serializer (#14562)
refs https://github.com/TryGhost/Team/issues/1550

- Switched to using the newsletter design settings over the global settings
- Made the `newsletter_id` property available in the Admin API Post resource
- Added the `showHeaderName` variable that can be used in the post html template
2022-04-26 12:31:34 +01:00
Simon Backx
ce5f55e43f Fixed created_at newsletter migration (#14568)
refs https://github.com/TryGhost/Team/issues/1551

- Updated existing migration to insert a nullable created_at column
- Added a migration to update all the created_at values to now
- Added a migration to drop nullable
- Also includes new helper methods to set and drop nullable
2022-04-26 12:31:34 +01:00
Matt Hanley
5f31f52139 Allow opt-in for existing members when creating a newsletter (#14567)
- Added changes to opt-in existing members for new newsletters

Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-04-26 12:31:34 +01:00
Hannah Wolfe
6e92229a07 Remapped member.subscribed value using newsletter subscriptions (#14563)
refs https://github.com/TryGhost/Team/issues/1545

- Remapped `member.subscribed` value based on newsletter subscriptions in API output
- Enabled filtering by subscribed status for multiple newsletters

Co-authored-by: Matt Hanley <git@matthanley.co.uk>
2022-04-26 12:31:34 +01:00
Matt Hanley
8662252ae1 Updated default newsletter model sort order (#14571)
refs https://github.com/TryGhost/Team/issues/1552

- The API doesn't enforce a unique sort order but we infer the "default newsletter" based on ordering so we need to ensure a consistent and deterministic ordering behaviour
2022-04-26 12:31:34 +01:00
Rishabh Garg
f9eff8a216 Updated admin route for newsletter settings (#14576) 2022-04-26 12:31:34 +01:00
Rishabh Garg
05b5059918 Updated portal to manage single newsletter with existing UI (#14573)
refs https://github.com/TryGhost/Team/issues/1554

- bumps portal to manage single site newsletter with old subscribe UI
- adds unit test for portal site endpoint
2022-04-26 12:31:34 +01:00
Thibaut Patel
ed29c7addf Filtered member email recipients based on the newsletter subscriptions (#14489)
refs https://github.com/TryGhost/Team/issues/1524

- We need to fetch the post newsletter to grab the slug as it's needed for the member NQL filter.
- We can then use the newsletter slug and append it in the existing member NQL filter.
- Removed `subscribed:true` when an email is sent to a newsletter and replaced it with the newsletter id
- Added `status:-free` when an email is sent to a newsletter with `visibility` set to `paid`
- Added tests what happens when you publish without newsletter_id
- Added tests what happens when you publish with newsletter_id

Co-authored-by: Simon Backx <simon@ghost.org>
2022-04-26 12:31:34 +01:00
Thibaut Patel
48799e1c68 Added the newsletter API ?include=count.posts and ?include=count.members query options (#14525)
refs https://github.com/TryGhost/Team/issues/1524

- This enables admins in the ghost admin to have an overview of the total posts/members associated with a newsletter.
- Follows the `?include=count.x` convention used by other resources
2022-04-26 12:31:34 +01:00
Matt Hanley
d4700e048a Mapped subscribers to newsletter (#14518)
Closes https://github.com/TryGhost/Team/issues/1508
Refs https://github.com/TryGhost/Ghost/pull/14468

- Maps existing subscribers to the default newsletter

A note on performance:
We loop over the rows in a potentially large table (members) but I've minimised the impact by limiting the columns we fetch. The alternative is a raw SQL query like the one below: the SQL version takes ~0.9s vs ~1.1s for the migration (my laptop, ~30k members). The disadvantage of the raw SQL implementation is the approximation of the ObjectID (instead of a legit bson ID) which isn't sequential and may impact index size/performance.

```sql
insert into members_newsletters (id, member_id, newsletter_id)
    select
        substr(replace(uuid(),'-',''),1,24),
        id,
        '62595dcbfad4e031d85d166f'
    from members
    where members.subscribed=true;
```
2022-04-26 12:31:34 +01:00
Rishabh Garg
a330165e4f Handled email unsubscribe with multiple newsletters (#14560)
refs https://github.com/TryGhost/Team/issues/1495

- removes subscription from all newsletters for a member on click of unsubscribe link in email
- allows the new multiple newsletter system to work with existing unsubscribe flow
2022-04-26 12:31:34 +01:00
Matt Hanley
2d27c9d42a Added a down() operation to newsletters
- Without the down operation, the previous migration fails to re-add the
created_at column after a rollback
2022-04-26 12:31:34 +01:00
Simon Backx
69f31074e0 Updated default newsletter migration for created_at
refs https://ghost.slack.com/archives/C02G9E68C/p1650632604790259?thread_ts=1650619639.619819&cid=C02G9E68C

The new column needs to be included in the migration explicitly, since there is no default in the database (and we don't use the model).
2022-04-26 12:31:34 +01:00
Simon Backx
50ab1e0d73 Added created_at/updated_at to newsletters (#14559)
no issue

Added the missing timestamps to the newsletters table
2022-04-26 12:31:34 +01:00
Thibaut Patel
c49d2d0b7e Fixed the newsletter_id assignement in the post API (#14485)
refs https://github.com/TryGhost/Team/issues/1502

- Assigned posts to the default newsletter when sent as email
2022-04-26 12:31:34 +01:00
Simon Backx
c15cb1b5be Added newsletter_id column to subscribe events (#14553)
refs https://github.com/TryGhost/Team/issues/1478

The `newsletter_id` is nullable for now to remain compatible until we have a proper data migration + updated code to set it on inserts
2022-04-26 12:31:34 +01:00
Thibaut Patel
c8230060a9 Added the default newsletter (#14468)
refs https://github.com/TryGhost/Team/issues/1473

- Added the default newsletter
- We use the title to populate the newsletter same, slug and sender name
- We use the description to populate the newsletter description
- We use the global design settings to populate the corresponding newsletter design settings

Co-authored-by: Matt Hanley <git@matthanley.co.uk>
2022-04-26 12:31:34 +01:00
Kevin Ansfield
a8687b35b9 Added newsletter from address verification (#14491)
refs https://github.com/TryGhost/Team/issues/1498
refs https://github.com/TryGhost/Team/issues/584

- Added newsletter `from` address verification

Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-04-26 12:31:34 +01:00
Matt Hanley
298599ce91 Added show_header_name column to newsletters table
refs https://github.com/TryGhost/Team/issues/1532

- Added before the migration in https://github.com/TryGhost/Ghost/pull/14468 to populate the default newsletter
- The fixture for the default newsletter has a different value than the model and schema default
- This is because by default the newsletter name is the same as the site title, and the site title is already shown
2022-04-26 12:31:34 +01:00
Naz
f5937c6f65 Refactored destroyUser method to async/await
refs https://github.com/TryGhost/Toolbox/issues/268

- Before doing a functional change to this method wanted to make sure it's more readable to keep better track of changes
2022-04-25 10:50:04 +08:00
Naz
2d92e98392 Added a note about unusual implemenation
refs https://github.com/TryGhost/Toolbox/issues/280

- When passing the sendEmail parameter with a boutnd 'send' method the e2e tests were failing becuase mock mailer did not pick up the send method. Using this slightly more verbose implementation as it "just works". Could be rewritten into something nicer if there's such a need in the future
2022-04-22 16:31:56 +08:00
Naz
7b9a80fbf4 Extracted data access code to external module
refs https://github.com/TryGhost/Toolbox/issues/280

- Keeps the code in the core to the minimum. Ideally we should not be adding any logic apart form "hooking things together"
2022-04-22 16:31:56 +08:00
Naz
cc71bbfd61 Hooked up api version compatibility middleware
refs https://github.com/TryGhost/Toolbox/issues/280

- ctd of putting pieces together to allow Ghost notifying owner and admin users about version mismatch errors
-  The `@tryghost/mw-api-version-mismatch` in a combination with api version compatibility service make the whole notification process play nicely :)
- The flow of the logic from the request to a sent notification email is following:
1. Request comes is with an Accept-Version header that's behind current Ghost version and is not supported
2. mw-error-handler middleware's 'resourceNotFound' detects such request and returns a 406 with a special 'code' identifying if the version of the client is ahead or behind
3. mw-api-version-mismatch intercepts the 406 request with "code === 'UPDATE_CLIENT'` and calls up APIVersionCompatibilityService
4. emails are sent out to active owner and admin users

- The above flow is also illustratd in the e2e tests that come with the changeset
2022-04-22 16:31:56 +08:00