Commit Graph

10523 Commits

Author SHA1 Message Date
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
Hannah Wolfe
865d57c4be
Removed api:versions from config
refs: https://github.com/TryGhost/Toolbox/issues/229

- Removed the final usage (logging only) of config.get('api:versions') and removed the config
- This is one of the last references to API versioning in the codebase & we don't need it anymore
- Cleaned up a random comment whilst searching for refs
2022-05-06 08:22:05 +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
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
Naz
dde9a5462a Moved the version rewrite middleware to a module
refs https://github.com/TryGhost/Toolbox/issues/315

- There's enough logic in the middleware to become it's own module and maybe even get extracted to an external module
2022-05-05 22:18:40 +08:00
Matt Hanley
8e1c10d146
Updated migration to always set a value
- When both parameters passed to `update` resolve to `undefined` we throw an `Empty .update() call detected` error
- This change always updates the `sender_email` to null rather than skipping the field
- `sender_reply_to` should still be `undefined` so we don't override an existing non-null value
2022-05-05 15:11:44 +01:00
Fabien 'egg' O'Carroll
e65d335c76
Fixed types for migration utils (#14709)
`import('knex')` does not refer to the type of an instantiated Knex instance.
2022-05-05 15:01:22 +01:00
Daniel Lockyer
51498abb5c
Fixed model validation erroneously triggering on non-nullable text fields
refs https://github.com/TryGhost/Toolbox/issues/309

- I've just ran into a problem when deleting the `defaultTo` field on a
  non-nullable `text` column in our schema because this validation
  thinks there should be a value set
- `text` fields cannot have defaults so the schema is incorrect, and the
  validation triggering is a bug that's preventing it from being
  cleaned up
- the default is defined on the model so I don't think we're losing
  anything here
2022-05-05 14:56:59 +01:00
Hannah Wolfe
a22879824b
Disabled lint on api-version-compat service temporarily
- We're in the process of bringing this service together
- It needs refactoring, and that will move most of the code back to utils
2022-05-05 12:46:19 +01:00
Naz
648530009d Added use of email templates for version mismatch notifications
refs https://github.com/TryGhost/Toolbox/issues/292

- This change allows to reuse existing pattern present in Ghost on the version mismatch service layer, where we define the contents of the sent email through email templates instead of plain text.
- Apart form templates, there's now failed request URL present in the data passed to the email template along with site title and site url
2022-05-05 18:26:08 +08: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
Matt Hanley
9371f6fd24 Migrated previous email sending settings to newsletters
refs https://github.com/TryGhost/Team/issues/1581

- The original migration to create the default newsletter omitted the from address and reply-to settings
- `sender_reply_to` and `members_reply_address` are both enums with the same values and copy straight across
- `members_from_address` had a default value of 'noreply' as the fallback, which is remapped to NULL in the newsletters table
- We apply the change to all newsletters (there should only be one outside of alpha) which haven't already been reconfigured
2022-05-05 09:44:03 +01:00
Matt Hanley
00e6f4bb34 Removed from-address fallback to members_from_address setting
refs https://github.com/TryGhost/Team/issues/1558

- `members_from_address` is no longer configurable in Admin but was still used as a fallback
- This change removes the fallback so we default straight to noreply@<domain> when a from-address isn't set for a newsletter
2022-05-05 09:44:03 +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
Fabien 'egg' O'Carroll
2da52130a6
Removed hasActiveStripeSubscriptions endpoint (#14689)
refs https://github.com/TryGhost/Team/issues/1147

This endpoint is no longer used in 5.0
2022-05-04 17:25:21 +01:00
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
ad1ebe6a47
Fixed error when firing Members webhooks (#14645)
refs https://github.com/TryGhost/Team/issues/1577

The last seen at was being updated via the model rather than the
respository, which mean that the default relations were not being
loaded.

This fix updates the repository to load the newseletters relation,
updates the last seen at updated to use the repository and updates the
output serializer to handle missing newsletter relation.

We also update all packages relying on the domain-events package to
ensure that they're all using the same version.

Co-authored-by: Fabien 'egg' O'Carroll <fabien@allou.is>
2022-05-04 12:42:27 +02:00