Commit Graph

5844 Commits

Author SHA1 Message Date
James Morris
1731723624 Alternative quote for email template 2021-12-02 14:13:50 +00:00
Thibaut Patel
7d9721dd54 Added one error catching inside the oembed service
refs https://github.com/TryGhost/Team/issues/1200

- The error was fixed in a1421c2380
- The error catching prevents future 500 errors in the API
- The logging enable visibility on these errors to fix them if they happen
2021-12-01 17:46:23 +01:00
Thibaut Patel
a1421c2380 🐛 Fixes oembed bookmark with whitespaces
refs https://github.com/TryGhost/Team/issues/1200

- The leading/trailing whitespaces are trimmed by `new URL()` but are considered invalid in metascraper. Trimming solves this edge case.
2021-12-01 15:58:09 +01:00
Sanne de Vries
ea50944897 Updated callout card class for consistency
No ref

- Swapped "kg-card-callout" for "kg-callout-card"
2021-12-01 14:25:33 +00:00
Kevin Ansfield
e9df5b9310 Fixed linter error
refs f91fc2add5

- with the removal of the labs check the labs service require is no longer used
2021-12-01 12:32:10 +00:00
Kevin Ansfield
f91fc2add5 Finished gifsCard labs flag removal
refs 5aa08acd33

- removed the flag check in public config output
- fixes failing tests
2021-12-01 12:29:50 +00:00
Naz
3150c87935 Fixed hidden validation error during frontend reload
refs https://github.com/TryGhost/Toolbox/issues/151
refs cbec6aa49e

- Without the await the try/catch block does not catch a pottential validation error straight away, which leads to a 500 error instead of a validation error being returned. The regression was introduced during the refactor (part of referenced commit).
2021-12-01 16:24:09 +04:00
Hannah Wolfe
004371be36
Revert "Removed overly-specific handling of handlebars errors"
This reverts commit 303ea87897.

- Although gscan catches these now, we have a number of sites that have slipped through the net
- Reverting until we get them all cleaned up
2021-12-01 12:04:36 +00:00
Naz
e6503e5148 Fixed invalid filename error during settings restore
refs https://github.com/TryGhost/Toolbox/issues/151
refs cbec6aa49e

- The error was happening due to incorrect "this" context. Because the filename and extension are only used once in this class and only for the purposes of the error message have moved the whole thing into the error message itself. No need to keep additional variables around when there's no clear usecase.
2021-12-01 15:47:13 +04:00
Sam Lord
18b8eddd0d Added linting for use of @tryghost/errors
refs: https://github.com/TryGhost/Toolbox/issues/147
Errors in @tryghost/errors rely on being called with an object (with a `message` member) rather than with a string.
2021-12-01 11:22:21 +00:00
Fabien egg O'Carroll
579b34434f Added separate confirmation email for paid signups
refs https://github.com/TryGhost/Team/issues/1067

As part of the work of automatically logging members in after payment,
we want to revisit the emails. Currently after payment we send an email
asking a member to _confirm_ their subscription, and that they can
ignore the email to cancel the subscription. This is not the case
however, as the member has already been subscribed.
2021-12-01 12:42:11 +02:00
Sam Lord
2887e416da
Switch to @tryghost/errors from ignition errors package (#13807)
refs: TryGhost/Toolbox#147

* Replaces all references to isIgnitionError with isGhostError
* Switches use of GhostError to InternalServerError - as GhostError is no longer public
There are places where InternalServerError is not the valid error, and new errors should be added to the @tryghost/errors package to ensure that we can use semantically correct errors in those cases.
2021-12-01 10:22:01 +00:00
Fabien egg O'Carroll
e6856f6ac6 Initial custom embed provider for Twitter
refs https://github.com/TryGhost/Team/issues/1001

We fall back to existing behaviour if no API key is present, or if there
is an error communicating with the Twitter API. We're also currently
requesting all the data, which will be thinned down once we understand
what we need.

This also includes a custom renderer for embeds of type "twitter" which
will be used to output the custom HTML for emails
2021-11-30 12:58:25 +02:00
Fabien egg O'Carroll
c4021b6eb4 Added OpenSea API key to config
refs https://github.com/TryGhost/Team/issues/1237

We want to use an API key for OpenSea where possible so that we do not
run into rate limit issues.
2021-11-30 12:58:25 +02:00
Hannah Wolfe
ad9eb35746
Moved theme-specific error handling to frontend
- our themeErrorRenderer is only used in the frontend.. move it there
- this required exposing prepareError as shared middleware
- TODO: move these shared compontents to @tryghost/error
2021-11-29 17:04:01 +00:00
Hannah Wolfe
d7c4168452
Removed HTMLErrorRenderer completely
refs: 0799f02e80
refs: 5e931e2e37

- with the referenced two commits I replaced our old HTML renderer with some code borrowed heavily from finalHandler
- I had intended to modify this further to out put our message, context and help error messages
- However, I ended up doing this in prepareError so it's done for all error renderers
- There's now very little point keeping duplicated code from finalHandler just to output the status code
- If we remove this code, express will fall back to finalHandler anyway, so the output is near identical
2021-11-29 17:00:47 +00:00
Hannah Wolfe
3b069b544f
Cleaned code patterns in error handler
- got rid of old _private & variable pattern in favour of const and module.exports
- changed weird capitalisation naming conventions to be camelCase
- removed some very old TODOs that we're never gonna get TODONE
   - these are mostly old ideas that never made it, and it's been so long they're clearly not important
2021-11-29 16:53:58 +00:00
Sam Lord
a21b91cc71 Added lint rules for migrations
refs: https://github.com/TryGhost/Toolbox/issues/105

Lint rules prevent:

* Invalid naming conventions for new migrations
* Loop constructs in migrations - these should be used with caution
and are therefore a warning rule, use `// eslint-disable-next-line
no-restricted-syntax` to prevent this rule from firing where a loop is
required
* Returing within a loop - this is usually meant to be a
continue/break
* Multiple joins - these can be badly performing migrations, so should
be treated with caution, disable the rule for the line if the risk is
understood / the migration cannot be written without it
2021-11-29 16:21:43 +00:00
Hannah Wolfe
8c93bdff41
Removed unnecessary BasicErrorRenderer
refs: 4474ca1a1d
refs: 0799f02e80

The BasicErrorRenderer was created as a fallback for when we needed to not render templates, which is
chiefly when we're trying to render a 404 for an image. Using a template puts us at risk of an infinite 404 loop
if the missing image is referenced in the 404 template.

As of 0799f02e, the HTMLErrorRenderer no longer uses templates - instead we serve a very simple HTML page.
This can be used instead of the BasicErrorRenderer, as it results in a properly formatted error.
Even when sending responses in plain text, the content type is returned as HTML and therefore having an
unformatted error makes no sense - if we really need a non-html format I guess there should be no body at all.
2021-11-29 15:40:55 +00:00
Naz
fa9d2a4105 Reworked media API thumbnail endpoint
refs https://github.com/TryGhost/Toolbox/issues/120

- Having an "options" parameter in the controller definition was missleading as if the `url` or `ref` parameters were expected as a part of the qurey parameter. These variables should be provided as a part of the request body, thus having them in "data" attribute is more accurate
2021-11-29 13:12:47 +04:00
Naz
b807be9699 Added JSDocs to redirects validator
refs https://github.com/TryGhost/Toolbox/issues/139

- Makes the expected file formatting easier to reason about
2021-11-26 06:18:36 +13:00
Naz
6ed5f64f4b Moved backup path calculation outside redirects module
refs https://github.com/TryGhost/Toolbox/issues/139

- Having tight coupling with backup file path calculation for redirects makes it extremely hard to test. In addition, having it injected will make it easier to swap this dependency to the mechanism similar to one used for routes files
2021-11-26 06:18:36 +13:00
Naz
edfe81e11c Moved validation dependency to constructor param
refs https://github.com/TryGhost/Toolbox/issues/139

- Having no external dependencies makes the class way easier to test
2021-11-26 06:18:36 +13:00
Naz
e6c9bcdf22 Moved custom redirects initialization to frontend init secton
refs https://github.com/TryGhost/Toolbox/issues/139

- The custom redirects services belong in the  initServicesForFrontend because frontend depends on these to function properly. When placed in general init section the middleware would not get initialized properly before it's used by the "frontend express app"
2021-11-26 06:18:36 +13:00
Naz
fd0a0ddf47 Refactored CustomRedirectsAPI constructor
refs https://github.com/TryGhost/Toolbox/issues/139

- The pattern we use accross the codebase is a single "options" object passed into a constructor instead of passing multiple parametes. Fixed the broken pattern in CustomRedirectsAPI constructor
2021-11-26 06:18:36 +13:00
Hannah Wolfe
303ea87897
Removed overly-specific handling of handlebars errors
refs: https://github.com/TryGhost/Ghost/issues/10496
refs: https://github.com/handlebars-lang/handlebars.js/issues/1548

- For a while, handlebars would and could generate quite a lot of obscure sytnax error messages for malformed helpers that we couldn't catch in gscan
- This was fixed in https://github.com/handlebars-lang/handlebars.js/issues/1548
- We have also since added AST parsing to gscan, so if there are more obscure syntax errors, we should be able to add rules to catch them
- Therefore, this additional, overly specific code block isn't needed anymore, so let's clean it up!
2021-11-25 14:53:36 +00:00
Naz
3315ed34ae 🐛 Fixed redirects.json file corruption on upload
refs 91efa4605c

- Referenced commit introduced a double json-stringification to uploaded redirects.json files.
- The endpoint has no stability index of any sort and is meant to be dropped in Ghost v5. It's best to rework the redirects to the yaml format as descirbe here - https://ghost.org/docs/tutorials/implementing-redirects/#file-structure
2021-11-25 18:43:45 +04:00
Hannah Wolfe
621cfd9866
Moved admin redirect middleware to named file
- moving this middleware because we're about to add a second piece of middleware
- it's easier to see what we have when each middleware is in its own file rather than in one big middleware.js file
2021-11-25 14:29:17 +00:00
Fabien 'egg' O'Carroll
eace98d787
Truncated offers.name to 40 characters (#13781)
refs https://github.com/TryGhost/Team/issues/1236

We use Offer names for the Stripe Coupon name - which has a limit of 40
characters. We are now introducing a limit of 40 characters to Offer
names too. This migration ensures that all our data in the DB is valid.
2021-11-25 12:33:22 +02:00
Hannah Wolfe
5e931e2e37
Added err.context & err.help to stack traces
- When we handle errors in Ghost, we are supposed to use a pattern of supplying 3 messages:
   - message: what went wrong
   - context: details about why how or where the error happened
   - help: where the user can go to get help with this error
- We do this in many places and our JSON error handler and CLI error logging tools are designed to output this extra information
- However, stack traces, which start with message as the first line and then output the stack are totally missing this
- By injecting the additional messages into the stack once an error has been "ghostified" we should get clearer messages everywhere

Notes:
- I've additionally injected a "Stack Trace:" line that makes it easier to read the error vs the stack
- This code looks a little weird because the lines are inserted backwards, but that allows us to always to the insert at position 1 as per the comment,
   so we don't have to keep track of whether we already injected something or not
2021-11-24 13:01:06 +00:00
Hannah Wolfe
0799f02e80
Rewritten HTMLErrorRenderer w/o asset helper & template
refs: 2af9e2e12

- This new HTMLErrorRenderer is borrowed heavily from finalHandler
   - This is the module that express uses to render errors if there is no custom errorhandler
- It just renders a really simple html page wrapping err.stack in a <pre>
   - This results in a nicely formatted, but unstyled error page
- I also updated BasicErrorRenderer to use the same res.statusCode + err.stack pattern rather than err.message

Note: This error renderer is _only_ used for renderering errors on the `/ghost/` route
 - In almost all cases, errors here are rendered by Ember
 - The only error that can be rendered here is a missing template error see: 2af9e2e12
2021-11-24 13:01:06 +00:00
Hannah Wolfe
2af9e2e125
Fixed error handling for missing admin templates
- If the admin templates default.html or default-prod.html are missing, don't throw a 500
- Instead throw a well considered 400 error with extra help for what to do to fix it
2021-11-24 12:30:41 +00:00
Hannah Wolfe
0c4c9ce553
Moved JSON error handlers next to each other
- helps for comparing and contrasting
- context is largely lost on why we have these two, need to figure it out and if possible, simplify
2021-11-24 11:42:53 +00:00
Hannah Wolfe
f417c4c732
Merged our two maintenance middleware into one
- Reduced our maintenance middleware code down to the bare minimum!
  - We have an old maintenance middleware in place to handle when a site is forcibly put into maintenance mode, or the urlService hasn't finished booting
    - This maintenance middleware was mounted on every sub app, instead of globally for reasons I no longer remember
  - Recently, we introduced a new, static version of maintenence middleware to show during the boot process so we can get the server started earlier & not drop requests
    - This version has its own HTML template and doesn't depend on any of Ghost's error rendering code
  - To simplify and help with decoupling, this commit merges the two middleware, so that the new independent & static middleware renders its template for any one of the 3 possible maintenance modes
    - It only needs to exist in the top level app 🙌

TODO: move the maintenance middleware to its own file/package so it's not part of the app.js as that is weird
2021-11-24 11:27:18 +00:00
Hannah Wolfe
6247aa4d8b
Added missing async/await calls
- throughout the theme activation flow there are several missing awaits and necessary async keywords
- we should be waiting on these processes, not letting them complete indeterministically
2021-11-23 17:24:50 +00:00
Naz
6ee94f66b4 Fixed invalid settings file path configuration
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- There were two separate instances of the SettingsPathManager in route-settings and settings-loader causing the configured paths missmatching on test environment. Because of this missmatch, uploading and resetting the routes.yaml file didn't work!
2021-11-24 05:32:20 +13:00
Naz
2fed8dbbd5 Moved all settings module bootstrap logic into init method
refs refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- The initialization outside the init method is causing problems when the configs are mocked during the test setup
2021-11-24 05:32:20 +13:00
Naz
cbec6aa49e Refactored route settings module into class
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings

- It's a step to making the module follow class+DI pattern before fully extracting it into an external libarary
- Reminder, doing in Ghost repo instead of substituting big chunks all at once to have clear history of how the service evolved prior to the extraction into external lib!
2021-11-24 05:32:20 +13:00
Naz
a9d742c2d3 Extracted getBackupFilePath out of route settings module
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- The method is used in a similar fassion in redirects modules, so should be a gret target for extraction and reuse.
- Bonuses: we drop 'path' and 'moment-timezone' dependencies from route settings module!
2021-11-24 05:32:20 +13:00
Naz
6d6aa12afe Extracted routes.yaml path calculation into external package
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings
refs e457fd5fe0 (diff-b292e8480eee007786cc602f55ed05006a06b8da9fe6934d51fbef8328013278R36)

- The full logic for  file path calculation for routes.yaml has been duplicated in couple modules. It is aslo following similar pattern used in redirects services and should be reused there once those modules are touched
2021-11-24 05:32:20 +13:00
Kevin Ansfield
1190ff1df0 Fixed errors being swallowed in oembed service
no issue

When switching the oembed service to async/await the error handling was not correctly refactored. `this.errorHandler(url)` was returning a curried function so it could be used as `.catch(this.errorHandler(url))` but that's not how it's being used after the async/await change meaning we were returning a function rather than the result of that function.

- `this.errorHandler(url)` is now only used in one place where `url` is available so removed the method and moved the body of the curried function inline into the `catch` handler
- added a message to the logged error so it's more clear what the log refers to
2021-11-23 10:58:52 +00:00
Sanne de Vries
969921f444 Fixed accent color background in email callout cards
Refs https://github.com/TryGhost/Team/issues/1206
2021-11-22 10:45:03 +01:00
Naz
bbc93ff996 Renamed withBackend/withFrotned to backend/frontend
refs https://github.com/TryGhost/Toolbox/issues/135

- Shorter name still makes sense and the "with" might be causing confusion understanding what's gonig on during the boot time
2021-11-22 21:56:32 +13:00
Naz
149c100b4c Fixed frontend initialization in "mock-express" tests
refs https://github.com/TryGhost/Toolbox/issues/135

- Without sensible defaults the web app was not initializing either the backend nor the frontned parts of the application. Fixed the defaults so the problem doesn't happen again and optimized mock-express-style initialization to only initialize the frontend routing
2021-11-22 21:56:32 +13:00
Naz
d0dfac438d Changed /^testing/ regexp use to startsWith method
no issue

- `startsWith` method is way easier to read and understand. also, **probably** has better performance comparing to building up a regexp and then matching
2021-11-22 21:56:32 +13:00
Naz
ae397eecdf Fixed UrlService initialization
refs https://github.com/TryGhost/Toolbox/issues/135

- When there's no instance of cache available the code to retreive it should not execut. Duh!
2021-11-22 21:56:32 +13:00
Naz
ae5dd8ad30 Fixed event listener pileup
refs https://github.com/TryGhost/Toolbox/issues/135

- When instantiating new Urls/Resources object in the UrlService's init on every test suite start it was loosing track of past events (softReset wasn't doing the cleanup properly). Not initializing new classes "fixes" the problem partially, by not loosing track of those event listeners. The real fix should be proper even listener cleanup on every soft reset!
2021-11-22 21:56:32 +13:00
Naz
34b0196c0f Added writeDisabled flag to URL file cache
refs https://github.com/TryGhost/Toolbox/issues/135

- Allows to turn off overwriting urls/resources JSON file caches on testing environment. This is needed to have predictable state when running multiple test suites that stop the Ghost process and try to persiste URL cache.
2021-11-22 21:56:32 +13:00
Naz
ee4d2dd1a8 Extracted a local file cache class for URLs
refs https://github.com/TryGhost/Toolbox/issues/135

- This extracts the file storage knowledge out of the URL Service an allows to have optional features based on the environment - for example turning off writing cache for when running tests
2021-11-22 21:56:32 +13:00
Naz
3b390639c4 Introduced booting from fixture url cache in test environment
refs https://github.com/TryGhost/Toolbox/issues/135

- To be able to reliably start ghost instance without a frontend the process needs access to urls/resources caches
- Storing the configuration in "paths" for now as there's no better place for it untill we are able to mock the content folder in pre-boot
2021-11-22 21:56:32 +13:00
Naz
c12ae81ece Introduced "withFrontend" and "withBackend" flags in boot
refs https://github.com/TryGhost/Toolbox/issues/135

- These flags are meant to control initialization of sections of the boot sequence depending on the needs - with or without bakend (API)/frontend (public handlebars site)
- Ideally these flags should not be passed deep into the components, and if the are (like in the web/parent/app case) it's a smell that we need to move things up into the boot process!
2021-11-22 21:56:32 +13:00
Hannah Wolfe
80358266b2 Added perf-improving PRAGMAs in testing mode
- These two things are meant to improve performance at the cost of reliability.
- Perfect for testing, however I think they make a minimal impact on modern SSDs :(
- Still worth a shot to see if it helps with CI
2021-11-19 10:47:21 +00:00
Daniel Lockyer
80d5f89382 Lazy loaded cheerio dependency
refs https://github.com/TryGhost/Toolbox/issues/136

- `cheerio` isn't needed during the boot but it takes time and memory to
  load the library
- this commit moves `cheerio` requires later into the code to when they
  are needed
2021-11-18 17:31:04 +01:00
Kevin Ansfield
ca26c3ab0a Added logging of unexpected errors in oembed service
no issue

- if we encounter an unexpected error whilst fetching embed details we return a generic validation error so we're not leaking any details about the URL that is being hit, however that meant the error logs were only showing validation errors making debugging difficult
- added explicit logging of the unexpected error before throwing the generic validation error
2021-11-17 13:31:20 +00:00
Peter Zimon
bbceace31c Implemented table based NFT email styles 2021-11-17 14:05:39 +01:00
Sam Lord
0692ddf57d Revert "Replace update user last seen middleware with package version"
This reverts commit 07f8c6efbb.

Revert "Remove unused unit test file"

This reverts commit f1798119d3.
2021-11-17 11:00:55 +00:00
Hannah Wolfe
332beaaf90
Moved "vhost-utils" to config helpers
- These are simple functions that get data from config in a specific format
- They are also used by the topmost part of the application
- Config helpers seems like a reasonable fit to get them out of the web folder
- Functions have also been renamed to try to get them to make more sense
2021-11-17 08:37:08 +00:00
Fabien O'Carroll
e6773d00e6 Updated NFT Embed custom provider
refs https://github.com/TryGhost/Team/issues/1211

Added ?format=json to the URL in an attempt to mitigate any issues with
weird caching and receiving HTML rather than JSON.

Used `type` in place of `card_type` to closer follow how the bookmark
card/embed works.

Removed the html & width/heihgt properties which are not needed at all.
2021-11-16 21:28:36 +02:00
Sanne de Vries
b6b024b132 Fixed missing bottom spacing on email callout cards 2021-11-16 19:19:49 +01:00
Kevin Ansfield
63b7ef7dc6 Added Tenor contentFilter setting to config
refs https://github.com/TryGhost/Team/issues/1217

- moved top-level `tenorApiKey` to `tenor:apiKey` and added `tenor:contentFilter`
- added base config to `defaults.json`
- updated `public-config.js` and API output serializer to use the new top-level `tenor` key
2021-11-16 17:42:26 +00:00
Sam Lord
a5484a0fe1 Fixed transaction logic in data importer
https://github.com/TryGhost/Toolbox/issues/130

The transaction no longer commits in the promise chain, which wasn't
valid logic for a transaction, since it is commited automatically when
the promise chain resolves, and rollsback automatically when the
promise chain rejects.

This makes code which fails during the transaction error in the right
place, instead of getting stuck here. (Especially good for writing
tests).

The tests for this code can now live in the integration folder.
2021-11-16 17:09:55 +00:00
Sam Lord
07f8c6efbb Replace update user last seen middleware with package version
no issue

Part of the goal to move these middleware packages to remove untested code from the codebase
2021-11-16 15:58:45 +00:00
Hannah Wolfe
4f9b72ff43
Renamed middlewares to middleware consistently
- This is a minor bugbare, but it will affect some configuration I'm about to do for c8
- I've been wanting to do it for ages, middleware is plural all on it's own so it's an odd affectation in our codebase
- This also only exists in 2 places, everywhere else we use "middleware"
- Sadly it did result in a lot of churn as I did a full find and replace, but consistency is king!
2021-11-16 15:51:47 +00:00
Hannah Wolfe
b781e47cb9
Changed to use different fixtures during testing
- this keeps production and test fixtures separate, so that changing the prod fixtures doesn't change the shape of our tests.
- we may still want to test that the production fixtures do what we expect, but that can be handled in a separate integration test, by specifically setting the fixture path
2021-11-16 14:03:42 +00:00
Hannah Wolfe
426c8bf918
Refactored fixtures to be loaded by fixture manager
refs: https://github.com/TryGhost/Toolbox/issues/133

- instead of just a collection of utils, we now have a class that manages fixtures
- this should allow us to change the path to fixtures, e.g. between prod/dev and test, so that different fixtures can be loaded by default
- also makes it easier to test the fixture manager code itself
2021-11-16 11:17:03 +00:00
Naz
458f5b894b Moved Urls and Rexources reinitialization
refs https://github.com/TryGhost/Toolbox/issues/127

- New instances or Urls and Resources during init were messing up test suites without an obvious solution. Moved them to only be triggered when the cache is present.
- Note the e2e-frontend tests are failing if thie initialization happens every time when init is called. There seems to be some reliance on Resources being the same intsance between "softReset" which seems wrong, but wasn't able to track it down definitevely
2021-11-17 00:00:23 +13:00
Naz
1a3a80cacc Added resource cache handling to UrlService
refs https://github.com/TryGhost/Toolbox/issues/127

- The resource cache is needed to have quick and reproducible state of the resouces tied to the urls instead of waiting for the db queries to finish.
- Allows to use UrlService without any database connection at all - useful for unit testing
2021-11-17 00:00:23 +13:00
Naz
9b309cf4e7 Refactored URL cache persistance
refs https://github.com/TryGhost/Toolbox/issues/127

- This refactor is needed to accomodate incoming "resource cache" which shares a lot of common logic with how url cache is operated
2021-11-17 00:00:23 +13:00
Hannah Wolfe
88311381ef Added a URL Service boot log
- At the moment there's no way to see in the logs when the URL Service finally finishes
- This is the moment when Ghost stops serving 503s
- Adding this log line so it's clear to see, which migh be useful whilst were refactorising
2021-11-16 19:13:36 +13:00
Sanne de Vries
632e15affc Added callout card email styles
Refs https://github.com/TryGhost/Team/issues/1206
2021-11-15 19:45:33 +01:00
Naz
83a54eeb99 Fixed UrlService's getPermalinkByUrl method
refs https://github.com/TryGhost/Toolbox/issues/127

- The "withUrlOptions" is used internally in the constructor by the frontend's routers. To avoid passing around a whole function from the frontend routers duplicated the functionality from there.
2021-11-15 19:40:44 +04:00
Naz
042618fe93 Fixed failing tests
refs 5a62253466

- The UrlService was relying on a "hidden" identifier field that was passed along with a router object. Now it's passed as an explicit parameter from the "frontend" to the backend's UrlService
2021-11-15 19:37:49 +04:00
Naz
5a62253466 Removed "router" dependency from UrlGenerator
refs https://github.com/TryGhost/Toolbox/issues/127

- Passing around whole instance of a frontend router was an overkill when there are only 3 static pieces of information that needed to be loaded. Extracting the router out makes the UrlGenerator way more readable, tests slimer, and the memory footpring of the process should be slightly lighter
- The toString overloading didn't make sense at the time of this refactor, maybe if there's a concrete usecase we could resurect it in a form of passing in a router's name or something.
2021-11-15 18:32:34 +04:00
Naz
6e205a3f05 Extracted an explicit "permalink" parameter in UrlGenerator constructor
refs https://github.com/TryGhost/Toolbox/issues/127

- This is an effor t to define a precise set of data needed for the UrlGenerator to function, which should help with decoupling it from the frontend routes
- This is almost the last piece to free us up from the massive "router" object that has been passed around
2021-11-15 18:32:34 +04:00
Naz
677ea1073d Extracted an explicit "resourceType" parameter in UrlGenerator constructor
refs https://github.com/TryGhost/Toolbox/issues/127

- This is an effor t to define a precise set of data needed for the UrlGenerator to function, which should help with decoupling it from the frontend routes
2021-11-15 18:32:34 +04:00
Naz
ca2809d432 Extracted an explicit "filter" parameter in UrlGenerator constructor
refs https://github.com/TryGhost/Toolbox/issues/127

- This is an effor t to define a precise set of data needed for the UrlGenerator to function, which should help with decoupling it from the frontend routes
2021-11-15 18:32:34 +04:00
Naz
176c369620 Refactored UrlGenerator to use DI constructor pattern
refs https://github.com/TryGhost/Toolbox/issues/127

- This is a standard across the codebase which is good to follow for better testability
2021-11-15 18:32:34 +04:00
Naz
33d02cddfe Added JSDocs to the UrlGenerator class
refs https://github.com/TryGhost/Toolbox/issues/127

- Before refactoring the URL Generator constructor to have a smaller construcotr, documented current state for future reference
2021-11-15 12:41:52 +04:00
Fabien O'Carroll
31e103be9d Updated NFT OEmbed provider to return metadata
refs https://github.com/TryGhost/Team/issues/1211

Instead of rendering the HTML as an embed - we will send back the
necessary data. This will allow us to keep all the knowledge of HTML
structure in the Koenig repository.
2021-11-15 10:31:35 +02:00
Peter Zimon
a68854c3bd Added NFT card email styles
- added email styles for NFT cards
- fixed buttons having capitalized text
2021-11-12 16:39:35 +01:00
Peter Zimon
661bde3892 NFT card frontend style refinements 2021-11-12 15:55:19 +01:00
Naz
04c6716171 Moved url cache loading logic behind the flag
refs https://github.com/TryGhost/Toolbox/issues/125

- The url loader is not fully working and is in very experimental mode. The aim is to ship this version to allow other team members to play with the feature in limited use-cases like testing evnironment
2021-11-13 01:01:28 +13:00
Naz
4582fd48b5 Parameterized url cache storage path
refs https://github.com/TryGhost/Toolbox/issues/116

- This should allow testing in a bit easier manner and would place the file into a more suitable directory
- ideally we'd put an alfa flag bahind this new "cached routes" feature to have less consequences to deal with if we have to back out
2021-11-13 01:01:28 +13:00
Naz
36bc05447c Booting instance with persisted urls
refs https://github.com/TryGhost/Toolbox/issues/116

- This is a PoC to check out how viable this approach is and if it's worth merging into main as a very quick win
- The `urls.json` is in a bad place right now should probably live in a data folder
2021-11-13 01:01:28 +13:00
Fabien O'Carroll
39f01f4925 Removed SVG from NFT OEmbed
refs https://github.com/TryGhost/Team/issues/1211

The SVG is causing issues with copy/paste in Firefox, we're going to
remove it and later replace it with a PNG.
2021-11-12 12:43:25 +02:00
Naz
b707f325c8 Exposed config initialization from Resources
refs https://github.com/TryGhost/Toolbox/issues/125

- Config initialization for the URL Resouces is a separate stage which doesn't have to be bundled along with resouce fetching method
- It gives even more flexibility when composing different ways to get the "resources" loaded into memory: right now it's from the DB but could come from a cache
2021-11-12 12:18:17 +04:00
Naz
963df37aaa Reworded UrlService's init documentation
refs https://github.com/TryGhost/Toolbox/issues/125

- The "init" method pattern is not used across the codebase and it's pretty standard to start the service in this way. Previous description was outdated and misguiding
2021-11-12 12:16:08 +04:00
Naz
39b480682f Fixed UrlService initialization
refs https://github.com/TryGhost/Toolbox/issues/125

- The await was missing from the "fetchResources" call which made the queue pick up less information than it should've
2021-11-12 12:15:01 +04:00
Naz
376e2f4cf3 Separated event listeners from resource fetching
refs https://github.com/TryGhost/Toolbox/issues/125

- The "fetchResources" method did way to many things extracted event listener setup logic to a separate method
- This allows to call out these stages as needed if we retreive resources separately from a cache of some sort and don't need to wait for the database response
2021-11-12 11:56:16 +04:00
Naz
46c3b53979 Moved queue start into UrlServices init block
refs https://github.com/TryGhost/Toolbox/issues/125

- The "fetchResources" is only used from one place and does way to many things at once:
- Fetches resources from the DB-
- Hooks up event listeners
- Starts the queue

- These are three different things, and should be three different methods ideally
2021-11-12 11:56:16 +04:00
Kevin Ansfield
6431e1a01c
Exposed tenorApiKey via config endpoint if set (#13734)
refs https://github.com/TryGhost/Team/issues/1217

- add `tenorApiKey` to `publicConfig.config()
- update canary config endpoint output serializer to include `tenorApiKey` when the `gifsCard` labs flag is enabled
2021-11-11 18:07:19 +00:00
Fabien O'Carroll
dda8e0249b Wired up NFT custom provider to canary API
refs https://github.com/TryGhost/Team/issues/1211

This registers the NFT custom OEmbed provider to the OEmbed service for
the canary API. This should probably be done in a centralised place -
but we do not have a single instance of the OEmbed service.

When we have more information about why the OEmbed service is
instantiated like this, we can think about moving it into a singleton
service with an `init` method - which is where we can register custom
providers.
2021-11-11 17:16:03 +02:00
Fabien O'Carroll
3b7284b62f Initial OpenSea NFT OEmbed customer provider
refs https://github.com/TryGhost/Team/issues/1211

This adds the initial custom OEmbed provider for OpenSea NFT's - we're
using the new custom provider functionality so that we can easily change
the logic here without affecting the core functionality.
2021-11-11 17:16:03 +02:00
Fabien O'Carroll
e69d112c77 Added support for custom OEmbed providers
refs https://github.com/TryGhost/Team/issues/1211

In order to override the default OEmbeds for OpenSea NFT's we need a way
to provide out own OEmbed data. We will want this in future too for
custom Twitter embeds, so this has been built in a way which allows
extension.
2021-11-11 17:16:03 +02:00
Naz
a64c186179 Fixed typo
no issue
2021-11-11 16:52:11 +04:00
Fabien 'egg' O'Carroll
7fae5b8341
🐛 Fixed setting Tier prices after changing Stripe accounts
refs https://github.com/TryGhost/Team/issues/1212

This now emits the event when the service is reconfigured, rather than
when we issue the reconfigure command, which causes the event and the
action to be run in the wrong order. This would then cause knock on effects
of having the database in an undefined state - with stripe data in not linked
to the current Stripe account.
2021-11-10 14:03:03 +02:00
Naz
4721b75463 Moved `/media/thumbnail/ Admin API endpoint to /media/thumbnail/upload
refs  https://github.com/TryGhost/Toolbox/issues/120

- Changed endpoint name as it suits way better to the `/upload` postfix convention we use along with all other endpoints that support file uploads
2021-11-09 16:39:33 +04:00
Naz
61b82e3ae2 Added thumbnail upload endpoint to Media API
closes https://github.com/TryGhost/Toolbox/issues/120

- Allows to update and upload brand new thumbnail images for previusly uploaded media resources
- The endpoint is available udner alpa flag as part of Admin API at `PUT /media/thumbnail/`
- As an input accepts following parameters:
- *required* `file` field containing an image file
- *required* `url` field containing parent media file URL
- *optional* `ref` as a field to put in an ID to reference the resource on the client side

- The response has following format:
```
{
  media: [{
    url: 'http://127.0.0.1:2369/content/images/1991/11/nicevideo_thumb.png'
    ref: 'unique-id-420'
  }]
}
```
2021-11-09 16:07:23 +04:00
Naz
2a7ef77a7b Added ability to delete existing files through storage adapters
refs https://github.com/TryGhost/Toolbox/issues/120

- When editing an uploaded media thumbnail  file there'a need to remove existing thumbnail to keep media files:thumbnails 1:1. - Because the API client only has a public URL under which the resource is served it can only provide that as an API input, the `urlToPath` was also added to the base class of LocalStorageAdapter (it might be moved up to the BaseAdapter in the future if we see a need)
2021-11-09 16:07:23 +04:00
Naz
3f59c1893b Renamed variables to better fit the context
no issue

- Slightly less code without compromising readability
2021-11-09 16:07:23 +04:00
Naz
92986b77e3 Renamed whitelist -> allowlist
no issue

- Renames to follow the naming convention from https://mysqlhighavailability.com/mysql-terminology-updates/
2021-11-08 16:09:30 +04:00
Naz
f0242baf9f Added static file limit handling in Files API
refs https://github.com/TryGhost/Toolbox/issues/114

- Just like with media files same limits apply and can be configured through the usual limit service's config
2021-11-08 16:09:30 +04:00
Naz
a099073fde Added Files API behind an alpha flag
refs https://github.com/TryGhost/Toolbox/issues/114

- Files API is meant to be used for non-executable file uploads of all sorts
- The files are stored and retrieved for download as-is
2021-11-08 11:40:17 +04:00
Naz
151ab6968c Added local file storage adapter
refs https://github.com/TryGhost/Toolbox/issues/114

- This adapter is meant to power Files API
- The files will be stored under `/files/` in the configured content path and under `/content/files/` URL.
2021-11-08 11:29:33 +04:00
Naz
f43eeacfd0 Changed thumbnail to be an optional parameter
refs https://github.com/TryGhost/Toolbox/issues/95

- With incoming support of audio media files thumbnail would not be a required parameter
2021-11-05 17:17:18 +04:00
Naz
ad2583530a Renamed getLocalFileStoragePath
refs https://github.com/TryGhost/Toolbox/issues/95

- getLocalImagesStoragePath makes a lot more sense in context of what the method really does
2021-11-05 17:17:18 +04:00
Naz
12cad62a53 Fixed up JSDoc
no issue

- The method description was a complete tautology
2021-11-05 17:17:18 +04:00
Naz
22ac28b250 Fixed ThemeStorage inheritance
refs https://github.com/TryGhost/Toolbox/issues/95

- The ThemeStorage was never supposed to inherit image specific mehods. The LocalStorageBase is all it needs, might be even too much
- Look mum no saveRaw!
2021-11-05 17:17:18 +04:00
Naz
c802097b72 Renamed LocalFileStorage to LocalImages store
refs https://github.com/TryGhost/Toolbox/issues/95

- This naming corresponds way better to what the actual adapter does
2021-11-05 17:17:18 +04:00
Naz
f3fc1bd5d4 Extracted local storage adapters' into a base class
refs https://github.com/TryGhost/Toolbox/issues/95

- The MediaStorage adapter and LocalFileStorage were almost identical, having a common base class makes sense here.
- Having a distinct class for the "LocalFileStorage" makes it easy to spot the implementation difference from the StorageBase - the "saveRaw" method, which is not present in the StorageBase
- The LocalFileStorage will become an LocalImageStorage in next commit as that name corresponds way better to what it does!
- Test files need a good cleanup
2021-11-05 17:17:18 +04:00
Naz
142eff22ee Fixed thumbnail file name
refs https://github.com/TryGhost/Toolbox/issues/95

- The uploaded media thumbnail name should have a "_thumb" postfix to be able to distinguish thumbnails from other files. This can be handy if we decide to store them in a different location in the future.
2021-11-04 19:03:45 +04:00
Rishabh Garg
3b90b1f335
Moved launchComplete user setting as global editor setting (#13703)
refs https://github.com/TryGhost/Team/issues/807

The launch wizard completed flag was previously stored at per user level in accessibility column of user table, so an administrator still got the option to complete the launch wizard even if the owner had completed it previously, which is not expected pattern. This change moves the launch complete flag for Admin to common settings from per user level so a site only needs to complete the launch wizard once irrespective of which user completes it

- adds new `editor_is_launch_complete` setting to track if a site launch steps are completed in Admin
- adds new migration util to easily allow adding new setting 
- adds migration to introduce new `editor_is_launch_complete` setting
- adds migration to update launch complete flag for a site if any of the users have already completed the launch steps
2021-11-04 18:03:51 +05:30
Naz
df5c87fae3 🐛 Fixed a 500 error when uploading invalid routes.yaml
closes https://github.com/TryGhost/Toolbox/issues/111

- Just like with invalid JSON redirects files we should return a BadRequestError instead of throwing a generic 500 when the redirects.yaml file fails parsing
2021-11-04 11:52:52 +04:00
Naz
2dac3d489f Added "mediaAPI" labs flag
refs https://github.com/TryGhost/Toolbox/issues/95

- A flag go control the Media API alpha feature
2021-11-04 10:48:53 +04:00
Naz
091240db48 Added thumbnail upload support to Media API
refs https://github.com/TryGhost/Toolbox/issues/95

- Each media file quires a thumbnail and these changes provide a capability to upload them along with media files.
- The thumbnail file is always required and has to be the format of already supported image formats
- The thumbnail should be uploaded as a part of "thumbnail" attachment in the request
- The regression tests added with this changeset will be claened up and moved to unit-tests (this is a dirty-but-working version!)
- The thumbnail always gets a name of the uploaded media file and keeps it's own extension.
- The thumbnails is accessible under the url present in the "thumbnail_url" reponse field
2021-11-04 10:23:29 +04:00
Fabien O'Carroll
6e53527666 Fixed init method for Offers service
refs https://github.com/TryGhost/Ghost/commit/da152a0a1

The cleanup of the Offers labs flag inadvertently removed this logic.
2021-11-03 17:17:33 +02:00
Fabien 'egg' O'Carroll
da152a0a13
Removed references to Offers labs flag (#13709)
refs https://github.com/TryGhost/Team/issues/1115

This feature is now GA, and the flag has been hardcoded to `true`, here we clean up the
remaining references as they're no longer needed.
2021-11-03 17:11:48 +02:00
Sanne de Vries
6c487ca2c9 Fixed links overflowing in mobile email preview in Chrome 2021-11-03 11:12:32 +01:00
Naz
0ccf31cdb5 Fixed error message when booting with no redirects
refs 91efa4605c

- When the instance is booted without any redirects files configured it's not supposed to error but rather default to an "empty" [] redirects configuration.
- Ideally the logic shoudl not contain try/catch block at all and fail as soon as there's any error during the initialization. This wasn't changed at this time due to possible break of existing Ghost instances
2021-11-03 13:50:24 +04:00
Naz
e1d16a55e1 Fixed DynamicRedirectManager initialization
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- After a bump of the '@tryghost/express-dynamic-redirects' the constructor has changed it's signature, so this needed an adjustment
2021-11-03 07:41:55 +13:00
Naz
c3edd4b3d4 Fixed redirects regression tests
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- The problem this change is addressing is inability to override config values once the code is extracted into a class+DI pattern
- The work around is restarting the instance with the configuration testing expected behavior - in this case missing or existing types of redirects files
2021-11-03 07:41:55 +13:00
Fabien O'Carroll
91efa4605c Used DynamicRedirectManager for Custom Redirects
refs https://github.com/TryGhost/Members/commit/9e59f5a9

Since we have a DynamicRedirectManager for handling adding/removing
redirects at runtime, we no longer need the custom-redirects middleware.
The redirects service does however need an init method now to add the
custom redirects at Ghost boot, so it's been refactored into our Class &
DI pattern.
2021-11-03 07:41:55 +13:00
Naz
d657432531 Cleaned up use of 'content/media' magic string
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- `content/media` path is now a part of the constants package and should've been used instead of a magic-string.
2021-11-03 00:33:28 +13:00
Naz
d20732ce34 Imroved media validation middleware
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- Error messages are now more specific when uploaded media files fail the validation check
2021-11-03 00:33:28 +13:00
Naz
02da62ee48 Added limit service check for uploaded media filesize
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- Uploading large files is costly and might cause DDoS. Limits would allow fair use of the site instance.
- The configureation in hostSettings to enable an "uploads" limit would look like following:
```
"hostSettings": {
    "limits": {
            "uploads": {
                "max": 5,
                "error": "Your plan supports uploads of max size up to {{max}}MB. Please upgrade to reenable uploading."
            }
    }
}
```
- Read more at ba37890be4/packages/limit-service (usage)
2021-11-03 00:33:28 +13:00
Naz
d5b1552dc9 Simlified limit service initialization
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- Init function for the limits service initialization is never called with parameters, so it doesn't make sense to keep that option around and have unnecessary logic handling it
2021-11-03 00:33:28 +13:00
Naz
f9a8edb1a0 Refactored upload middleware
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- Using a wrapping object to store enableClear/multer instances didn't make any sense
2021-11-03 00:33:28 +13:00
Naz
4a551661d9 Implemented '/media/upload' API endpoint
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- This is an experimental implementation of video file upload support
- Also the output serializer skipped use of url utils in favor of inline implementatoin - this should almost certainly be it's own package
2021-11-03 00:33:28 +13:00
Naz
5242566252 Added local media storage adapter
refs https://linear.app/tryghost/issue/CORE-121/create-a-video-storage-adapter

- This is an experimental implementation of video file upload support (audio is yet to follow)
- The storage adapter still needs more thinking as it's almost the same as the "LocalStorgeAdapter" that stores images.
- Also the output serializer skipped use of url utils in favor of inline implementatoin - this should almost certainly be it's own package
2021-11-03 00:33:28 +13:00
Fabien O'Carroll
c45afc7f26 🐛 Fixed email type when creating Members via API
refs https://github.com/TryGhost/Team/issues/1197

We were always sending the 'signin' email, rather than respecting the
email_type param passed to the API. This updates our email sending when
creating members to force the requested type if it's present.
2021-11-02 12:56:00 +02:00
Rishabh
1a9705b824 🐛 Fixed error in setting page access to tiers
closes https://github.com/TryGhost/Ghost/issues/13704
closes https://github.com/TryGhost/Team/issues/1186

- updates page serializer to handle new `visibility_filter` property for filtering access on specific tier
- this change was already added for `posts` but was missed on `pages`, so parsing filter on `visibility` filter was failing
2021-11-02 13:36:32 +05:30
Fabien 'egg' O'Carroll
b36d0cc1c4
🐛 Fixed idempotentcy of addPermissionToRole util (#13685)
refs https://github.com/TryGhost/Team/issues/1178

The "up" migration that this util generates correctly throws if the
pre-requisite data cannot be found in the database. The "down" migration
however was incorrectly mirroring this behaviour of throwing - which
meant that it wasn't idempotent, as it does not require a permission or
role to existing if it wants to move relations between them.
2021-11-01 09:27:50 +00:00
Thibaut Patel
d0933c51ad Revert "Switched AMP to be 'off' by default in all new Ghost instances"
This reverts commit 98fd48cb32.
2021-10-28 18:52:31 +02:00
Thibaut Patel
98fd48cb32 Switched AMP to be 'off' by default in all new Ghost instances
refs https://github.com/TryGhost/Team/issues/1189

- The world & internet is slowly moving away from AMP
2021-10-28 18:13:25 +02:00
Naz
d89b8448ab Added a not to the Images API ref field
refs https://github.com/TryGhost/Ghost/pull/10534

- The original PR has no explanation around the purpose of the ref field and it's easy to forget without knowing a wider context. Documented it to remember next time we come around working on this part of the codebase!
2021-10-28 16:05:54 +04:00
John O'Nolan
297e173544 Updated member signup email copy 2021-10-26 17:53:35 -04:00
Fabien O'Carroll
bccc8790f0 Fixed max-complexity-warnings for stripe_connect API
no-issue

This removes the logic to check if stripe connect is allowed into the
stripe connect service, which makes the feature easier to maintain, as
well as fixes the v3 API - which previously did not have this check.
2021-10-25 14:06:28 +02:00
Fabien O'Carroll
a68b96001c Fixed max-complexity-warnings for members API
no-issue

This removes logic from the Members API controller, and into the Members
BREAD service, this allows our controllers to be simpler and easier to
maintain, as well as keeping the important logic all together.
2021-10-25 14:06:12 +02:00
Kevin Ansfield
a485509a2f
🐛 Fixed GA labs flags not appearing enabled in settings API (#13681)
no issue

The way GA flags were introduced means that they stop existing in the `'labs'` setting in the db and are instead forced to always return `true` when checking the flag in the labs service. However, Admin which uses the flags fetches them via the `/settings/` API endpoint which was only returning the raw labs setting db value meaning GA flags appeared to be disabled unless the flag had previously been enabled and no settings save had occured.

- updated the settings bread service to replace the labs setting value with the JSON stringified output of `labs.getAll()` which is the ultimate source-of-truth for a feature being enabled/disabled
  - extracted `browse()` behaviour to an internal `_formatBrowse()` method so we can apply the same filtering/modification for output of `browse()` and `edit()`

Co-authored-by: Fabien O'Carroll <fabien@allou.is>
2021-10-22 19:59:13 +01:00
Fabien O'Carroll
f3bb6b43a5 Added Offers feature to Ghost
refs https://github.com/TryGhost/Team/issues/1115

This allows users to create Offers for Tier/Cadence pairs in order to
provide discounted subscriptions to Members! We have support for
percentage based discounts & fixed price discounts, either for the first
payment, all payments, or a number of monthly payments.

Offers also have a code, which can be used as an easy way to share them,
as visiting https://site.com/offer-code will automatically open Portal
with the Offer prepopulated.
2021-10-22 17:55:34 +02:00
Fabien O'Carroll
696d8e3c49 Added 404 handling for edit Offer
no-issue

This was also missing as part of the Offers API.
2021-10-22 16:16:39 +02:00
Kevin Ansfield
0c6cd37679 Fixed missing space between authors in emails
no issue

- author line was appearing as "Author One,Author Two,..." with no space
- fixed the generation of `post.authors` when serializing a post before it's rendered for email
2021-10-22 14:41:15 +01:00
Daniel Lockyer
e834904125
Fixed verification threshold when set to 0
no issue

- if the verification threshold is 0, `_.get(..)` becomes falsy so we
  fallback to Infinity
- this is not correct - we only want to default to Infinity if the value
  is not set
- this commit explicitly compares the config value to `undefined` and sets
  the fallback accordingly
2021-10-22 15:33:59 +02:00
Kevin Ansfield
d7fbf94d91
Fixed ETag header for admin templates not changing between versions (#13680)
refs https://github.com/TryGhost/Team/issues/1175

We found the ETag header sent when serving the Admin template for /ghost/ was not changing between versions which after an upgrade could result in out of date cached content being served containing links to JS/CSS files that no longer existed.

The culprit is weak etags served by Node's `send` package, coupled with Admin template filesize not changing between versions and `npm pack` setting a fixed modification date for every file. See https://github.com/pillarjs/send/issues/176 for more details.

- updated the Admin app's controller to read the template and generate an md5 hash of the contents so we can serve a strong ETag header value when serving the `/ghost/` html
2021-10-22 14:25:58 +01:00
Fabien O'Carroll
363eb94aee Handled 404 for Offer not found
no-issue

This was missing handling! We need to throw a NotFoundError so we
return with the correct response.
2021-10-22 14:22:33 +02:00
Fabien 'egg' O'Carroll
d962f0e18e
Removed NOT NULL constraint from portal_title (#13659)
refs https://github.com/TryGhost/Team/issues/1163

We want to make the title for Offers optional, our nullable validation
means that we cannot store an empty string, so we must remove the NOT
NULL constraint from the column if we want to store either an empty
value or null.

There is a bug with editing columns in SQLite with `knex` which strips all
the indexes, so we have to manually add them afterwards.
2021-10-22 14:14:49 +02:00
Daniel Lockyer
ed6a8dca76 Inlined package requires to save boot time and memory
no issue

- following on from f4fb0fcbaa,
  this commit moves around some package requires in Ghost
- these are often niche packages that do something in a subsystem of
  Ghost, and are not necessarily be needed to boot the application
- these packages use non-negligible CPU and memory when they are
  required, so it makes sense to lazy-require them
- the concern here is that we obscure the code too much by moving
  random requires further into code, but the changes are small and the
  improvements big
- this commit bring the boot time since 4.19.0 down ~31% and initial
  memory usage down by a total of ~12%
2021-10-22 09:57:59 +02:00
Hannah Wolfe
faea2da596
Moved server/web/site to frontend/web
- we're slowly trying to draw the lines between the backend and the frontend correctly
- these files deal only with serving the frontend so they should live there
- there are lots of mixed requires in these files, so having them in the right place makes that clear
2021-10-21 19:28:18 +01:00
Fabien O'Carroll
8c9b4d18bf Fixed error when enabling Offers via labs
no-issue

The listOffers method requires an options object. This was missed during
the update.
2021-10-21 20:05:42 +02:00
Hannah Wolfe
2777093c76
Refactored model init to be implicit
- no more need to explictly add a model file to be loaded!
- this makes building Ghost just the tiniest smidge easier
2021-10-21 17:01:26 +01:00
Hannah Wolfe
99fde5154f
Fixed dependency on the order of models
- this has been a niggle for ages, we shouldn't need to care what order our models are loaded in
- this is stopping us from having a built-in model loader and "frameworkizing" models
2021-10-21 16:57:36 +01:00
Kevin Ansfield
1708f0c3a4 Fixed custom theme settings not being available when expected
closes https://github.com/TryGhost/Team/issues/1172

Custom theme settings sync and cache population had been left to complete in the background as it wasn't essential for it to be complete for the front-end to start. However that was causing problems for the API where theme activation and custom theme settings list requests happen very close together, with the latter often not containing the theme settings data when it is expected to.

- changed `activationBridge.*` methods to `async` so they can `await` the completion of custom theme settings sync before activating a theme
2021-10-21 15:02:52 +01:00
Fabien O'Carroll
39160fc794 Passed Offer model to MembersAPI
refs https://github.com/TryGhost/Team/issues/1166

The MembersAPI needs access to the Offer model so that we can remove all
the Stripe related data when Stripe is disconnected.
2021-10-21 15:39:26 +02:00
Fabien O'Carroll
03d4561a5f Added relation between Member & OfferRedemption
refs https://github.com/TryGhost/Team/issues/1135

This will allow us to fetch the OfferRedemptions for a Member so that we
can display them on the Member details page.
2021-10-21 15:39:26 +02:00
Iuri Mendes
7debc28832
Removed "The team at X" from member emails (#13615)
closes: https://github.com/TryGhost/Ghost/issues/13613

- The language "The team at X" didn't suit all Ghost users. The language is more appropriate without it.
2021-10-21 13:58:34 +01:00
Hannah Wolfe
a1ad9f2870
Reworked init migrations to use async/await (#13635)
- use async/await and fat arrow syntax
- makes it easier to refactor later as "this" context is then reliable
2021-10-21 11:19:59 +01:00
Naz
07afb08875 Made storage calls related to images use "images" feature
refs https://linear.app/tryghost/issue/CORE-1/multiple-adapters-per-type

- Having this preemptive change allows to separate implementation of "image" storage from future usecases like "videos", "audios" etc. Even if the "image" adapter is not configured the default behavior will fallback to use the "active" storage adapter. If there's a need to handle "images" differently through a custom apapter that'll work out of the box ;)
2021-10-21 20:22:45 +13:00
Naz
f890d8d4cd Enabled passing through a feature name to utilize with a storage adapter
refs https://linear.app/tryghost/issue/CORE-1/multiple-adapters-per-type

- When the storage is requested the caller can now specify a "feature" they want to use the storage for. For example there could be different configurations for "images" or "vidoes" storages and the caller would not necessarily have to know about the details of how the feature is implemented.
2021-10-21 20:22:45 +13:00
Naz
98c27b5555 Added multiple adapters capability to adapter manager
refs https://linear.app/tryghost/issue/CORE-1/multiple-adapters-per-type

- There's a need to support multiple adapter variations per given adapter type (storage, sso, etc.)
- With the introduced changes we can specify a version of an adapter that should be fetched based on `:feature` postfix. For example:

`adapterManager.getAdapter('storage')` -  would return the default adapter listed under "active" configuration
`adapterManager.getAdapter('storage:videos') - would return an adapter configured for videos *feature*

- Here's an example configuration for a custom video storage:
```
"storage": {
    "active": "LocalFileStorage",
    "videos": "ghost-storage-custom-video",
    "ghost-storage-custom-video": {
        "custom": "configHere"
    }
}
```
2021-10-21 20:22:45 +13:00
Naz
e90c4217e5 Added a doc to adapter service coinfig mapper 2021-10-21 20:22:45 +13:00
Hannah Wolfe
360f7490dd
Refactored fixture utils scout style
- This is a minor refactor to reorder functions, use async/await & fat arrows
- It will make the coming bigger refactor slightly easier to read :D
- This should not make any functional changes
2021-10-20 19:54:14 +01:00
Kevin Ansfield
256f16a01f
🐛 Fixed URLs not being correctly transformed during insert operations (#13618)
closes https://github.com/TryGhost/Team/issues/1150

Our override of the base Bookshelf `insert` operation so that our own `formatOnWrite()` method is called on attributes was working on a false assumption that an `attrs` attribute is passed in as it is for the `update` operation. Instead Bookshelf's base update uses the `model.attributes` values to create an `attrs` object that is then passed through the usual `.format()` method meaning that our `insert` override was not actually doing anything.

- added a failing regression test for the `formatOnWrite()` override behaviour
- adjusted our insert/update overrides to set an internal `_isWriting` property on the model, then if that property is true our `.format()` override (which is called by Bookshelf on a generated `attrs` object during inserts) we manually call our `.formatOnWrite()` method
  - updated both overrides even though `update` was working for consistency and less cognitive overhead for reasoning between two different approaches
2021-10-20 15:22:46 +01:00
Kevin Ansfield
59a6f040d2 Fixed custom theme settings being clobbered with duplicate-named themes
refs https://github.com/TryGhost/Team/issues/1149

Ghost allows different themes to have the same `name` value in `package.json` but gives them a custom name based on the zip file used to upload it. The custom theme settings service however was always using the package.json name meaning that when syncing a theme with a duplicate name it was overwriting the settings for all other themes.

- bumped `@tryghost/custom-theme-settings-service` which changes the `.activateTheme()` signature to accept a theme name as the first argument
- updated our calls to `.activateTheme()` to pass Ghost's known theme name as the first argument so we're always syncing with the correct `theme` field value in the `custom_theme_settings` table
2021-10-20 13:25:02 +01:00
Fabien 'egg' O'Carroll
4e326123d3
Updated Offers related tables (#13609)
no-issue

* Removed NOT_NULL constraint from stripe_coupon_id

When handling disconnecting from Stripe - we remove all Stripe data from
our database to ensure we do not have bad/invalid data stored. Removing
this constraint will allow us to set the value to NULL.

* Added created_at column to offer_redemptions

Offer Redemptions are not just a joining table, but an event. A created_at
date allows them to be ordered

Because this is in alpha it is simpler to just drop the tables and
re-add them, due to offer_redemptions depending on offers, we also drop
this table and re-add it.
2021-10-20 14:22:37 +02:00
Daniel Lockyer
1fd980ee9b Set global Luxon timezone override to UTC
refs https://linear.app/tryghost/issue/CORE-113/start-off-luxon-refactor

- we're planning on switching to Luxon for our date/timezone library,
  eventually replacing `moment` and `moment-timezone`
- the first step is to set the global timezone override to UTC, which is
  done in `core/server/overrides.js`
- also adds a test to ensure we're setting the timezone correctly
- this was mostly pulled from https://moment.github.io/luxon/#/zones?id=changing-the-default-zone
2021-10-20 09:19:29 +02:00
Naz
393280b6ae Reworked LocalFileStore methods to use async syntax
refs https://linear.app/tryghost/issue/CORE-1/multiple-adapters-per-type

- While digging around this area refactored the code to use more readable async/await syntax instead of chaining then's
- Dropped unneeded "catch" block in save method as all it was doing was rethrowing an error with out additional handling
2021-10-20 10:29:46 +04:00
Naz
51b78211c5 Renamed bootstrap to routerManager
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events

- A follow up rename after bootstrap module was transformed into class
2021-10-19 07:29:09 +13:00
Naz
6e075c78bf Moved URL service to backend
refs https://linear.app/tryghost/issue/CORE-104/decouple-frontend-routing-events-from-urlserver-events

- URL module is part of the backend heavily dependent on the model and fits perfectly here. Frontend should get the data it needs by passing a URL manager instance to it
2021-10-19 07:29:09 +13:00
Hannah Wolfe
ae33c89707
Moved public folder to frontend
- The files in the public folder are all specific to the frontend:
  - ghost.css / ghost.min.css contains styles for default templates like unsubscribe, private and error
  - favicon is the default for the frontend
  - robots.txt is the default robots.txt for the frontend
  - sitemap.xsl is the stylesheet for the sitemap
- Therefore, they should live in the frontend!
2021-10-16 19:27:34 +01:00
Hannah Wolfe
17e4d89a79
Removed unused public assets
refs: a482c547ae

- This image hasn't been used for a very long time!
2021-10-16 13:58:29 +01:00
Daniel Lockyer
f4fb0fcbaa Improved Ghost boot time and memory usage by lazy loading routes
no issue

- right now, we mount all API endpoints (v2, v3 and canary), alongside some
  other routes, when Ghost is booting. This is wasteful because we don't
  necessarily need any of the endpoints to get Ghost up and running
- even when Admin is used, it uses `canary` so `v2` and `v3` sit in memory
- the better approach here is to lazy load these endpoints, so they only
  get mounted when needed
- this commit adds the `lazyUse` function into our Express lib,
  which takes a mount path and a module function to execute down the
  line. This gets passed to the wonderful `express-lazy-router` lib which
  detects when we're calling an unmounted module and will mount it for
  us
- from local testing, this speeds up boot time by about 18% and reduces
  initial memory usage by about 6% 🚀
2021-10-15 17:52:07 +02:00
Fabien O'Carroll
0210b329cb Passed OfferRedemption to members
refs https://github.com/TryGhost/Team/issues/1132

In order for the members module to create redemptions for members, it
needs access to the OfferRedemption model.
2021-10-15 16:56:04 +02:00
Fabien O'Carroll
a41c3cae1f Passed OfferRedemptionModel to offers
refs https://github.com/TryGhost/Team/issues/1132

In order for the offers modules to read the redemption count it needs
access to the OfferRedemption model.
2021-10-15 16:56:04 +02:00
Fabien O'Carroll
e2b243040e Added OfferRedemption model
refs https://github.com/TryGhost/Team/issues/1132

A model is needed for reading and writing Offer Redemptions to the
database.
2021-10-15 16:56:04 +02:00
Hannah Wolfe
67821a7bc7
Removed remaining usage of i18n & translation file
refs https://github.com/TryGhost/Ghost/issues/13380

- Now that i18n.t has been removed everywhere, we can cleanup the final usages
- Still TODO: merge the i18n logic into themeI18n, and get rid of shared/i18n entirely
2021-10-15 11:39:07 +01:00
Rishabh Garg
7270baa99c
Added new offers endpoint on members API
refs https://github.com/TryGhost/Team/issues/1138

Portal offer urls use offer id to load offer details UI and stripe checkout in frontend. This endpoint allows portal to fetch offer details from offer id to create Portal UI with relevant details for potential members.
2021-10-15 11:46:27 +05:30
Hannah Wolfe
b286142a6b
Removed errant console.log
refs: d7ae6e0138

- removed a debugging console log accidentally committed to main
2021-10-14 20:38:02 +01:00
Kevin Ansfield
d7ae6e0138 Added image as an allowed custom theme setting type
refs https://github.com/TryGhost/Team/issues/1107

- updated schema validation to allow `'image'` through as a known setting type now that Admin has support
- added transformation of setting values for `'image'` types because they will be URLs and should be stored with `__GHOST_URL__`
2021-10-14 18:41:54 +01:00
Kevin Ansfield
41c21f501d Added text as an allowed setting type
refs https://github.com/TryGhost/Team/issues/1107

- updated schema validation to allow `'color'` through as a known setting type now that Admin has support
2021-10-14 15:45:47 +01:00
Kevin Ansfield
adb176f5b2 Added color as an allowed setting type
refs https://github.com/TryGhost/Team/issues/1107

- updated schema validation to allow `'color'` through as a known setting type now
2021-10-14 10:37:28 +01:00
Naz
add30f3d5b Decoupled frontend routing from url service
refs https://linear.app/tryghost/issue/CORE-103/decouple-internal-frontend-code-from-url-module

- By becoming a parameter in the routing bootstrap process URL is Service no longer a "require" inside the frontend controllers but rather becomes a part of the "internal API" of the bootstrapper. This is not the end form of it, rather a step closer to decouplint routing from the URL serivce.
- The bootstrap module needs a facelift to have cleaner distinction between init/start methods. This is left for another time
2021-10-14 05:55:49 +13:00
Kevin Ansfield
7cb93be60b Added boolean as allowed custom theme setting type
refs https://github.com/TryGhost/Team/issues/1106

- updated schema validation to add `'boolean'` as an allowed `type` value
- added `format()` and `parse()` methods to `CustomThemeSetting` model to match `Settings` model behaviour for boolean-type settings
2021-10-13 17:25:32 +01:00
Fabien O'Carroll
f3dcf578a9 Prefixed migration with 01
refs https://github.com/TryGhost/Ghost/commit/b48c16c1

This was missed in the initial commit. We require numbers so that we can
easily see the order in which migrations will run.
2021-10-13 17:37:39 +02:00
Fabien O'Carroll
b93e7d7f7c Added offer_redemptions table to database
refs https://github.com/TryGhost/Team/issues/1132

This will be used to store Offer Redemptions, which will be used to list
the Offers which a Member has redeemed, as well as the number of times
an Offer has been redeemed.
2021-10-13 17:37:39 +02:00
Fabien O'Carroll
a441825c3f Passed MembersAPI the OffersAPI over OfferRepository
no-issue

The MembersAPI using the OfferRepository coupled it to the internals of
the Offers Module - instead we pass the "external" API - so that we can
change the internals, and not have to update the MembersAPI's usage.
2021-10-13 11:17:32 +02:00
Hannah Wolfe
00bcaeeb8c
Fixed duplicate message due to bad merge
- sadly git is not always detecting conflicts properly
2021-10-13 09:17:01 +01:00
PJ
4943c97ecb
Replace i18n with tpl in api/v2/utils/validators/input/users.js (#13589)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 09:08:57 +01:00
PJ
d362d8c8bd
Replace i18n with tpl in core/server/api/v3/invites.js (#13587)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 09:07:57 +01:00
PJ
09a9a9844f
Replace i18n with tpl in api/v3/pages-public.js (#13586)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 09:07:42 +01:00
PJ
f8033596c0
Replace i18n with tpl in api/v3/pages.js (#13585)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 09:06:53 +01:00
PJ
6e14047a2a
Replace i18n with tpl in core/server/api/v3/memberSigninUrls.js (#13584)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 09:05:38 +01:00
Naz
dbdf7160bf Simplified DynamicRedirectManager's constructor
refs https://linear.app/tryghost/issue/CORE-84/have-a-look-at-the-eggs-redirects-refactor-branch

- This simplification allows to make the test for dependent services a lot more readable without a need to stub urlUtils
2021-10-13 10:04:55 +02:00
PJ
57ce743d98
Replace i18n with tpl in output/authentication.js (#13581)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 09:00:19 +01:00
Tomás Castillo
2c659ea447
Replaced i18n.t w/ tpl helper in v3/posts.js file (#13580)
refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 08:58:34 +01:00
IncredibleZuess
dd5a96d37c
Replaced i18n.t w/ tpl in api/v2/utils/validators/input/setup.js (#13579)
refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 08:54:22 +01:00
IncredibleZuess
b2e4145bd9
Replaced i18n.t w/ tpl in api/v2/utils/validators/input/settings.js (#13578)
refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 08:53:57 +01:00
IncredibleZuess
0cbc813f28
Replaced i18n.t w/ tpl in core/server/api/v2/utils/validators/input/passwordreset.js (#13577)
refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package
2021-10-13 08:52:39 +01:00
IncredibleZuess
e0c0022cb7
Replaced i18n.t w/ tpl in core/server/api/v2/utils/validators/input/invites.js (#13576)
refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 08:52:19 +01:00
IncredibleZuess
6d4b682b95
Replaced i18n.t w/ tpl in api/v2/utils/validators/input/images.js (#13575)
refs: TryGhost#13380

- The i18n package is deprecated. It is being replaced with the tpl package.
2021-10-13 08:50:15 +01:00
Levi Richardson
6421f60852
Switch i18n.t to tpl in users.js (#13574)
refs: #13380

- i18n is deprecated and is being replaced with tpl
2021-10-13 08:44:04 +01:00