Commit Graph

16282 Commits

Author SHA1 Message Date
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
Simon Backx
fb60a0199c
Fixed editing members throwing when setting avatar_image (#14751)
refs https://ghost.slack.com/archives/C02G9E68C/p1652126859737159?thread_ts=1652126765.251419&cid=C02G9E68C

When you try to edit a member in the admin frontend, the `avatar_image` property is passed. But that field is not editable and should be ignored. Currently an error is thrown, but this update from `admin-api-schema` adds it as a skipped property to remove this error.
2022-05-10 10:00:27 +02:00
Daniel Lockyer
10390e3408
Upgraded migration lint warnings to errors
- we have these rules in place to force the developer to think about the
  performance impact of their code
- unless they are enforced, it's easy for them to slip by and miss them
- this commit changes the warnings to errors, which will fail CI
- developers still have the ability to disable lines that flag the
  linting in case there is a valid use-case
2022-05-10 08:14:05 +01:00
Renovate Bot
c753d61be6
Update dependency sinon to v14 2022-05-09 19:14:13 +00: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
7fbf2a62ac Removed support for single "author" shorthand in fixtures
refs https://github.com/TryGhost/Toolbox/issues/230

 - The test fixtures should be using `authors: [{id:...}]` syntax instead of relyin on `author_id` or `author` - these are deprecated concepts that should go away from the codebase
2022-05-09 20:43:19 +08:00
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
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
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
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
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
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
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
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
cb80be3d0c
Fixed migrations running in CI tests
- we needed to bump the major version so 5.0 migrations will run in CI
- I'm also switching the Migrations test to delete all 5.x migrations
  and re-run them to test idempotency
2022-05-09 11:49:53 +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