Commit Graph

10493 Commits

Author SHA1 Message Date
Daniel Lockyer
8473298072
Renamed /email_preview API endpoint to /email_previews
refs https://github.com/TryGhost/Toolbox/issues/308

- we have a pattern of using plurals for API endpoints but it was missed
  when we implemented email previews
- this fixes that for v5 and updates the tests accordingly
- there's some cleanup here to fix the API controller name too which
  I'll add to the list
2022-04-28 15:37:10 +01:00
Daniel Lockyer
10874100ef
Deleted mail/ Admin API endpoint
refs https://github.com/TryGhost/Toolbox/issues/308

- this endpoint isn't used by Admin, nor Ghost, and isn't documented
  publicly
- we are nuking it in v5 so the easiest step to achieve that is by
  removing the API route mounts
- there's plenty of cleanup here, including refactoring other API
  controllers to avoid using the `mail` API controller, but this is the
  easiest way to achieve what we want
2022-04-28 15:37:10 +01:00
Daniel Lockyer
b788604e15
Added erroring migrations to the final minor of deleted majors
refs https://github.com/TryGhost/Toolbox/issues/300

- the previous commit deleted all v1/v2/v3 migrations
- Ghost-CLI forces you to update to the latest minor in your major
  before you upgrade but people who aren't on the latest minor, who don't
  use Ghost-CLI and try to update to v5 might have missed migrations that
  I've just deleted
- the way to protect against this is to add some migrations for the last
  minor in each major, that will throw an error if they get run
- this uses a feature of knex-migrator where it will always try to
  backfill missing migrations when you run Ghost, so these new migrations
  should _only_ be run if the Ghost DB hasn't already run the same number
  of migrations in that minor
- by throwing an error, it'll cause knex-migrator to fail and the user
  shouldn't be able to update, which is good
- v2 and v3 only have 1 migration so I can just replace that, but v1 has
  2 migrations. I think it makes more sense that the first one errors
  and the second one is a no-op otherwise it'll run the first migration,
  succeed, run the second, error, and then rollback the second and first
  one
- the new migration names are different from the original ones but that
  shouldn't matter because we're not comparing nor storing them
2022-04-28 15:37:10 +01:00
Daniel Lockyer
145dc4651a
Deleted all v1/v2/v3 migrations
refs https://github.com/TryGhost/Toolbox/issues/300

- due to Node compatibility, it only makes sense that users on the latest
  v3 (and v4) can update to v5
- therefore, we don't need v1/2/3 migrations as it's more maintenance in
  the long run
- this deletes over 5000 lines of code (!!)
2022-04-28 15:37:10 +01:00
Hannah Wolfe
19852de5cb
Removed config and bluebird from ghost-server
- In the interest of simplifying and cleaning up this code which affects Ghost's boot process
- Moved config to DI, injecting only known properties. It's expected that you must restart the server to pick up new config
   - Even in tests!
- Got rid of unused bluebird code, but also reworked some promise-based code to be simpler using util.promisify
2022-04-28 15:37:10 +01:00
Hannah Wolfe
3c60ac6e90
Removed socket option from ghost-server
- As far as we know this is no longer used by anyone
- It was added by a contributor many moons ago, before we had Ghost CLI
- As we're prepping to ship a stripped-back 5.0, this seemed like a great deletion candidate.
- If anyone used it, they can add it back in with tests :)
2022-04-28 15:37:09 +01:00
Hannah Wolfe
9a14c2de4c
Removed sync method from route settings loader
refs: cf514cdf7

- in commit cf514cdf7 we moved the loadSettings call up to the bridge
- here we can call the async method, so we can remove loadSettingsSync altogether
- all the tests have now been changed to use the async method
2022-04-28 15:37:09 +01:00
Hannah Wolfe
56af742a0b
Moved frontend reloading logic into bridge
- following on from removing api versioning logic from the frontend, it's possible to make more sense of what's happening
- this commit first introduces a proper jsdoc'd object that gets passed through the frontent load & reload flow
- that object contains the urlService and optionally our routeSettings processed from routes.yaml
- additionally, we were passing around a start boolean, which told the routerManager whether to just init, or init+start
- with this refactor, we always pass in the routeSettings when we want to do init+start, so we no longer need a boolean

- The refactor itself moves logic from the reload function in site.js and urlservice + routesettings fetching logic from routes.js
    into the reloadFrontend function in bridge.js.
- This makes it clearer to see what happens when we call reloadFrontend.
- This commit also makes it clearer to see what is happening with the route settings, where they are needed and why
- Ideally we'd also clean up the weird dupliated logic and somewhat unnecessary routes.js file
2022-04-28 15:37:09 +01:00
Hannah Wolfe
a4a9ba7940
🔥 Removed versioned APIs
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
- removed all the code for multiple api versions & left canary wired up, but without the version in the URL
- TODO: reorganise the folders so there's no canary folder when we're closer to shipping
        we need to minimise the pain of merging changes across from main for now
2022-04-28 15:37:09 +01:00
Hannah Wolfe
d7ff49dc88
Removed API versioning from post scheduling service
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 schedulei content
- this, as with all of our api versioning logic, was questionable anyway, and mostly just unnecessary complexity
2022-04-28 15:37:09 +01:00
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
Daniel Lockyer
afcb975696 Updated Admin to v4.46.0 2022-04-28 15:29:18 +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
Rishabh
2c2099b87f Added homepage redirect for unsubscribe urls
refs https://github.com/TryGhost/Team/issues/1495

With multiple newsletters, members are allowed to manage their newsletter pref via email unsubscribe link with member uuid. Since Portal is now taking over handling unsubscribe for members, we don't need to keep the current `/unsubscribe` page as Portal can load the member's newsletter pref on site home page directly.
The redirect change is only enabled behind the `multipleNewslettersUI` flag as its in beta.
2022-04-28 11:49:20 +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
Ghassan Maslamani
aacb30e35e
🐛 Fixed missing alt on AMP images (#14453)
closes: #14440 

- use best available values to provide alt tags on images in amp.hbs
- this prevents certain tools from reporting errors/warnings with our amp pages
2022-04-28 11:33:22 +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
Matt Hanley
db65c7d04e Promoted multiple newsletters UI labs flag to private beta
- Promoted the flag to beta to allow manual enabling via the database
- The UI for this flag is intentionally still gated behind developer experiments in Admin
2022-04-28 10:54:59 +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
Matt Hanley
b2e36b2f6f
Promoted multiple newsletters flag (backend) to GA (#14609)
refs https://github.com/TryGhost/Team/issues/1566
2022-04-27 19:02:56 +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
Daniel Lockyer
11799b048b Updated Admin to v4.45.0 2022-04-22 16:00:32 +01: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
Naz
b56557ea04 Hooked up api version compatibility service
refs https://github.com/TryGhost/Toolbox/issues/280

- This is continuation of putting pieces together to allow Ghost notifying owner and admin users about version mismatch errors
-  This changeset adds the api-version-compatibility intialization during the boot (needed to be able to pospone the send email initialization so that it's testeable from the e2e tests)
- There's also a data service which handles fetching/saving notifications and fetching emails of users that should be notified
2022-04-22 16:31:56 +08:00
Rishabh
05583d254f Added multiple newsletters UI feature flag 2022-04-22 12:40:51 +05:30
Fabien 'egg' O'Carroll
19a08cd11d
Replaced stats service with @tryghost/stats-service (#14527)
- Pulls logic out of Ghost core and into the Analytics repository.
- Test coverage has increased for the stats service
- Interface simplified
2022-04-21 14:57:07 +01:00
Naz
1ecb837981 Added version_notifications key to settings table
refs https://github.com/TryGhost/Toolbox/issues/292

- When version missmatch handling is done in Ghost we need to store the 'Accept-Version' header values that have been already processed in the past (to avoid sending notifications about the same mismatch multiple times)
- The `version_notifications` will be storing an array with handled versions like so: `['v3.44', 'v4.23', 'v4.39']`.
- The emailing logic and processing is slightly similar to how "notification" key is handled, that's why I've placed the definition of this new key close by.
2022-04-21 20:34:19 +08:00
Simon Backx
9def4e6edc
Added migration to backfill offer ids in subscriptions (#14511)
refs https://github.com/TryGhost/Team/issues/1520

- Sets the `offer_id` in the `members_stripe_customers_subscriptions` table based on the `offer_redemptions` that have the same tier and cadence
- We currently use the same subscription <-> offer linking when viewing a member
- The MySQL query is quite optimized in a single UPDATE query, but in SQLite we'll need to run (maximum) one UPDATE query for every offer (not per subscription).
- Best to merge this migration in 4.x (not in 5.0) because it is better (less error prone) to run this migration before starting to fill the offer_id field for updated migrations instead of after (https://github.com/TryGhost/Ghost/pull/14488)
- We need the SQLite migration for sites that will only migrate to MySQL at 5.0
2022-04-21 11:45:24 +02:00
Thibaut Patel
52a855f314
Added the newsletter read endpoint (#14520)
refs https://github.com/TryGhost/Team/issues/1533

- Retrieves one newsletter
- Makes the newsletter resource consistent with the other resources
- Solves an issue with the admin expecting the route to exist
2022-04-21 09:59:44 +02:00
Kevin Ansfield
05da593516 Added publishingFlow labs flag
no issue

- alpha flag for testing a rework of the publishing flow in Admin
2022-04-20 16:20:01 +01:00
Thibaut Patel
ae664e9cad
Added newsletter read permission (#14519)
refs https://github.com/TryGhost/Team/issues/1533

- Needed to create the read newsletter endpoint to make the newsletter resource more consistent with the other resources
- Read is available to admins like other newsletter actions
2022-04-20 15:25:41 +02:00
Rishabh
5a2219bec3 Removed archived newsletters from Portal settings
Archived newsletters won't be shown in Portal for selection, this change filters to only include active newsletters in Portal settings.
2022-04-20 14:18:42 +05:30
Rishabh
6092b31c40 Refined newsletter selection in Portal UI 2022-04-20 14:18:27 +05:30
Simon Backx
a3215a6edf
Updated calculation of MRR history to use mrr column (#14481)
refs https://github.com/TryGhost/Team/issues/1518

- Uses mrr column now
- Doesn't account for `cancel_at_period_end` until a migration fixes the MRR values: https://github.com/TryGhost/Ghost/pull/14480
2022-04-19 17:07:20 +02:00
Hannah Wolfe
9e8de9ab01
Moved cors middleware to own file
- This cors middleware function has been stuck at the top of the site file for a while
- Move it to it's own file in keeping with our usual patterns for middleware
2022-04-19 11:19:59 +01:00
Hannah Wolfe
1d121c52f4
Replaced white/black list terminology
refs 92986b77e3

- I thought we did this a while ago, but uses in comments and elsewhere in the codebase were missed
2022-04-19 11:19:59 +01:00
Daniel Lockyer
7ac7652dd9 Updated Admin to v4.44.0 2022-04-15 16:00:39 +01:00
Simon Backx
9b23424e48
Added offer_id column to members_stripe_customers_subscriptions (#14487)
refs https://github.com/TryGhost/Team/issues/1519

Migration that adds the (nullable) offer_id column to members_stripe_customers_subscriptions.
- New reliable way to know which offer is active for a given subscription (currently we compare the tier and cadence in offer redemptions)
- We'll create a separate migration to backfill all the offer_ids, but only after we updated the code to also store them correctly for new or updated subscriptions (https://github.com/TryGhost/Team/issues/1520)
- Allows us to backfill the MRR of all subscriptions to account for forever offers
2022-04-15 13:47:15 +02:00
Rishabh Garg
1362750640
Updated newsletter fixtures to remove nullable sender name (#14479)
refs https://github.com/TryGhost/Team/issues/1513

Since `sender_name` for newsletter is now nullable field, this change removes hardcoded `sender_name` from fixtures.
2022-04-14 23:45:59 +05:30
Sam Lord
5d62758e64 Fixed verification trigger for imports
refs: https://github.com/TryGhost/Toolbox/issues/293

This import verification check now works by testing all imports in the last 30 days.
2022-04-14 16:04:26 +01:00
Rishabh Garg
5218cf194d
Updated newsletter sender name column as nullable (#14476)
refs TryGhost/Team#1513

- nullable `sender_name` allows us to use auto fallback of site title for sender name without setting any explicit value for it.
2022-04-14 17:42:20 +05:30
Naz
fa82722b03 Uppercased Content-Version header use
refs https://github.com/TryGhost/Toolbox/issues/227

- The convention across the codebase is to define headers with capitalized first letters. This change does not affect the output though as all headers are served lowercased anyway.
- Might be a good idea to make all headers lowercased one day to match the casing with the outputs
2022-04-14 15:21:35 +08:00
Thibaut Patel
bfbece948e Fixed the previous commit issue
refs 7a55e1a60a
2022-04-13 16:51:10 +02:00
Rishabh
00e5e87d4b Added newsletter preference selection to Portal signup flows
refs https://github.com/TryGhost/Team/issues/1490

- adds intermediary newsletter pref selection page to signup flows in case a site has multiple newsletters
  - for members signing up as free via magic link
  - for members signing up as paid via stripe checkout
  - for members signing up as paid via offer url
2022-04-13 20:06:27 +05:30
Thibaut Patel
7a55e1a60a
Added the newsletter_id query string to the post edit API route (#14449)
refs https://github.com/TryGhost/Team/issues/1502

- Support the `newsletter_id` only when sending a newsletter
- Default to the default newsletter when `newsletter_id` isn't specified
- Ignore the `newsletter_id` parameter when passed in the post body
2022-04-13 15:27:43 +02:00
Simon Backx
cb1f0802d4
Added migration that fills the mrr column in members_stripe_customers_subscriptions (#14465)
refs https://github.com/TryGhost/Team/issues/1456

- Sets the MRR of active subscriptions
- Mirrors the behaviour of the getMRR method from MembersRepository in `members-api`
2022-04-13 14:07:34 +02:00
Thibaut Patel
ffc57301f6
Fixed the newsletters api permissions (#14458)
refs https://github.com/TryGhost/Team/issues/1504

- The permissions were missing in the fixture file
- This caused some Ghost installs to not have the right permissions
- This is fixed by adding the missing permissions to the fixture file and creating a migration to resolve the missing permissions
2022-04-13 12:02:06 +02:00
Rishabh Garg
e6f96d4711
Added filtering for members api on newsletter subscriptions (#14460)
refs https://github.com/TryGhost/Team/issues/1484

While sending a post to a specific newsletter, we'll need to get list/count of members eligible to receive the post. This change enables members admin API to filter list of members on specific newsletter by their slug.
2022-04-12 21:01:49 +05:30
Rishabh Garg
95670eed52
Handled default newsletter fixtures setup (#14459)
closes https://github.com/TryGhost/Team/issues/1491

With multiple newsletters feature, a site should always have at-least one newsletter by default. Also, as with the default product, the default newsletter also needs to be renamed to the site title during the setup flow.

- adds default newsletter to main and test fixtures
- updates setup flow to rename newsletter name and sender name to site title
- updates model to extend default value for fields
- updates test
2022-04-12 19:44:21 +05:30
Simon Backx
2db746e559
Added mrr column to subscriptions (#14448)
refs https://github.com/TryGhost/Team/issues/1457

We want to save the MRR with a subscription to simplify the calculation of the total MRR once, in 5.0, we also take 'forever' offers into account into the MRR (so we can just SUM the MRR of all subscriptions).

- Sets the MRR to 0 for now.
- Separate commit will fill in all the values in a data migration, but this needs to get merged first because we need this new column in order to update the members-api package (so we already save the MRR before doing the data migration).
- Updated `test/e2e-api/admin/legacy-members.test.js` with improved body assertions.
2022-04-12 11:02:18 +02:00
Fabien 'egg' O'Carroll
cf6eef60e3
Added migration to populate cancellation events (#14438)
refs https://github.com/TryGhost/Team/issues/1302

We do not want to update MRR calculations until 5.0 - so will be adding
a separate migration to populate the mrr_delta column for 5.0

We've only added events for non-expired subscriptions as this is simpler
and won't impact the mrr events when mrr_delta is updated
2022-04-11 15:18:12 +01:00
Daniel Lockyer
184dc861cb
Merged v4.43.1 into main
v4.43.1
2022-04-11 12:21:16 +01:00
Daniel Lockyer
10248f71e6 Updated Admin to v4.43.1 2022-04-11 12:16:38 +01:00
Fabien 'egg' O'Carroll
ee9190b912
Populated type column of existing events (#14437)
refs https://github.com/TryGhost/Team/issues/1302

Currently we only have three event types: created, updated & expired.

A created event always has a `from_plan` of null

An updated event will always have a different `to_plan` and `from_plan`
as the subscription has changed tier/cadence.

An expired event _should_ have a `to_plan` of null, but due to a bug we
have events with the same `from_plan` and `to_plan`.
2022-04-11 11:41:44 +01:00
Rishabh Garg
cb76b738ce
Fixed newsletter schema column validation (#14456)
refs https://github.com/TryGhost/Team/issues/1500

- newsletter schema columns were using incorrect syntax for `isIn` validations
- adds schema test to make sure schema `isIn` validations are in correct format
2022-04-11 15:05:02 +05:30
Daniel Lockyer
3df2158d23 Updated Admin to v4.43.0 2022-04-08 16:00:32 +01:00
Thibaut Patel
1ba72edce6
Added the emails-newsletters relation (#14434)
refs https://github.com/TryGhost/Team/issues/1497

- This enables us to keep track of which newsletter an email was sent to even if the related post is deleted.
- Adds the `newsletter_id` property to the email API
2022-04-08 16:16:23 +02:00