Commit Graph

10542 Commits

Author SHA1 Message Date
Hannah Wolfe
ddb718f0bb
Fixed settingsCache returning falsy as null
refs: e68cb8b314

- a couple of months ago when improving the test coverage here I found some weird behaviour with falsey values
- turned out it didn't matter at the time because we didn't have any settings that are false
- with the introduction of calculated settings we will have: https://github.com/TryGhost/Ghost/pull/14766
- whilst building that, I found settings that should be returned as false were being returned as null
- fixing it in a separate commit to keep the work clean
2022-05-10 20:37:03 +01:00
Daniel Lockyer
1c7d4e49c5
Disabled model auto-refresh when processing email batches
- by default, the model will auto-refresh when you save
- in MySQL, which doesn't support RETURNING, this is implemented by
  doing a SELECT after your actual query
- `email_recipients` is a huge table and `processed_at` is not an
  indexed column, so the query times can become realllyyyyyyy big
- given we don't even need the result of the model save, we can just
  disable fetching all the affected records again
- Bookshelf gives us this ability in the form of `autoRefresh: false`
2022-05-10 18:11:15 +01:00
Daniel Lockyer
bb9a797283 Regenerated HTML for posts containing a product or video card
refs https://github.com/TryGhost/Toolbox/issues/309
refs https://github.com/TryGhost/Ghost/issues/14344

- this migration will regenerate the HTML for posts that contain a
  product or video card as we experiencing a bug in the card generation
- this migration is mostly ripped from c0d82122b0/core/server/data/migrations/versions/4.0/23-regenerate-posts-html.js
2022-05-10 18:05:27 +01:00
Daniel Lockyer
ada0e7975b fixup! Added validation to posts status column 2022-05-10 18:05:18 +01:00
Daniel Lockyer
66652b6ea9 Added validation to posts status column
refs https://github.com/TryGhost/Toolbox/issues/309

- this commit adds `isIn` validation to the `status` column on the
  `posts` table, with values pulled from the model: c0d82122b0/core/server/models/post.js (L28)
- this also adds a migration to update any posts with invalid statuses
  to `draft`
2022-05-10 18:05:18 +01:00
Daniel Lockyer
ca82914052 Removed client and subscriber permissions
refs https://github.com/TryGhost/Toolbox/issues/309

- these stopped being added to the DB in v3 but there was never a
  migration to clean up existing permissions and the role link in the DB
- we now have the utils to do this cleanly, so we can drop all the
  permissions in this migration
2022-05-10 18:05:06 +01:00
Daniel Lockyer
5384944fa4
Added log line before updating user statuses
- this makes it obvious where we are in the flow and its clear we're
  inside this migration if we see that log line
2022-05-10 16:46:33 +01:00
Hannah Wolfe
b911c66bb6
Fixed legacyApiPathMatch not working with subdirs
- The recently refactored path matching code forgot to take into account that originalUrl can include the subdir
- Added more permutations to tests and ensured that all tests pass
- This means we don't have to worry about what sort of path we pass to the function, it'll figure out the version and api info
2022-05-10 13:57:06 +01:00
Daniel Lockyer
b7b4f8d1d1 Added migration utils for removing a permission
- this will drop the link between a role and a permission, and then
  delete the permission
- required minor refactoring to aid in creating migrations for dropping
  the links and permission
2022-05-10 13:21:26 +01:00
Daniel Lockyer
bf28721844 De-duped MIGRATION_USER constant across migration utils
- we shouldn't declare this in more than one place, even if it is a
  weird concept anyway
2022-05-10 13:05:47 +01:00
Daniel Lockyer
1c440e14b1 Split apart migration utils into separate files
- this should help organize the code a little better and frees us up to
  turn it into a separate package in the future
2022-05-10 13:05:47 +01:00
Daniel Lockyer
892408e1cd Moved migration utils.js to subfolder
- this helps makes way for splitting the file apart to make the utils
  easier to write
2022-05-10 13:05:47 +01:00
Daniel Lockyer
3b860c9b0d Switched use of migration utils to folder
- I'm refactoring the utils to make way for dropping permissions but the
  utils are in a real mess
- to aid my refactoring, I want to make the utils a folder, so the
  migrations that require utils as a file need updating
- this commit does that
2022-05-10 13:05:47 +01:00
Simon Backx
f732b0181d
Fixed last_seen updated for suspended users (#14715)
refs https://github.com/TryGhost/Team/issues/1461

- A suspended user was able to make it through the Express middlewares to the `updateUserLastSeen` middleware, until it was halted when checking the user permissions in the API pipeline. This was only the case for session logins, not for API keys.
- For API keys, the user status is checked:
6dc3f1bf56/core/server/services/auth/api-key/admin.js (L178-L181)
- In the session middleware, the `findUserById` in `getUserForSession` didn't filter on the active status of users:
be4146e324/core/server/services/auth/session/middleware.js (L22-L27)
- This has been fixed now by updating the sessionService's `findUserById` method.
2022-05-10 13:34:12 +02:00
Hannah Wolfe
f3d5d9cf6b Added internal frontend integration
refs: https://github.com/TryGhost/Team/issues/1599

- add an internal integration for Ghost's frontend to talk to the content API
- this is so that portal and future features can access our APIs through the correct mechanism of an API key
2022-05-10 11:43:07 +01:00
Daniel Lockyer
b794c6885e Deleted membersActivity flag
refs https://github.com/TryGhost/Toolbox/issues/325

- this was used for an alpha proof-of-concept for member activity data
  collection but we're rethinking the strategy so this is the easiest
  way to ensure it can't be enabled when the database table has been deleted
2022-05-10 11:19:58 +01:00
Naz
6934595053 Added Integration Name in version mismatch emails
refs https://github.com/TryGhost/Toolbox/issues/292

- Providing user-defined Integration name instead of API client's UserAgent gives a lot more control to instance administrators identifying which integration is being used incorrectly.
- It's best practice to create an Integration with a set of API keys per API client - which should be enough to identify an outdated one.
2022-05-10 17:55:18 +08:00
Naz
6cca515eae Fixed typo 2022-05-10 17:44:58 +08:00
Daniel Lockyer
98a8fa8b0d Dropped temp_member_analytic_events table
refs https://github.com/TryGhost/Toolbox/issues/309

- this table was used an an experiment for member analytics
- as we rethink the strategy, we can take the opportunity to clean the table up
2022-05-10 10:00:19 +01:00
Fabien "egg" O'Carroll
6d48846f15 Fixed ESLint warnings 2022-05-09 17:13:07 +01:00
Daniel Lockyer
aed7ef0cae
Altered wording in migration utils
- if the table doesn't exist, it's not necessarily a failure that we
  should be informing the user about
- this brings the message wording in line with other log lines of
  similar operations
2022-05-09 16:49:28 +01:00
Daniel Lockyer
c8d6024a0c Dropped subscribed column in members table
refs https://github.com/TryGhost/Toolbox/issues/309

- this column is now a calculated value based upon the relation of a
  member to a newsletter
- we should no longer need `subscribed`, so this migrations cleans up
  the column in the DB
2022-05-09 16:47:43 +01:00
Simon Backx
5657019e47
Fixed wrong newsletter used when sending scheduled post (#14734)
refs https://ghost.slack.com/archives/C02G9E68C/p1651939076681719

Cause:
- When a scheduled post was published via the post scheduler, no `newsletter_id` option is passed when editing the post.
- When editing a post via the posts service, without the `newsletter_id` option, the `newsletter_id` option is automatically set to the default newsletter's id.
- Inside the post model, this new `newsletter_id` was not saved, because it was already set, and changing it is prevented.
- The `mega` service wasn't using the (unchanged) post's newsletter_id, but used the option instead, which contained the default newsletter's id.

Fix:
- Always using the newsletter_id from the post and requiring the newsletter associated with a post to exist.
- This behaviour can be/is tested by publishing a scheduled post without any option.

Also cleaned up some `Object.assign` usages.
2022-05-09 17:30:50 +02:00
Rishabh Garg
4d6b3568c5
Enabled Admin integration for newsletters API (#14714)
refs https://github.com/TryGhost/Team/issues/1546

- allows newsletters API to work with Admin API keys
- updates fixtures to add permissions to admin integration role for new sites
- adds migration to update existing sites to have correct permissions for role
- whitelists add/edit/read/browse on newsletters API for integrations
2022-05-09 20:46:34 +05:30
Daniel Lockyer
e10f33e30f Added users.status validation to the schema
refs https://github.com/TryGhost/Toolbox/issues/309

- this commit adds a validation array of valid user `status` values to
  the schema
- this also includes a migration to update users with invalid statuses
  to `inactive`, which I've seen with `invited` and `invited-pending`
  statuses that pre-dated proper invitations
- this also deletes tests that were wrong and written 7 years ago before
  invites was added
2022-05-09 16:13:44 +01:00
Daniel Lockyer
fce17d714e
Removed subscribed from email recipient filter validity check
- `subscribed` will soon cease to be a column on a member and I get errors
  in tests that stem from this block of code because it no longer exists
- AFAICT this block of code is only used to verify the filter is valid
  to filter on, which we should be able to do even if we remove
  `subscribed`
- this commit removes `subscribed` from the filter
2022-05-09 15:46:22 +01:00
Daniel Lockyer
f48a668671 Removed unused defaults from text columns in schema
refs https://github.com/TryGhost/Toolbox/issues/309

- I originally started looking at this because I wanted to change the default of
  `emails.recipient_filter` for old DBs to `status:-free`
- we changed these columns to a `text` type, which doesn't support
  defaults
- the tables already have defaults set in the model, so the only change
  needed here is to delete the `defaultTo` in the schema to avoid
  confusion
- on the way, I ended up fixing 51498abb5c too
2022-05-09 14:31:35 +01:00
Daniel Lockyer
1c12557c46 🏗 Dropped oauth table
refs https://github.com/TryGhost/Toolbox/issues/309

- we're removing the OAuth prototype and the table was never used, so we
  should be good to drop it
- this commit adds a migration to drop the table
2022-05-09 14:18:01 +01:00
Daniel Lockyer
63f62c3302 Migrated old recipient filters to NQL string format
refs https://github.com/TryGhost/Toolbox/issues/309

- we started off with "free" and "paid" in these columns but since moved
  to NQL strings
- there is code in Ghost to rewrite these values to NQL strings, but we
  still have posts/emails in the DB with these old values so they need
  to be updated
- once this migration is merged, we can probably clean a lot of that
  aliasing up
- this commit migrates values in `posts.email_recipient_filter` and
  `emails.recipient_filter` from `free` to `status:free` and `paid` to
  `status:-free`
- I've left the down as a no-op because we don't want to translate
  values back, and we don't know which ones we originally migrated in
  the first place
2022-05-09 13:43:46 +01: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
36e54656b6 Removed unnecessary model handling of single authors
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
69bf4ba92b Removed a comment about single author usecase
refs https://github.com/TryGhost/Toolbox/issues/230

- We no longer have/support `author_id` in the code, so the usecase was outdated
2022-05-09 20:34:06 +08:00
Naz
15951aa1d5 Removed unneeded author_id cleanup
refs https://github.com/TryGhost/Toolbox/issues/230

- As the `author_id` column is gone there's no need to cleanup the posts table when reassigning user's posts
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
e8f20e5f12 Removed creation of single author on post creation
refs https://github.com/TryGhost/Toolbox/issues/230
2022-05-09 20:34:06 +08:00
Naz
efc443a8d1 Removed author_id as a default fetched column for posts
refs https://github.com/TryGhost/Toolbox/issues/230

- The column has been dropped from schema and would not be necessary in the post's model
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
6d17d28d1a 🏗 Removed author_id column from the posts table
refs https://github.com/TryGhost/Toolbox/issues/230

- This is a first step to removal of `author_id` concept from the codebase. The aim is to see what parts break down from this changes an work backwards from there
2022-05-09 20:34:06 +08:00
Naz
b2db80c9fe Fixed missing failed request URL if version emails
refs https://github.com/TryGhost/Toolbox/issues/292

- The version mismatch notification emails were missing a URL of the endpoint that was being accessed by an outdated integraton
- Also squeezed in a refactor simplifying APIVersionCompatibilityService initialization
2022-05-09 20:11:25 +08:00
Matt Hanley
e5c5661701
Assigned existing email records and related posts to the default newsletter (#14695)
refs https://github.com/TryGhost/Team/issues/1571

- With the addition of multiple newsletters, all emails sent previously should be assigned to the default newsletter
- This will make sure that the sent count for the default newsletter displays correctly
2022-05-09 12:48:24 +01:00
Fabien 'egg' O'Carroll
895ffee90b
Added Dashboard 5.0 migrations (#14716)
refs https://github.com/TryGhost/Team/issues/1515
refs https://github.com/TryGhost/Team/issues/1516
refs https://github.com/TryGhost/Team/issues/1455

The updates the `mrr` column for subscriptions and the `mrr_deltas` for events
so that both Offers and canceled Subscriptions are correctly handled.

We must apply the canceled Subscription changes after the Offers, so that they
interact correctly, and that the `mrr` column has the necessary data for each migration.

Co-authored-by: Simon Backx <simon@ghost.org>
2022-05-09 12:46:46 +01: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
Daniel Lockyer
d8e58b53d0
Altered migration utility to always use algorithm=copy for MySQL (#14699)
refs https://github.com/TryGhost/Toolbox/issues/309
refs 2bfd8f8b7e

- we've previously had issues when dropping a column on `posts`
  because it's a large table and it can take a veeeeeeery long time with
  the default SQL produced by Knex
- we found a magic incantation that makes it super speedy (context in
  commit above) => `, algorithm=copy`
- for that migration, we did it all manually but we can now change the
  utility to always append this to the generated SQL so we don't have to
  think about the specific table size when adding or dropping columns
- this changes the `addColumn` and `dropColumn` utilities to append the
  string to SQL in MySQL, or just executes the SQL for SQLite
2022-05-09 10:16:36 +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
Rishabh
95fc22e6fe Refined newsletter import sanitisation
refs https://github.com/TryGhost/Team/issues/1529

- simplifies the sanitisation method to delete ignored columns
2022-05-09 12:32:25 +05:30
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
renovate[bot]
e0ce8995a7
Update dependency @tryghost/security to v0.3.0 (#14718)
- Swapped instances of createSecret for security.secret.create

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
2022-05-06 17:53:10 +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