Commit Graph

16163 Commits

Author SHA1 Message Date
Renovate Bot
1afe52c657
Update dependency sqlite3 to v5.0.7 2022-05-05 18:34:13 +00: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
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
Naz
bc464f8930 Fixed file permissions on pre-push hook
refs 002cf5b0eb

- The hook file has to be executable to be triggered in the pre-push stage:

hint: The '.git/hooks/pre-push' hook was ignored because it's not set as executable.
2022-05-05 22:09:44 +08: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
Naz
002cf5b0eb Moved linting check to pre-push git hook
refs 81cd5fac7e

- While developing locally it's common to commit small WIP changes which might contain linting errors. Having the check done once on a pre-push phase gives enoght protection from pushing out broken code and reduces frustration when developing locally
2022-05-05 21:36:56 +08:00
Naz
81cd5fac7e Added linting check to a pre-commit hook
refs 648530009d

- Naz has broken the main too many times - it's time to stop the atrocities.
- Having a lint check as a pre-commit hook will make it really hard commiting code with linting errors
2022-05-05 21:21:48 +08: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
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
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
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
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
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
2d7bcdf80a Reworked EmailContentGenerator to async/await
refs https://github.com/TryGhost/Toolbox/issues/292

- Makes the code more readable
2022-05-04 15:36:50 +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
Renovate Bot
7c992ef099
Update dependency express-jwt to v7.6.2 2022-05-03 15:17:44 +00:00
Simon Backx
12f569ebf9
Dropped nullable from members_subscribe_events.newsletter_id (#14656)
closes https://github.com/TryGhost/Team/issues/1570

- Includes utils to disable foreign key checks when dropping nullable from columns
- Migration to drop nullable from members_subscribe_events.newsletter_id
2022-05-03 16:30:07 +02: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
c9ab21f821
Fixed inconsistent error response from the API
- we have two JSON error response formats one old, one new (v2)
- we couldn't use the new one everywhere before without changing the response from older versions
- that is totally irrelevant in Ghost 5.0 as there is only one API version
- therefore we can and should use the new response format everywhere
- eventually we should rename it so it doesn't have v2 in it
2022-05-02 13:31:25 +01:00
Simon Backx
ab4ea4850d
Fixed null values in settings default newsletter migration (#14638)
refs https://ghost.slack.com/archives/C02G9E68C/p1651484563907609

- When the site has an empty name, it is set to `NULL` in settings.
- The name column is not nullable in newsletters, breaking the migration in that case.
- Fixed by excluding all non-nullable columns
- Replaced JS Date object with raw SQL `CURRENT_TIMESTAMP`
2022-05-02 12:16:58 +02:00
Hannah Wolfe
438a368a01
Added deprecation comments and notes to schema.js
- Adding some missing context for some parts of the schema that aren't how we would have them in an ideal world
2022-05-02 11:05:13 +01: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
Renovate Bot
073b1f8dad Update dependency postcss to v8.4.13 2022-05-02 06:54:31 +01:00
Renovate Bot
e418630737
Update dependency mocha to v10 2022-05-02 01:29:26 +00:00
Renovate Bot
21b0ab0a8e
Update dependency express to v4.18.1 2022-04-29 21:07:20 +00: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