Commit Graph

1392 Commits

Author SHA1 Message Date
Naz
b71c1895fb Removed use of author_id syntax in fixtures
refs https://github.com/TryGhost/Toolbox/issues/230

 - The `author_id` would be ignored as a parameter in the API or Post model, so would produce a falsy results if specific fixtures were used to compare test results
2022-05-09 20:43:19 +08:00
Naz
625f83af09 Cleaned up schedules test suite from author_id field
refs https://github.com/TryGhost/Toolbox/issues/230

 - The `author_id` is ignored in the API of Ghost 5.0 and should not be used in the fixtures either
2022-05-09 20:43:19 +08:00
Naz
d804366b44 Removed outdated comment
refs https://github.com/TryGhost/Toolbox/issues/230

- The author_id column has been removed, it should not appear across the codebase in post context any longer
2022-05-09 20:34:06 +08:00
Naz
945345d990 Removed permissions handling of "author_id"
refs https://github.com/TryGhost/Toolbox/issues/230

- Single author logic can be removed as we dropped `author_id` column from the post model
2022-05-09 20:34:06 +08:00
Naz
d4f10e8fa3 Added test coverage for fixture manager
refs https://github.com/TryGhost/Toolbox/issues/230
2022-05-09 20:34:06 +08:00
Naz
30de0603ca Fixed dynamic routing test suite
refs https://github.com/TryGhost/Toolbox/issues/230

- Code tweaks to make test suite play nicely without single post author concept
2022-05-09 20:34:06 +08:00
Naz
e38c8a4662 Fixed model posts test suite
refs https://github.com/TryGhost/Toolbox/issues/230

- Code tweaks to make test suite for post modela and utils play nicely without single post author concept
2022-05-09 20:34:06 +08:00
Naz
6e6c702127 Fixed importer tests related to author
refs https://github.com/TryGhost/Toolbox/issues/230

- The tests were written using single author syntax, which is now gone
2022-05-09 20:34:06 +08:00
Naz
a372a84e82 Fixed test query using outdated author_id filter
refs https://github.com/TryGhost/Toolbox/issues/230

- The `author_id` column is gone, so is the support for filtering posts by single author's id. Using author's slug(s) is the closest alternative to achieve the same result
2022-05-09 20:34:06 +08:00
Naz
a3005dc328 Fixed authors initializaion on SQLite
refs https://github.com/TryGhost/Toolbox/issues/230

 - The plain ["id"] syntax doesn't work for SQLite - has to be an explicit property to catch up.
2022-05-09 20:34:06 +08:00
Naz
9821c3785e Fixed multiple author fixture initializaion
refs https://github.com/TryGhost/Toolbox/issues/230

 - The fixture manager has to initialize User/Roles fixtures first to be able to insert multiple authors as a relation in post fixtures. Otherwise the posts could not find correct authors and were failing trying to assign default "owner user" to each post
- The order of running fixtures matters, and till now the order wasn't taken into account at all when populating the db
2022-05-09 20:34:06 +08:00
Naz
e88b4b5c1b Removed single author concept form data generator
refs https://github.com/TryGhost/Toolbox/issues/230

- Data generator for test's state should not be inserting author_id columns now that it's not present in schema
2022-05-09 20:34:06 +08:00
Naz
2f98ad68ba Removed author_id useage form fixtures
refs https://github.com/TryGhost/Toolbox/issues/230

 - The column has been dropped form shema, so should not be used in fixtures either
2022-05-09 20:34:06 +08:00
Naz
6a42c1fa3b Fixed validator test as author_id does not exist anymore
refs https://github.com/TryGhost/Toolbox/issues/230

 - No column - no validation!
2022-05-09 20:34:06 +08:00
Matt Hanley
62164ecdf2
Added gravatar URL to config to make it configurable (#14490)
refs https://github.com/TryGhost/Toolbox/issues/288

- Allows switching out the Gravatar URL to use placeholder images when working with mocked demo data
2022-05-09 12:44:04 +01:00
Simon Backx
21d9d20e3e
Included newsletter relation by default in posts (#14723)
refs https://github.com/TryGhost/Team/issues/1569

**Changes in admin-api-schema:**
- https://github.com/TryGhost/SDK/compare/%40tryghost/admin-api-schema%402.14.1...%40tryghost/admin-api-schema%402.15.0
- Ignore `newsletter` when used in input

**Changes**
- Added the `newsletter` relation as a default include for posts
- Removed the newsletter_id from the API output

**Tests**
- Test the newsletter relation is always loaded for browse, read, add and edit, unless the include option is added explicitly

Co-authored-by: Matt Hanley <git@matthanley.co.uk>
2022-05-09 11:06:59 +02:00
Simon Backx
96e7187e8d
Fixed members CSV export not filtering on subscribed (#14721)
refs https://ghost.slack.com/archives/C02G9E68C/p1651851268912299?thread_ts=1651848216.832419&cid=C02G9E68C

- When exporting members to CSV the subscribed filter was not working correctly
- Fixed by also applying the NQL mapping to the export endpoint
- This also changes the order of the members in the CSV export to match the order in admin/browse endpoint
2022-05-09 10:56:36 +02:00
renovate[bot]
abd90be910
Update dependency @tryghost/mw-error-handler to v1 (#14719)
- Replaced usage of handleJSONResponseV2 with the newly renamed handleJSONResponse

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-05-07 15:28:28 +01:00
Matt Hanley
a43ab8445d 🐛 Fixed importing posts with a newsletter assigned
refs https://github.com/TryGhost/Team/issues/1595

- Since adding multiple newsletters, posts may be linked to a related newsletter
- We don't export newsletters, so the related newsletter_id doesn't exist and fails the FK check on import
2022-05-06 16:36:35 +01:00
Hannah Wolfe
401fe46380
Changed webhooks to store safe version
refs: https://github.com/TryGhost/Toolbox/issues/229

- We're getting rid of the concept of api versions inside of Ghost
- Instead of storing the supposed api version a webhook was created with, store the current ghost version
- This way we can determine if anything signicant changes in future and we need to update webhooks or something
2022-05-06 12:43:14 +01:00
Hannah Wolfe
d3ea145c19
Refactored webhook tests to use e2e framework
- webhooks are one of the remaining places where we need some sort of api version handling
- in order to fixup the tests for this, I wanted to first change them to use the e2e framework
2022-05-06 12:38:13 +01:00
Hannah Wolfe
7618f925e1
Cleaned newsletter e2e tests, improved framework
- attempting to make our framework a one-stop-shop for all requires (except assert)
- using utils for tests instead of lots of requires makes it easier to reason about how our tests interface with our code
- helps with refactoring later, and making sure that tests really do what we expect
2022-05-06 12:15:12 +01:00
Rishabh Garg
0694e016e0
Excluded newsletter's sender email value when importing (#14706)
refs https://github.com/TryGhost/Team/issues/1529

- the sender email addresses for newsletters require verification to set.
- this ensures there isn't a way around that by modifying an export file then importing it by setting it to null on import.

This pattern is similar to the current `members_from_address` setting which is excluded when importing.
2022-05-06 12:45:10 +05:30
Hannah Wolfe
6dc3f1bf56
Removed versioning from api-key/admin auth
refs: https://github.com/TryGhost/Toolbox/issues/229

- our api-key audience handling code is still relying on internal api version config
- the regex used is also buggy (it expects 3 parts, which isn't true without versions) and doesn't always match, in which case it can cause the tests to hang
- we already had some very similar code in the version-rewrite middleware which is also validates exact values for version and api type
- moved this code into a util inside api-version-compatibility-service
- using this code, all the tests still pass as is, but when I start to adjust them to cover more cases, none hang (test changes coming in a separate commit)
2022-05-06 08:09:54 +01:00
Hannah Wolfe
829261f04f
Added tests for version-rewrites
- Now that the code is split out it's super easy to unit test.
- I was being lazy before :)
2022-05-05 19:13:51 +01:00
renovate[bot]
9aa8e3e7ff
Update dependency @tryghost/url-utils to v3 (#14705)
- updated usage of url-utils.urlFor to work with v3

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-05-05 16:10:18 +01:00
Simon Backx
38b9cf2472
Fixed newsletter includes when adding or editing (#14696)
refs https://github.com/TryGhost/Team/issues/1571
refs https://ghost.slack.com/archives/C02G9E68C/p1650986988322609

- Makes sure the includes are always included
- Moved read to the newsletter service
- Added tests
- Updated unit tests to work with multiple findOne calls
- Fixed reject assertions not correctly awaiting in unit tests
2022-05-05 11:20:15 +02:00
Simon Backx
366a7be36d 🐛 Fixed newsletters' header_image saved as absolute url (#14690)
refs https://github.com/TryGhost/Team/issues/1579

- When writing to the database, the header_image is tranformed to the transformReady path
- When reading from the database, the transformReady path is transformed to an absolute path
- Includes a test when adding a newsletter

Migration:
- Updates all newsletter who have a header_image to make sure it is saved in transform ready format
- Down operation is required to work with the old model logic and transforms it back to an absolute format
2022-05-05 09:44:03 +01:00
renovate[bot]
45695ef2d5
Update dependency @tryghost/mw-error-handler to v0.2.4 (#14677)
- Updated accept-version error message copy

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-05-05 08:57:32 +01:00
Hannah Wolfe
7c795b4e26
Rewrite old version URLs to unversioned URLs with headers (#14646)
closes: https://github.com/TryGhost/Toolbox/issues/315

- For all the current versioned URLs, rewrite the URL as unversioned
  - Add the accept-version header
  - Add the deprecation header
  - Add the link header

- This then does the content-version middleware afterwards, ensuring that rewritten requests get this in the response
2022-05-05 08:45:24 +01:00
Rishabh Garg
420697291b
Added newsletter info to email unsubscribe url (#14693)
refs https://github.com/TryGhost/Team/issues/1495

For single newsletters, the unsubscribe link on emails auto unsubscribed member from the newsletter. In case of multiple newsletters, we were missing the newsletter information on unsubscribe URL that will allow us to auto unsubscribe member from that specific newsletter as they intended, while allowing them option to manage other newsletter preferences via Portal UI. This change -

- adds relevant newsletter UUID on the unsubscribe url in emails
- allows portal to auto unsubscribe members from desired newsletter
2022-05-05 11:00:24 +05:30
Simon Backx
cf9231e77a
Added name property to duplicate newsletter ValidationError (#14694)
refs https://github.com/TryGhost/Team/issues/1564

We need this property in the frontend to correctly handle the error
2022-05-04 16:45:55 +02:00
Simon Backx
473ac3b5a4
Fixed updating a non-existent member internal error (#14658)
refs https://github.com/TryGhost/Team/issues/1580

- When you try to edit a member that doesn't exist, a 500 error is thrown. We should throw a 404 error instead
- This is fixed by https://github.com/TryGhost/Members/pull/395
2022-05-04 13:51:35 +02:00
Naz
c627779948 Extracted email-content-generator into a package
refs https://github.com/TryGhost/Toolbox/issues/292

- Following the concept of having as little code in Ghost core as possible :) The email content generation is also needed to be reused in the version mismatch handling package.
2022-05-04 17:28:09 +08:00
Naz
551bd5e511 Refactored email utils to a class with DI params
refs https://github.com/TryGhost/Toolbox/issues/292

- There's a need to reuse these utils in the version mismatch notification service. Having loads of tightly coupled dependencies makes it super hard to rip out this module for reuse
- It's a groundwork for extraction of the email-utils package
- Rewrote the unit tests that were written for these utils previously - they weren't testing anything useful. The goal of this util is to generate specific content based on provided data and available templates - now the tests do test those specific things, not the mailer itself!
2022-05-04 15:36:50 +08:00
Hannah Wolfe
499bb293c9
Fixed urlUtils usage in member config provider
- This is preparation work for getting rid of API versions
- The existing code used api versions for members, but the members API is not versioned
- This caused a bug as issuer was begin set to {{admin_url}}/ghost/api/undefined
- The updated code returns the correct value and is unit tested
- Whilst cleaning up I also swapped the usage of urlUtils to consistently use urlFor, as that is our main helper
2022-05-03 21:07:04 +01:00
Simon Backx
18ad847211
Added ValidationError for duplicate newsletter names (#14631)
refs https://github.com/TryGhost/Team/issues/1564

- While creating a newsletter
- While editing a newsletter
- Includes tests and updated snapshots
- Igored sort_order to snapshot test because sort_order is different in CI than locally so had to ignore it in the snapshot.
2022-05-03 15:33:56 +02:00
Hannah Wolfe
b6e9eadef9
Fixed overly specific assertion
- Asserting for the exact error message thrown was a bad idea
  as it is different between different versions of Node... derp
- Also, don't really care, I'm just asserting that the serialize function errors under certain conditions
2022-05-03 11:59:50 +01:00
Hannah Wolfe
d01c1cba64
Fixed undefined error when serializing webhooks
closes: https://github.com/TryGhost/Toolbox/issues/318
refs: https://github.com/TryGhost/Toolbox/issues/320
refs: 2a11d5100e

- The underlying problem was caused by the removal of API versions
  - commit 2a11d5100e
  - I missed doing the same refactor as was done for the post-emailserializer here: 2a11d5100e (diff-0f7477bb5e5a9fdcb4c909a9e9e61ab5bb76b640b2d63a5791a9d6c8904f2758R7)
  - The removal of api versions included a change to remove circular references in the api module
- Written some basic unit tests to prove that webhook serialization works
  - I'm not 100% happy with the output, and not sure if it's the tests or reality, needs further work
  - Future work tracked in https://github.com/TryGhost/Toolbox/issues/320
2022-05-03 11:40:59 +01:00
Naz
3d397bb5f1 Revert "Disabled version compatibility emails temporarily"
This reverts commit 9a0d143fb1

- main is now a precursor of 5.0 which should have email notification turned on
- had to add missing `err` in the errorHandler middleware as it was not triggering the versionMissmatchHandler otherwise
2022-05-03 17:18:44 +08:00
Naz
734ef66e6c Fixed deadlock when adding multiple authors in tests
refs 275107d423

- Because there might be multiple authors being added at the same time with different values to the posts_authors table these operations should not be done in parallel! Making post insertion sequential fixed the deadlock
2022-05-03 16:28:07 +08:00
Naz
275107d423 Added test coverage for author reassignment
closes https://github.com/TryGhost/Toolbox/issues/268

- Adds more coverage to the author reassignment method as it hasn't been covered much. It should put a good base to expand upon in case a bug pops up
2022-05-03 14:57:35 +08:00
Naz
6fa77cc0e6 Fixed fatal errors in theme tests
refs 03c8e7f010
refs https://github.com/TryGhost/Toolbox/issues/226

- With a bump of gscan the default "Casper" theme in test fixtures should have been updated, otherwise it's leaving "fatal error" logs all over the place
2022-05-03 12:24:39 +08:00
Hannah Wolfe
d75daca5fd Removed outdated snapshots from version snap file
- these are old snaps that are not run or used any longer
- they were probably generated during development or as part of naming changes
2022-05-02 19:05:14 +01:00
Hannah Wolfe
c6ae3c30d8 Moved content-version middleware onto api app
closes: https://github.com/TryGhost/Toolbox/issues/319

- at the moment, content-version is only set if one of our endpoints touches the request
  - this was demonstrated in the e2e tests, where many of the tests that set accept-version did not receive accept-version
- by moving the middleware out of the http module and onto the api app we ensure it's always done
- I put the code in the api-version-compatibility service to keep it all co-located
- ideally we will refactor that service slightly so it only exposes middleware
2022-05-02 19:05:14 +01:00
Hannah Wolfe
55ce208ebb Fixed api-version-compatibility-service init error
closes: https://github.com/TryGhost/Toolbox/issues/317

- Added two tests for unknown versions with accept-versions set ahead and behind
   - Ahead passes, but we get an error for behind
- Refactored the api-version-compatibility-service to expose its own middleware so the init sequence is correct
2022-05-02 19:05:14 +01:00
Naz
03c8e7f010 Switched gscan to validate against v5 set of rules
refs https://github.com/TryGhost/Toolbox/issues/226

- We are on the finish line to release 5.0 - the instance should be validating it's themes agains v5 set of rules.
- The prominent deprecations are `{{author}}` and `@blog` helpers removals - will throw 'fatal' errors when encountered.
2022-05-02 20:56:25 +08:00
Hannah Wolfe
857464c104
Swapped etag matcher to always be anyEtag
- some tests were using anyString, but we have a more specific matcher available
- it's best to use the most specific matcher possible
2022-05-02 11:05:07 +01:00
Naz
5e441d0942 🔥 Removed {{author}} helper support
refs https://github.com/TryGhost/Toolbox/issues/230

 - Single {{author}} helper has been deprecated since multiple major releases. It has also been throwing fatal errors in gscan v5 since some time. It will finally be gone!
 - The plural {{authors}} helper should be used instead, read here for more information: https://ghost.org/docs/themes/helpers/authors/
2022-05-02 17:59:48 +08:00
Daniel Lockyer
ae13b61cb0
Removed backwards compatibility for ghost_head and ghost_foot settings
refs https://github.com/TryGhost/Toolbox/issues/308

- these two settings are deprecated and we're removing all the code in
  v5 that kept supporting them
2022-04-28 15:37:14 +01:00
Daniel Lockyer
3b6cdc2bc5
Renamed preview files to previews
refs https://github.com/TryGhost/Toolbox/issues/308

- we have a pattern of using plurals around Ghost but this was singular
- this shouldn't change any API functionality, it's just code
  refactoring
2022-04-28 15:37:14 +01:00
Hannah Wolfe
0eedb1c556
Added 307 redirects for old API endpoints
closes: https://github.com/TryGhost/Toolbox/issues/296

- This is a small change to permit any known API version to redirect to an unversioned URL
- We include v2 because although it should have been deleted in 5.0 anyway, in the spirit of the change away from versioned URLs there's
  absolutely no sense in forcing people to update clients that still work for no reason.
- We use a 307, because this preserves the original HTTP method, allowing POSTS, PUTs and DELETEs through as well as GETs
- We set the accept-version header on the redirect, meaning that for example with a request to the old /v4/ api, Ghost will respond as though
  the client sent `accept-version: v4.0` and if there are known breaking changes, it may choose to inform the admin and owner users of these
2022-04-28 15:37:14 +01:00
Naz
4edec18289
Fixed lint error 2022-04-28 15:37:14 +01:00
Naz
ce19cf80bf
Added better coverage for author reassignment
refs https://github.com/TryGhost/Toolbox/issues/268

 - The test didn't check if the posts were successfully reasigned, so have added that part of logic
2022-04-28 15:37:13 +01:00
Daniel Lockyer
f82ff87177
Changed /email_previews/posts/<post id> endpoint to return 204 upon success
refs https://github.com/TryGhost/Toolbox/issues/308

- this endpoint is currently used to send a test email with the post
- it currently returns a 200 with whatever the response of the mail
  service is
- this body isn't used in Admin nor is useful generally because it just
  contains the ID of the mailgun response
- it's better than we change it to 204 and no response
- this commit does that and updates the tests
2022-04-28 15:37:13 +01:00
Naz
b123a9bb77
Refactored multiauthor posts suite to async/await
refs https://github.com/TryGhost/Toolbox/issues/268

 - I'm about to rewrite it, so made the test suite slightly more readable to keep track of changes easier
2022-04-28 15:37:13 +01:00
Naz
5b43b4f40d
Fixed failing reassignByAuthor test
refs https://github.com/TryGhost/Toolbox/issues/268

 - After the logic change the number of posts no longer decreases - reassignment does not delete posts
 - In a follow up commit will add a more sophisticated check for actual reassignment
2022-04-28 15:37:13 +01:00
Naz
5ba3f5efcf
Reassigned posts when deleting a user
refs https://github.com/TryGhost/Toolbox/issues/268

 - When the user is removed our current pattern was deleting their posts. This didn't work well and created all sorts of problems
 - As a solution we now reassign any posts that are only authored by the deleted user to the owner user
 - This change also reduced the dependency on "author" field
2022-04-28 15:37:13 +01:00
Daniel Lockyer
6920c03b3f
Fixed erroneously passing test
- this test was passing for the wrong reason because it wasn't using the
  correct endpoint that we were meant to be testing
2022-04-28 15:37:12 +01:00
Daniel Lockyer
68cffa62ae
Renamed email-preview file to email-previews
refs https://github.com/TryGhost/Toolbox/issues/308

- I recently pluralised the API endpoint but never made the changes to
  the controller file and everywhere else it's needed
- this commit cleans up that inconsistency so it should be clearer
2022-04-28 15:37:12 +01:00
Daniel Lockyer
0f5c22a38d
Cleaned up mention of subscribers in test folder
refs https://github.com/TryGhost/Toolbox/issues/308

- we had a few mentions of `subscribers` in the test suite data generator
  but this shouldn't be used any more because it's an ancienttttt concept
- removing this for v5 as it helps to clean the codebase
2022-04-28 15:37:12 +01:00
Daniel Lockyer
51835c5c80
Fixed status code in tests
refs https://github.com/TryGhost/Toolbox/issues/308

- this was previously missed when altering the status code
  for `DELETE .../settings/stripe/connect/`
2022-04-28 15:37:12 +01:00
Daniel Lockyer
a48d8427f4
Change response code of special settings API endpoints to 204
refs https://github.com/TryGhost/Toolbox/issues/308

- these endpoints return no body but they were implemented to return a
  200 error code
- 204 would be more suitable so this commit changes that for v5
- also removes the passthrough serializer and updates the snapshots to
  reflect the changes
2022-04-28 15:37:11 +01:00
Daniel Lockyer
ea3c927d94
Renamed reset_all_passwords Authentication API endpoint to /global_password_reset
refs https://github.com/TryGhost/Toolbox/issues/308

- our API has a pattern of using nouns and not verbs for the endpoint
  names, so this changes the endpoint for v5
2022-04-28 15:37:11 +01:00
Daniel Lockyer
cfa2f0e102
Changed /authentication/reset_all_passwords to return 204 response code
refs https://github.com/TryGhost/Toolbox/issues/308

- this endpoint has no body to return but it was initially implemented
  as returning a 200 which we couldn't change until 5.0
- this changes it to a 204, removes the serializer and updates tests to
  take this into account
2022-04-28 15:37:11 +01:00
Daniel Lockyer
379f64428e
Renamed passwordreset body object to password_reset
refs https://github.com/TryGhost/Toolbox/issues/308

- I've just renamed the `/authentication/passwordreset` API endpoint to
  `/authentication/password_reset` and noticed the body object is also
  badly named
- this clears that up in code and tests
2022-04-28 15:37:11 +01:00
Daniel Lockyer
c4f3d44baa
Renamed /passwordreset Authentication API endpoint to /password_reset
refs https://github.com/TryGhost/Toolbox/issues/308

- we have the pattern of splitting words in API endpoints with an
  underscore but this was an exception we want to clean up in v5
2022-04-28 15:37:11 +01:00
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
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
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
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
Fabien "egg" O'Carroll
a332e42476 Tested for updating email and adding existing members
This test is skipped on SQLite3 as there is an issue with transactions
2022-04-28 12:35:06 +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
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
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
Hannah Wolfe
a703185497
Fixed mockLabs disabling all other flags (#14621)
refs TryGhost/Team#1566

- Mocking a labs flag (regardless of enabled/disabled) currently has a side effect of setting any other flag to undefined.
- This meant in a test where we set a flag e.g. members-importer where we set multipleProducts, multipleNewsletters is always disabled
- This fix preserves the default state of all labs flags that are not mocked so that labs behaves how we expect
- Removed usage of GA flags in tests
- Removed tests that had GA flags disabled

Co-authored-by: Simon Backx <simon@ghost.org>
2022-04-28 10:55:20 +02: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
21af34a0d4
Added mapping from member subscribed to newsletters on edit/create (#14596)
refs https://github.com/TryGhost/Team/issues/1545

**Changes (`members-api`)**
- Compare via https://github.com/TryGhost/Members/compare/%40tryghost/members-api%406.0.0...%40tryghost/members-api%406.1.0
- Added mapping from member subscribed to newsletters on edit/create
- When editing or creating a member with the subscribed property, it is mapped to the corresponding newletters value
- Defaults to all active newsletters with visibility = members and subscribe_on_signup = true

**Tests**
- Adds test that adds a member with subscribed = true
- Adds test that adds a member with subscribed = false
- Adds test that edits a member with subscribed = true
- Adds test that edits a member with subscribed = false
2022-04-27 17:04:55 +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
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
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
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
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