Commit Graph

668 Commits

Author SHA1 Message Date
Naz
eb7e4bb815 🐛 Fixed frontmatter-related validation error
refs https://github.com/TryGhost/Team/issues/687

- The frontmatter field has leaked into the API layer unintentionally when it was introduced into the DB schema during 4.0 release.
- The fix add the field to "trim" list in all API. A proper validation and handling will be add per API as usecase for the field becomes clear
2021-05-13 12:14:05 +04:00
Naz
06dd9bac59 Refactored post resource Admin API test utils
refs https://github.com/TryGhost/Team/issues/687

- The approach of generating validation properties using `/server/data/schema` package's tables object is prone to leaking unwanted database fields into API responses
- This refactor takes a tiny step into direction of relying on "allowlist" approach for properties in the API response resources.
- Apart from solving the described property leak problem it also moves toward decoupling tests from `/core/server` dependencies!
2021-05-12 18:15:54 +04:00
Kevin Ansfield
c36e749820
Added support for gating content by member labels and products (#12946)
refs https://github.com/TryGhost/Team/issues/581
closes https://github.com/TryGhost/Team/issues/582

Emails can now be sent to members with specific associated labels or products by specifying an NQL string. We want to bring the same members segment feature to content by allowing `visibility` to be an NQL filter string on top of the `public/members/paid` special-case strings.

As an example it's possible to set `posts.visibility` to `label:vip` to make a post available only to those members with the `vip` label.

- removed enum validations for `visibility` so it now accepts any string or `null`
    - bumped `@tryghost/admin-api-schema` for API-level validation changes
- added nql validation to API input validators by running the visibility query against the members model
- added transform of NQL to special-case visibility values when saving post model
    - ensures there's a single way of representing "members" and "paid" where NQL gives multiple ways of representing the same segment
    - useful for keeping theme-level checks such as `{{#has visibility="paid"}}` working as expected
- updated content-gating to parse nql from post's visibility and use it to query the currently logged in member to see if there's a match
    - bumped @tryghost/members-api to include label and product data when loading member
2021-05-10 19:32:11 +01:00
Rishabh
3d9d2b7974 Fixed settings integrity spec
refs c199918465

Fixes integrity spec with last commit's change
2021-05-10 18:54:47 +05:30
Rishabh
2497af0072 Updated default description for free price
refs https://github.com/TryGhost/Team/issues/671

When turning on custom products, existing sites should have default price descriptions that match existing values for prices. This change sets the default description for Free price to match existing hardcoded value.
2021-05-10 14:19:02 +05:30
Hannah Wolfe
895bffec1f
Enabled no-skipped-tests eslint rule [warn]
- Not sure why, but this is set to off in our base plugin
- It masks issues where people have temporarily skipped tests to fix later and then forgot
- Enabling this to allow us to review all those places, but we should also try to leave it on and set to error
2021-05-07 19:24:23 +01:00
Fabien O'Carroll
6106d1fdc4 Updated active column type from boolean -> bool
no-issue

Our base model will only automatically convert numbers to booleans if
the type is 'bool' - however this column was incorrectly added with a
type of 'boolean'. Lucklily - knex with both MySQL & SQLite3 will add
a column with the same type for both of these, so no migration is needed
to fix it.
2021-05-07 16:37:38 +01:00
Fabien O'Carroll
e1f0eb8794 Updated fixture utils for Products & Prices
no-issue

This ensures that the fixture Product is added, and the Prices are
linked to it.
2021-05-07 16:34:22 +01:00
Fabien O'Carroll
569f1c559d Updated theme middleware to use products api
refs https://github.com/TryGhost/Team/issues/668

Since we no longer store price data in the settings we must use the api
to read the stripe prices for the default price, so that we can maintain
backwards compatibility for the `@price` data in themes.
2021-05-07 16:32:57 +01:00
Fabien O'Carroll
b35f060bef Added settings for members 'free' price
refs https://github.com/TryGhost/Team/issues/637

The "free" price - when Members signup without using Stripe, should have
a name and description, so that it can be displayed in Portal in a
similar way to paid price's. As there is only ever one, and it is not a
fully fledged price, a setting makes more sense than a dedicated db
table.
2021-05-07 16:32:12 +01:00
Fabien O'Carroll
a138586c83 Updated stripe_plans & portal_plans settings
refs https://github.com/TryGhost/Team/issues/586

We are no longer using the `stripe_plans` setting, instead we are using
the `stripe_prices` database table. However, we must keep the setting as
the migration from the setting to the database is not done as a standard
migration, but in code. This means our code has to still read and pass
the setting because we will never know if the migration in code has run
yet.

The `portal_plans` setting has been updated to only include 'free' by
default, because the setting must include id's now rather than names.
2021-05-07 16:31:08 +01:00
Fabien 'egg' O'Carroll
e9687d359d
Removed unique constraint from Product names (#12928)
refs https://github.com/TryGhost/Team/issues/586

A discussion in the Members team resulted in us determining that we do
not need to enforce unique names for Products. Stripe does not enforce
uniqueness for their Products, and we feel it's not necessary for us to.
2021-05-07 13:34:23 +01:00
Daniel Lockyer
b1499d4037 Extracted package-json lib to Utils
refs 37ebe723c6

- `package-json` was a standalone library using dependency injection so
  we could pull it out into its own package in Utils
- this was done in the commit referenced above
- this commit removes the implementation and tests in Ghost and replaces
  the require in the initialization wrapper with the new package
2021-05-07 12:35:06 +01:00
Kevin Ansfield
322664a145
Added ability to send a newsletter to members with a certain label or product (#12932)
refs https://github.com/TryGhost/Team/issues/581
refs https://github.com/TryGhost/Team/issues/582

When publishing a post via the API it was possible to send it using `?email_recipient_filter=all/free/paid` which allowed you to send to members only based on their payment status which is quite limiting for some sites.

This PR updates the `?email_recipient_filter` query param to support Ghost's `?filter` param syntax which enables more specific recipient lists, eg:

`?email_recipient_filter=status:free` = free members only
`?email_recipient_filter=status:paid` = paid members only
`?email_recipient_filter=label:vip` = members that have the `vip` label attached
`?email_recipient_filter=status:paid,label:vip` = paid members and members that have the `vip` label attached

The older `free/paid` values are still supported by the API for backwards compatibility.

- updates `Post` and `Email` models to transform legacy `free` and `paid` values to their NQL equivalents on read/write
  - lets us not worry about supporting legacy values elsewhere in the code
  - cleanup migration to transform all rows slated for 5.0
- removes schema and API `isIn` validations for recipient filters so allow free-form filters
- updates posts API input serializers to transform `free` and `paid` values in the `?email_recipient_filter` param to their NQL equivalents for backwards compatibility
- updates Post API controllers `edit` methods to run a query using the supplied filter to verify that it's valid
- updates `mega` service to use the filter directly when selecting recipients
2021-05-07 11:56:41 +01:00
Kevin Ansfield
1ee97ccfbc
Fixed editors not being able to read labels when assigning member segments (#12934)
refs https://github.com/TryGhost/Team/issues/581

Editors are allowed to restrict post visibility and send emails to particular member segments, they need to be able to read labels so that they can select them in a member segment.
2021-05-07 10:51:44 +01:00
Hannah Wolfe
d2c6838133
Switched to using .js files for eslint
- Using JS files to configure eslint gives us more power, e.g. being able to calculate paths
- We already use JS in pretty much every other repo we own, including admin... it's just Ghost we don't, and it's time!
2021-05-07 10:30:41 +01:00
Kevin Ansfield
b08b95085e
Added default email recipients settings (#12925)
refs https://github.com/TryGhost/Team/issues/496

We want to give more control over the default selection of email recipients when publishing a post, to do that we need somewhere to store those settings. These settings are site-wide and intended for use by admins to control the default editor behaviour for all staff users. They _do not_ control API behaviour, if you want to send email when publishing via the API it's still necessary to explicitly opt in to that using the `?email_recipients_filter=` query param.

- new `editor` settings group to indicate that these settings only affect the UI rather than the API
- `editor_default_email_recipients` controls overall behaviour, string/enum with these allowed values:
  - `'disabled'`: no option to send email is shown in the editor's publishing dropdown
  - `'visibility'`: (default) selected member segment is dynamic and matches the post visibility filter
  - `'filter'`: specific member filter defined in `editor_default_email_recipients_filter` setting
- `editor_default_email_recipients_filter` is an NQL string for selecting members, used when `editor_default_email_recipients` is set to `'filter'`
  - default value is `'all'`
  - the segment string can be any valid NQL filter with the additional special-case values of `'all'` and `'none'`
2021-05-07 09:30:57 +01:00
Hannah Wolfe
ccbb44bc67
Added fake logging to i18n tests
- without this we splurge random info out into the test results, which is undesirable 🙈
2021-05-06 19:38:01 +01:00
Hannah Wolfe
ad9b18e00f
Improved i18n to use DI for logging + config
- final preparation for moving i18n out of Ghost core
- logging is passed in via DI
- theme i18n needs a config value, but no need to pass all of config for one parameter, a better pattern is to pass the one value needed
2021-05-06 10:58:24 +01:00
Hannah Wolfe
e1699afc77 Refactored i18n so all logic is in the base class
- preparation for moving the base class out of Ghost
- refactored so that all the logic for file loading and fallbacks live in the base class
- theme i18n now only overrides init with the properties it needs, filepath generation and error handling
- this makes it much easier to move the i18n file out, and eventually have theme i18n live elsewhere too
- also prepares for using DI for logging
2021-05-05 20:29:34 +01:00
Hannah Wolfe
9ce407966f Improved theme locale handling
- when activating a theme, we need to load the current locale
- this request used to be buried deep in the themeI18n init call
- now we surface it in the bridge and pass it down, which is closer to what we want to do with eventually initialising the frontend
with everything it needs up front (or not initialising it, if it isn't needed)

- in the related helpers we depend on the site.locale value instead of proxy -> themeI18n -> settingsCache drastically simplifying the code and removing deep requires
- site.locale is updated via middleware and can be relied upon
2021-05-05 16:13:26 +01:00
Hannah Wolfe
d8318654a9 Improved i18n with unified getCandidateString fn
- the core i18n library and theme i18n library have slightly different methods of getting a candidate string
- both of them use forms of jsonpath, meaning they both require jsonpath as a dependency
- to try to get to a point of being able to rip more things out of ghost, we want to have less dependencies
- so instead of overloading the method, we pass in a stringMode as an argument
- eventually we might not need an overloaded class for themeI18n at all, which would simplify the codebase
2021-05-05 15:53:09 +01:00
Hannah Wolfe
ba53de1add Refactored i18n into a class + index
- preparation for using DI instead of requires, so we can move this out of Ghost
- have done this for both the main i18n and theme i18n file
- refactored the constructor
2021-05-05 15:13:23 +01:00
Fabien 'egg' O'Carroll
b4d9ee0b4e
Added description to Products & Prices (#12916)
refs https://github.com/TryGhost/Team/issues/586

The `products` and `stripe_prices` tables are missing a description
column which will be used by Portal to display information about the
products and prices
2021-05-04 13:41:48 +01:00
Hannah Wolfe
3eec28afcf Removed unused onMany method from events
- Preparing to cleanup / change how we use events across Ghost
- Removing this unused bit of additional complexity makes it easier to reason about what we need
2021-05-04 13:28:24 +01:00
Hannah Wolfe
273e220327 Moved i18n to shared
refs 829e8ed010

- i18n is used everywhere but only requires shared or external packages, therefore it's a good candidate for living in shared
- this reduces invalid requires across frontend and server, and lets us use it everywhere until we come up with a better option
2021-05-04 13:03:38 +01:00
Hannah Wolfe
829e8ed010 Expanded requires of lib/common i18n and events
- Having these as destructured from the same package is hindering refactoring now
- Events should really only ever be used server-side
- i18n should be a shared module for now so it can be used everywhere until we figure out something better
- Having them seperate also allows us to lint them properly
2021-05-03 17:14:52 +01:00
Naz
bc15f8c1bb Added "emails" limit check when (re)sending a newsletter
refs https://github.com/TryGhost/Team/issues/588

- This check allows for a on/off switch to be set up on the instance and control limits around sending emails
- An example configuration for such check would look like following in config's hostSettings section, e.g.:
```
"emails": {
    "disabled": true,
    "error": "Email sending has been temporarily disabled whilst your account is under review."
}
```
2021-05-03 17:51:33 +04:00
Hannah Wolfe
bc75fab663 Moved theme service to core/server
refs: bf0823c9a2
refs: ae86254972

- continuing the work of splitting up the theme service into logical components

Themes Service
- The serverside theme service now serves just the API and boot
- It loads the theme and passes it to the theme-engine via the bridge

This achieves the bare minimum goal of removing all the cross requires between server and frontend around themes
There is still a lot more to do to achieve an ideal architecture here as laid out in ae86254972
2021-04-27 15:14:49 +01:00
Fabien 'egg' O'Carroll
33f26fbf32
Updated subscriptions for Members Admin API
refs https://github.com/TryGhost/Team/issues/616

We need a way to assign Products to Members via a Subscription, and we've
followed the same pattern as the editSubscription method for the Members API
controller, which acts upon Subscriptions as a nested resource.

Subscriptions now are linked to products, and we've included those links by
default in the Member Admin API as we already include subscriptions by
default, and Products are now a core part of the Members feature-set.
2021-04-26 17:14:34 +01:00
Hannah Wolfe
af2b0b6729 Fixed broken require path (bridge in tests)
refs: fdefa4964f

- IDE didn't fix all the paths 🙈
2021-04-26 15:01:10 +01:00
Hannah Wolfe
1025600ae1 Cleaned up some unused code in test fixtures
- the themeService.loadAll method was refactored out ages ago, so this clearly isn't used in tests
- the rest are requires I spotted whilst working around the codebase
- note: we have noUnusedVars disabled as a linting error in tests because else should complains everywhere
2021-04-26 13:20:07 +01:00
Hannah Wolfe
9614d71e1f Moved theme i18n to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components

- This one is a little more involved, as the i18n initialisation was unnecessarily spread over several locations.
- I moved it into being part of the ActiveTheme class and called in the constructor, meaning we don't need the services.theme.activated event anymore as the constructor is called in the same cases.
- Also moved the event listener for locales into the bridge, as I don't want that inside of theme-engine, and we don't want circular dependencies. We'll figure out a wayto refactor this soon too.
2021-04-26 12:29:55 +01:00
Hannah Wolfe
b9fc68b1b4 Moved theme middleware to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
2021-04-24 20:01:09 +01:00
Hannah Wolfe
5458126422 Moved theme preview mw to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
2021-04-24 19:56:00 +01:00
Hannah Wolfe
d3f20c52fd Moved getApiVersion to a new shared "bridge" class
refs: bf0823c9a2

- Added a new bridge class that lives in shared. This should eventually be responsible for all cross-communication between the frontend and the server
- Having all the gnarly shared bits in one place should help us refactor more easily
- For now it also reduces requires between the core/server and core/frontend folders that are meant to be separate
- All calls to getApiVersion have also been renamed to getFrontendApiVersion, as this is different to the "default" API version
- Slowly getting to the point where frontend/services/themes can be moved to server/services/themes :)
2021-04-24 09:55:48 +01:00
Hannah Wolfe
34d2cc1b0b Moved active theme to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
- this is where it starts to get fiddly as the getActive function in themeService index is required across the frontend/backend mostly due to its use in the getApiVersion method
- for now left one usage of the getActive method in place in ghost-locals middleware ready for the next phase of the refactor, which will move some of the themeService index into a shared location
2021-04-23 15:28:50 +01:00
Hannah Wolfe
50367fafee Moved theme engines to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
2021-04-22 21:05:01 +01:00
Hannah Wolfe
c02b0a19ac Used new default API version in theme engines
refs: 9f50e941eb
refs: bf0823c9a2

- Still working towards splitting the theme service into logical components
- The engine defaults were required in the index file, in a way that creates tight coupling across what would otherwise
be distinct components
- Also meant there was another hardcoded 'v4' in the codebase
- This fixes both issues by depending on the value from config
- Currently this adds Yet Another Config Require, but it should be fine for now until we have a new pattern for the frontend
- Note: We only care about the ghost-api engine, we used to care about both ghost and ghost-api. Now that there is only one there was no need for the more complex code structures
2021-04-21 18:08:17 +01:00
Daniel Lockyer
e9b21fdbd1 Updated bson-objectid calls to match API change
refs c873899e49

- as of `bson-objectid` v2.0.0, this library exports the function
  to generate an ObjectID directly, and then you need to use `.toHexString()`
  to get the 24 character hex string - 6696f27d82
- this commit removes all uses of `.generate()` and replaces with this
  change
2021-04-21 16:23:52 +01:00
Hannah Wolfe
c687df21e1 Moved theme config to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
2021-04-21 14:21:32 +01:00
Hannah Wolfe
ef4e4e8cc0 Moved handlebars utils to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
2021-04-21 14:21:32 +01:00
Kevin Ansfield
074e8b1292
Added @site.signup_url data property for themes (#12893)
refs https://github.com/TryGhost/Team/issues/579

- when members signup is enabled returns `#/portal` otherwise returns feedly subscription URL
- allows for themes to have subscription buttons without condititionals, eg `<a href="{{@site.signup_url}}">Subscribe</a>`
2021-04-21 12:10:09 +01:00
Hannah Wolfe
db79176724 Used themeService as var name everywhere [again]
refs 08fbcf1d90

- I didn't quite finish this commit before, and also forgot to write a proper commit message 🙈
- Having the theme service required and referenced in lots of different ways contributes to it being very hard to refactor and break down into smaller pieces
- This is just one simple nice-to-have so we can search the codebase for references more easily
2021-04-20 19:16:52 +01:00
Hannah Wolfe
307e035796 Fixed incorrect require path in theme tests
- At some point we have updated the path that should be required to get helpers, but missed updating the path in this test
- When run with the full suite, the test still passed, but when run independently it threw the error loadCoreHelpers is not a function
- This is to do with some interaction with the middleware_spec.js tests
- I'm working on breaking all this down so hopefully will get rid of any further weird test independence issues
2021-04-20 19:16:52 +01:00
Fabien 'egg' O'Carroll
5b936c052f
Added Default Product fixture (#12892)
refs https://github.com/TryGhost/Team/issues/619

As part of the Custom Products work, we are linking members to products
when updating their subscriptions. This requires that we have at least
one product in the database. For existing sites that are using Members
this is handled by the v4.3 03 migration. But for new sites we must
include a fixture.

Also fixes the tests to not reply on the order of the fixtures
2021-04-20 16:39:27 +01:00
Rishabh Garg
48a2d24497
Added stripe_price_id column to subscriptions table (#12881)
refs https://github.com/TryGhost/Team/issues/586

- Adds new `stripe_price_id` column to subscriptions table to store stripe price ids with `index`
- Populates `stripe_price_id` column value to current `plan_id` making the `plan_*` values redundant
- Updates tests
2021-04-20 16:37:59 +05:30
Rishabh Garg
5da4ae90b2
Added cascade delete for stripe products and prices (#12891)
refs https://github.com/TryGhost/Team/issues/586

If a product inside Ghost is deleted, we want to cascade delete all associated Stripe products and prices as they always need to refer back to a ghost product and will hang without any reason otherwise. This change adds cascade delete for products -> stripe_products -> stripe_prices to avoid broken states
2021-04-20 15:24:52 +05:30
Hannah Wolfe
bf0823c9a2 Moved hbs engine into new theme engine service
- This is the beginning of splitting up the theme service into:
   - Storage components used by the API (should be a server service)
   - Theme engine & rendering components used by the frontend (this new engine service)
   - The code to activate a theme which is shared code where the API & frontend need to communicate
- This is needed because currently the frontend theme service is required and used by the API, creating tight coupling.
- In my quest to truly separate the API and frontend, this is one of many battles that needs winning
2021-04-19 20:03:30 +01:00
Hannah Wolfe
08fbcf1d90 Used themeService as var name everywhere 2021-04-19 19:41:13 +01:00
Kevin Ansfield
5c41c67ffc Set @labs.members to false when members_signup_acess == 'none'
refs https://github.com/TryGhost/Team/issues/579

- setting `members_signup_access` to `'none'` effectively disables all built-in members functions on the front-end so setting `@labs.members` to `false` allows themes to react accordingly
- `@labs.members` keeps backwards compatibility with pre-4.0 versions where themes were using it to toggle member-related functionality
2021-04-19 18:28:51 +01:00
Kevin Ansfield
4a8352c418 Disabled portal and stripe in {{ghost_head}} when signup access is none
refs https://github.com/TryGhost/Team/issues/579

- skips insertion of members-related scripts and styles when `members_signup_access` setting is set to `'none'`
- adds `id="gh-members-styles"` to the inserted style script tag for reference in tests and JS
2021-04-19 17:27:37 +01:00
Kevin Ansfield
fff6a04c54
Migrated members_allow_free_signup setting to members_signup_access (#12886)
refs https://github.com/TryGhost/Team/issues/579

Currently the members signup setting is explicitly yes/no to allowing free members signup, with the implication that when set to "no" members is still active but members have to be created via Stripe or the admin API.

This change renames the setting and changes its type to allow more than a binary option.

- migration to create/update the new setting based on the old value
  - free signup = "all", no free signup = "invite"; matches the current UI for this setting
- rename setting everywhere it's used/tested against
- modify `getAllowSelfSignup()` used to configure members packages to only return `true` when the new setting is set to `'all'` to match behaviour to the older setting
- update importer to rename the setting when importing from an older Ghost version
2021-04-19 16:36:30 +01:00
Thibaut Patel
375c71fc6a 🔒 Added a way to hide the secret settings once they are set
issue https://github.com/TryGhost/Team/issues/621
2021-04-16 17:05:16 +02:00
Daniel Lockyer
d01d8988e2 Updated tests to reflect jwks-rsa v2 changes
refs https://github.com/auth0/node-jwks-rsa/blob/master/CHANGELOG.md#200---2021-03-01

- `jwks-rsa` switches from callbacks to async-await and so we need to
  change the tests to reflect this
- this commit moves from `getSigningKey` containing a callback to it
  being part of the async-await flow
2021-04-16 09:58:47 +01:00
naz
d964224312
Added settings keys to store OAuth related data (#12879)
refs https://github.com/TryGhost/Team/issues/618

- The `oauth_client_id` and `oauth_client_secret` are placeholders to store OAuths related data.
- The flag for `oauth_enabled` or anything along those lines was not added intentionally in favour of checking if the `oauth_client_id` & `oauth_client_secret` are null.
2021-04-16 10:02:21 +02:00
Fabien 'egg' O'Carroll
22924c62d4
Added permissions for the Products resource (#12875)
refs https://github.com/TryGhost/Team/issues/616

All roles which can publish posts should be able to read/browse products, as content gating
will be based on products going forward.

Creating, updating & destroying products will often make modifications to Stripe which requires
Administrator or Owner roles.

We also improve the permissions tests so that we no longer rely on things being in a particular
order.
2021-04-15 14:34:45 +01:00
Rishabh Garg
eb66c715fd
Updated stripe prices table schema (#12863)
refs https://github.com/TryGhost/Team/issues/586

- Change the interval column to be `nullable` as one time payments won't have any interval
- Remove the `livemode` column as we store the connected account's livemode status at top level
2021-04-12 19:18:19 +05:30
Naz
cb0807d07a Blocked requests from integrations when integration limit is in place
https://github.com/TryGhost/Team/issues/599

- When custom integration limit is enabled all requests from existing integrations should not be accepted. With the exception of internal integrations like backup and scheduler
2021-04-10 00:45:26 +12:00
Naz
edd0e26a78 Fixed limits realoding during soft Ghost restart
refs https://github.com/TryGhost/Team/issues/599

- This is a precursor change to tests which verify the hostSettings limits are working correctly
- Bumped limits-service version which allows for multiple calls of loadLimits on the same service instance
2021-04-10 00:08:17 +12:00
Fabien 'egg' O'Carroll
15b7485a94
Added Product model and Member model relation (#12859)
refs https://github.com/TryGhost/Team/issues/586

- Member model now has `products` relation, sorted using `sort_order`, following convention from `labels`
- Product model has handling to set `slug` from name, following convention of Label model
- Updated filter plugin to handle filtering Member models by their `product` relations e.g. `product:[slug, slug]`
2021-04-08 18:01:49 +01:00
Rishabh Garg
94766c05bf
Added stripe_products and stripe_prices tables (#12858)
refs https://github.com/TryGhost/Team/issues/586

- Add the `stripe_products` table, so that we can map Stripe Products to Products in Ghost
- Add the `stripe_prices` table, so that we can associate Stripe Prices to Products table
2021-04-08 20:41:00 +05:30
Fabien 'egg' O'Carroll
25182b7b82
Added products and members_products tables (#12844)
refs https://github.com/TryGhost/Team/issues/586

- Add the products table, so that we can store Products in Ghost 
- Add the members_products table, so that we can associate Members w/ Products
- Use sort_order on the members_products table to follow the same convention in members_labels
- Populate the products table with a single product, using the name from the stripe_product_name setting
- Populate the members_products table with relations based on the status column of the members table

Populating the tables allows us to transition from the current system, which does not care about products, into the
new system, where Products are used to group members. The intention is that all existing paid members have the
same product
2021-04-08 14:15:30 +01:00
Kevin Ansfield
bb19eddeae
Added DELETE /members/ to the Admin API for bulk member deletion (#12082)
refs https://github.com/TryGhost/Team/issues/585

- adds `DELETE /members/` route to the Admin API
- supports `?filter`, and `?search` query params to limit the members that are deleted
- `?all=true` is required if no other filter or query is provided
- uses `models.Member.bulkDestroy` which _will not_ cancel any Stripe subscriptions if members have them but _will_ clean up the Stripe relationship data in Ghost's database
2021-04-08 12:03:45 +01:00
Naz
af6b73f085 Fixed typo in test case name 2021-03-30 17:54:53 +13:00
Naz
33a52d5850 Added test coverage for send_email in members API
no issue

- During an investigation of a possible Zapier bug discovered there was no coverage at all for sending emails for new member signups. This changeset adds coverage for basic case of `send_email` and `email_type` behavior
2021-03-30 17:54:53 +13:00
Rishabh Garg
72e8894eac
Cleaned old members stats endpoint (#12821)
no refs

- Removes old `/members/stats` endpoint in favor of new `/members/stats/count` in canary/v4 which captures members counts using new events table
- Removes tests for old `/members/stats` endpoint
- Added test for new `/members/stats/count` endpoint
2021-03-29 13:07:01 +05:30
naz
ffd866cedc
💥 Reduced default exports content for DB APIs (#12818)
refs https://github.com/TryGhost/Team/issues/555

- Export files included a lot of data which was not used in the importer, for example: members,  labels, migrations and many more. This lead to a lot of clutter in the import files and made it hard to reason about their purpose.
- The main purpose of exports - is to export importable resources. These are posts, tags, and users. The rest of data like members or migrations either have their own importer (like CSV importer for members) or does not and should not have any ways to be imported.
- These changes are in now way complete. It's a first step towards resource-based exports which could be properly versioned in the future on API level and not be a mirror of the DB structure.
- This is sort of a breaking change. But we are doing it because: (1) its an internal API that should not be used by external clients, (2) there was no public contract to have this API stable at any point, (3) we really need to get back the control over export files structure and size
- In case an external client was dependent on some structure of the exported json file they can still pass in ALL of previously exported data by passing table names in `include` query parameter.
2021-03-25 19:27:49 +13:00
Naz
2d4a06023d Updated version check assertion in exporter test
refs https://github.com/TryGhost/Team/issues/555

-  This version is dynamic and depends on latest Ghsot version. It's unrealistic to expect test maintainer to update this version regularly, instead opted into checking the format of the version property
2021-03-25 17:16:18 +13:00
Naz
ea90e0a314 Fixed exporter unit test suite
refs https://github.com/TryGhost/Team/issues/555

-  Fixed "skipped" test which was useful to have for scenarios when "include" parameters are passed into exporter
- Also updated assertions to explicitly list calls to tables - these tests should break and should be fixed when exporter is modified!
2021-03-25 17:10:22 +13:00
Naz
aaa54c603c Refactored exporter to use "allowlist" table filtering
refs https://github.com/TryGhost/Team/issues/555

- Previous blocklist approach was resulting in adding every single new table into an export automatically. Which creates possibility to leak sensitive data if not used porperly. Allowlist approach gives better control over what is exported, makes this information explicit, and version-control friendlier
2021-03-25 16:46:56 +13:00
naz
7f50083cc5
Fixed node version specific object key sorting (#12817)
refs 74cdbadedb

- Fixes failing test by enforcing ordering through `sort()` call. Doing this to avoid differences between node versions' `Object.keys()` ordering
2021-03-25 15:16:24 +13:00
Naz
74cdbadedb Fixed exporter tests using should.have.keys assertion
refs https://github.com/TryGhost/Team/issues/555
refs 080a8fc082

-  The `have.keys` assertion was not doing strict comparison neither provided any useful output when changed to `have.only.keys`.
- Rewrote the tests to use manual assertion through array comparison which checks exactly what it's supposed to and gives a visual diff in case there are any missing/extra properties in config
2021-03-25 13:22:34 +13:00
Naz
080a8fc082 Fixed config test that failed to detect changes
no issue

- The test was designed to fail when `exactly the right keys` were modified. This was not happening! The `have.keys` assertion was not doing strict comparison neither provided any useful output when changed to `have.only.keys`.
- Rewrote the test to use manual assertion through array comparison which checks exactly what it's supposed to and gives a visual diff in case there are any missing/extra properties in config
2021-03-25 13:12:43 +13:00
Kevin Ansfield
bc63f51fd7 🐛 Fixed 404 errors if navigation URLs are somehow blank
no issue

- in very rare circumstances it's possible that a navigation url in settings can be blank, we should not throw errors in this case as it appears as a theme/routing problem which is difficult to diagnose and much worse than simply not outputting a link class
2021-03-24 09:43:43 +00:00
Naz
e290983042 Updated export fixture for Ghost 2.9
refs https://github.com/TryGhost/Team/issues/555

- This test fixure is up to date and contains real export from Ghost 2.9. This file should not be edited any more as it represents a "snapshot" of 2.9 (don't really know why this version was chosen to be tested, so didn't change the convention).
- Ideally in the future we should maintain snapshots of export from major releases (or at least first non-broken releases after major release) AND a snapshot of the latest ghost version export file (canary of a sort). This way we'll be able to build up confidence of older export files still working and keep good track in export file changes with every new version
- Updated db spec suite to remove "fixture" user before each import to reduce a variable amount of import errors (star from the same state). It has to be done through an API call because restarting Ghost instance to have clean slate before each test case times out the suite
2021-03-24 20:00:34 +13:00
Naz
4286fa8a53 Fixed skipped DB API regression tests
no issue

- The tests were skipped because schema changed and there was probably no time to figure out why they were failing.
- They work now!
2021-03-24 18:39:25 +13:00
Naz
0813bebac4 Updated export fixture for Ghost 4.0
refs https://github.com/TryGhost/Team/issues/555

- This test fixure is up to date and contains real export from Ghost 4.0. Previous file was just an old 2.x export file which was updated manually on "as needed bases"
- See 3240d4adf0 for more context
- Updated README.md for exports generations with more accurate instructions (previous one contained a typo)
2021-03-24 18:37:57 +13:00
Naz
32e1ea3679 Moved importer tests to regressions suite
refs 3240d4adf0

- Acceptance tests have low timeout limit and were not making it through with updated export files
2021-03-24 18:11:34 +13:00
Naz
3240d4adf0 Updated export fixture for Ghost 3.0
refs https://github.com/TryGhost/Team/issues/555

- This test fixure is up to date and contains real export from Ghost 3.0. Previous file was just an old 2.x export file which was updated manually on "as needed bases"
- The aim is to keep these files as close to real world as possible instead of manually making up data for the needs of test suites
- Fixed test suite which was using the v3 export file
2021-03-24 15:44:56 +13:00
Naz
7015894e3a Added export test fixture update instructions
refs https://github.com/TryGhost/Team/issues/555

- There were no automations or instructions for updating or creating new export fixtures. This redme should put a start for faster fixture generation process and possibly automation in the future
2021-03-24 15:40:54 +13:00
Kevin Ansfield
929cb0afe9
🐛 Fixed plaintext and excerpt fallbacks having incorrect URLs after domain change (#12811)
closes https://github.com/TryGhost/Team/issues/571

- `post.plaintext` values were being transformed with the markdown URL transformer but that wasn't picking up the link format used in our plaintext fields resulting in absolute URLs being stored in the database rather than `__GHOST_URL__` URLs
  - meant that if the `url` config is changed then plaintext and other calculated fields that used it would have URLs that referred to the old domain rather than the new one
  - re-saving the posts would have updated it but that's not feasible to do manually for large sites
- bumped `@tryghost/url-utils` to a version that has plaintext transform utils and updated the post model's transform map
2021-03-23 16:56:14 +00:00
Thibaut Patel
44035fd591 Added a better error when a user try to create an orphaned webhook
issue https://github.com/TryGhost/Team/issues/526
refs 70627d84a7 (r48575450)
2021-03-23 17:15:21 +01:00
Kevin Ansfield
426cbeec0f
🐛 Fixed performance regression introduced in 4.1.0 (#12807)
closes https://github.com/TryGhost/Ghost/issues/12791
closes https://github.com/TryGhost/Team/issues/566

https://github.com/TryGhost/Ghost/pull/12787 introduced a significant performance regression due to a misunderstanding of when Bookshelf calls `.format()` ([related upstream issue](https://github.com/bookshelf/bookshelf/issues/668)). We expected `.format()` to only be called on save but it's also called when Bookshelf performs fetching and eager loading which happens frequently. `.format()` can be a heavy method as it needs to parse and serialize html and markdown so it should be performed as infrequently as possible.

- override `sync()` in the base model so we can call our own `.formatOnWrite()` method to transform attributes on `update` and `insert` operations
  - this was the only feasible location in Bookshelf I could find that is low enough level to not require modifying model instance attributes
  - gives models the option to perform heavy transform operations only when writing to the database compared to the usual `.format()` method that is also called on fetch in many situations
2021-03-23 09:11:24 +00:00
Naz
81a54a70bc Fixed failing notification update for non-major version
refs 4dc413d6a1

- Fixed failing test cases which were designed to check non-major upgrade messages. There's no clear use cases for those, but still worth keeping such case in mind
2021-03-23 18:02:52 +13:00
Naz
4dc413d6a1 🐛 Fixed upgrade notification showing post-upgrade
closes https://github.com/TryGhost/Team/issues/564
refs https://github.com/TryGhost/Ghost/issues/10236

- The notification to upgrade to new 4.0 Ghost version was still visible to users after upgrading the instance to 4.0. This was caused by notification filtering not taking into account 3.x or 4.x versions.
- The fix filters out notifications that detect a major version notification using `x.0 is now available` pattern and compares current version to that major. This should future proof the issue from happening in Ghost 5.0 (but a proper holistic fix is preferable!)
2021-03-23 16:42:46 +13:00
Naz
72602040d7 Added unit test coverage for notifications service
refs https://github.com/TryGhost/Team/issues/564
refs https://github.com/TryGhost/Ghost/issues/10236

- These tests are meant to be built up upon when introducing a bugfix for referenced issue in Ghost 4.0 notifications
2021-03-23 15:24:20 +13:00
Naz
a71d5dc633 Renamed importer spec to match tested version
refs https://github.com/TryGhost/Team/issues/555

- Export/Import test suite clean up ctd. See previous commits for context
- Next up will introduce v3 and "latest" tests to be able to check how importer behaves when import files are used from a particular version
2021-03-23 00:42:22 +13:00
Naz
d30ecf70c0 Added latest export body generator
refs https://github.com/TryGhost/Team/issues/555

- Export/Import test suite clean up ctd. See previous commits for context
- Main goal here was to update latest JSON export data. Also hardened tests to make sure this fixture is updated whenever the endpoint changes structure
2021-03-23 00:42:22 +13:00
Naz
046c3445ce Renamed "lts" importer spec to "legacy"
refs https://github.com/TryGhost/Team/issues/555

- This name suits way better to describe what's actually being tested
2021-03-23 00:42:22 +13:00
Naz
efbaa4401e Renamed export body generator functions to match their versions
refs https://github.com/TryGhost/Team/issues/555

- This is a continuation of importer/exporter test suite cleanup. Check previous commits for more context
2021-03-23 00:42:22 +13:00
Naz
341b2bb604 Moved importer utils to general exporter utils
refs https://github.com/TryGhost/Team/issues/555

- Check previous commit for more context. This changeset is part of importer/exporter cleanup effort.
2021-03-23 00:42:22 +13:00
Naz
cc8fe3ad43 Removed importer suite assertion with no specific meaning
refs https://github.com/TryGhost/Team/issues/555

- Follow up to previous commit. Read it for full context.
2021-03-23 00:42:22 +13:00
Naz
653863bf0e Extracted v1 spec out of importer test suite
refs https://github.com/TryGhost/Team/issues/555

- Follow up to previous commit. Read it for full context.
- This step splits existing importer test suite into separate files based on current "describe sections". This is done to get the test suite size to somewhat comprehensive shape
2021-03-23 00:42:22 +13:00
Naz
0bc33d6816 Extracted LTS spec out of importer test suite
refs https://github.com/TryGhost/Team/issues/555

- Follow up to previous commit. Read it for full context.
- This step splits existing importer test suite into separate files based on current "describe sections". This is done to get the test suite size to somewhat comprehensive shape
2021-03-23 00:42:22 +13:00
Naz
4f83716cfe Extracted importer test suite utils
refs https://github.com/TryGhost/Team/issues/555

- As part of testing upcoming 4.0 release was looking into a robust way to test imports. The importer test suite is humongous, so started with small extractions.
- The goal is to have readable and easy to create version-specific "exports" that would allow for more convenient testing
2021-03-23 00:42:22 +13:00
Kevin Ansfield
9ac7ed5f3b
🐛 Fixed images not having srcset or sizes attributes (#12800)
closes https://github.com/TryGhost/Team/issues/567

- bumped `@tryghost/kg-default-cards` with a version containing a bugfix for detecting absolute URLs as local content images when they match the site url supplied as an option when rendering
- this bug surfaced because of the change in https://github.com/TryGhost/Ghost/pull/12787 - the renderer is now seeing absolute URLs when passed content from the model layer rather than `__GHOST_URL__` URLs. We didn't hit it in 3.x because that was passing content with relative URLs.
2021-03-20 22:17:43 +00:00
Peter Zimon
b3b6a603af
New logo in Admin (#12768)
refs https://github.com/TryGhost/Team/issues/547

- replaced link to static/squircle to orb
2021-03-18 17:27:27 +00:00
Kevin Ansfield
afbe0c27fb
🐛 Fixed __GHOST_URL__ appearing in sitemaps (#12787)
closes https://github.com/TryGhost/Team/issues/552

Refactors URL transforms so they take place at the model layer rather than the API serializer layer. Continuation of the pattern created for the settings model in https://github.com/TryGhost/Ghost/pull/12738

- Added checks to all front-end tests to ensure output does not contain the magic replacement string
  - includes failing acceptance test for `__GHOST_URL__` appearing in sitemaps
- Removed all transform-ready URL transforms from API serializers
  - input serializers transform image urls relative->absolute to keep absolute-urls as the consistent "outside of the database" format
  - output serializers should not need to perform any URL transforms as that will be done at the model layer
- Added url transforms to models layer
  - removes knowledge from the API serializers which shouldn't need to know how data is stored internally in the database
  - makes absolute urls the consistent "outside of the database" URL format
  - adds transform step to the sitemap generator because the data used for that is fetched directly via knex which will not run through the bookshelf `parse()` methods
2021-03-18 17:16:37 +00:00
Fabien 'egg' O'Carroll
d19452147d
🐛 Fixed @price template data to work with price helper (#12764)
closes https://github.com/TryGhost/Team/issues/545

The price helper requires an object with amount & currency properties to
work correctly. This updates the @price data object to expose these.

In order to maintain backward compatibility with using the @price data
as primitive number values, we add a valueOf method which returns the
legacy dollar amount value.

This means you can use {{price @price.monthly}} OR
{{@price.monthly}} - the second of which will output the dollar
amount.

A new theme fixture was added to test both usages of the @price data
2021-03-18 16:13:10 +00:00
Thibaut Patel
ba511445df Fixed broken tests from previous commit
commit 63d55570a3
2021-03-17 16:18:48 +01:00
Kevin Ansfield
7b1aa38841
🐛 Fixed AMP validation warning from accent color style tag (#12771)
closes https://github.com/TryGhost/Ghost/issues/12770

AMP pages can't contain bare `<style>` tags, they need to have an attribute like `<style amp-custom>` and there can only be a single `<style amp-custom>` tag in the output.

- removed accent color style tag output from `{{ghost_head}}` (aliased as `{{amp_ghost_head}}`) when in an AMP context
- added a new `{{amp_style}}` helper that can be used to inject styles into the AMP template
  - outputs `:root {--ghost-accent-color: #abc123}` style if an accent color is set
2021-03-17 11:49:42 +00:00
Naz
b5de4f4cf5 Reverted dropped model usage in post serializer
refs 6b07d4b2a0

- The model is needed here, because it contains full set of fields. In some cases, like email-preview, the "plaintext" field is not present in "attrs" which causes the logic to fail.
- This should be sorted along with https://github.com/TryGhost/Ghost/issues/10396
2021-03-17 20:01:12 +13:00
Naz
6b07d4b2a0 🐛 Fixed __GHOST_URL__ appearing in generated excerpts
refs https://github.com/TryGhost/Team/issues/467
refs a6f5eb71be

- When a generated excerpt is calculated for posts/page resources it uses raw model! to get the data. Model contains untranformed __GHOST_URL__ markup which has to be additionally processed before extracint an excerpt or use the transformed `plaintext` from available attributes (chose the latter to decrease complexity)
- Removed model dependency as `attrs` at this point of serialization should always contain the `plaintext` field. It's ugly and has an unsolved bug report here - https://github.com/TryGhost/Ghost/issues/10396. The reliance should be solved at some point, but definitely not a part of this issue
2021-03-17 19:12:40 +13:00
Kevin Ansfield
652fed6bd1
Fixed image and gallery cards not having srcset or sizes attributes (#12765)
no issue

- we run raw mobiledoc through the mobiledoc-html renderer and we now store URLs in raw mobiledoc as `__GHOST_URL__` relative. Those URLs were not passing the "local image" check in the renderer for image optimisation availability meaning the srcset and sizes output was skipped
- bumped library version to include a fix for the optimisation check
2021-03-15 21:38:27 +00:00
Kevin Ansfield
19d5448101
🐛 Fixed complimentary members' content gating (#12761)
no issue

Comped members were not able to view paid-member content because content gating was only looking for `member.status === 'paid'` which doesn't take into consideration members on a "complimentary" plan.

- added front-end acceptance tests for member access to posts
- updated content-gating check to take comped members into consideration
2021-03-15 19:13:48 +13:00
Hannah Wolfe
67adfe6054 Updated fixture copy
closes: https://github.com/TryGhost/Team/issues/528

- This only changes one sentence slightly to a minor grammar issue 💪
2021-03-11 19:20:30 +00:00
Fabien 'egg' O'Carroll
fac62cd698
Fixed circular dependency warning for the proxy service (#12746)
no-issue

The handlebars template module is required by the proxy service, as part
of the definition of the proxy service's module.exports. By
destructuring the i18n property from the proxy service at the time the
template module is loaded, the i18n property was always undefined, as the
module.exports of the proxy service had not been set.

Bypassing the proxy, and requiring the i18n module directly eliminates the
circular dependency.


* Refactored handlebars template tests to use proxy

Since this module is intended to be used via the proxy, we should test
it in the same way. We have uncovered a circular dependency issue, which
would not be possible to catch in tests unless the tests were to go via
the proxy.

* Added breaking test for handlebars template function

This test highlights the issue caused by a circular dependency, we are
unable to throw an IncorrectUsageError because i18n is undefined.
2021-03-11 16:30:49 +00:00
Hannah Wolfe
fdc043227a Updated fixtures for Ghost v4.0
- With 4.0 we have a brand new version of Casper, new fixtures and new default settings
- Fixture posts cover the key features and give users an introduction to how to use their site
- This all comes from the marketing and design teams to refresh the look and feel of Ghost and give users the best possible onboarding experience
Note: this fixture overhaul includes
- new content for new 4.0 features
- regenerated post content using our updated mobiledoc structure
- a switch from British to US English
2021-03-10 17:37:16 +00:00
Hannah Wolfe
44060d3515 Refined navigation default settings for 4.0
refs 2bba9989db

- Note: this will require new fixtures so that the navigation links actually work
- These updates are all in aid of getting the best possible default setup and onboarding experinence for new Ghost users
2021-03-10 10:42:21 +00:00
Hannah Wolfe
2bba9989db Updated default settings for 4.0
- With 4.0 we have a brand new version of Casper, new fixtures and new default settings
- This all comes from the marketing and design teams to refresh the look and feel of Ghost

Note on accent color:

This commit changes the default accent colour again.

The intention is that new sites should get #FF1A75 (pink) as their default.
Any existing sites that do not have an accent colour set yet, should get #15171A (black) on upgrading to 4.0.

These are different as they are different experinces. Fresh sites will be guided to pick a color, so
a bright color is more visible and helps to see what can be done, whilst existing sites get a muted
black, that should be a sensible fall back color.
2021-03-09 20:19:59 +00:00
Fabien 'egg' O'Carroll
15978689c0
Added default value to accent_color setting (#12743)
refs TryGhost/Team#535

We want to ensure that a site will always have a default value of
`'#15171A'` for the accent_color setting.

Since the boot process changed we have three cases to account for:

1. Setting does not exist
2. Setting exists with no value
3. Setting exists with a value

It is only in the case of 2. that we want the migration to update the
database with a default value.

In the case of 3. the site owner has already set a value, which we do
not want to override.

In the case of 1. the setting will be created (and populated with
default value) from the default-settings.json file, by the
populateDefaults method called from the settings service

We also update the accent_color setting to include a non-empty
validation, to ensure that the setting will always have a value, as
sites before 4.x may have an empty accent_color, we must update the
importer to set the default value if one is not present. Otherwise we
would run into validation errors and even if we didn't would have an
invalid database state.
2021-03-09 16:15:10 +00:00
Naz
a87d17e570 Updated utils for site endpoint response checks
refs 55dd16568b

- Fatfingered to add these files with a referenced commit
2021-03-09 22:12:05 +13:00
Naz
55dd16568b Added regression tests for Admin API /site endpoints
no issue

- We had a suspicion about a regression with these endpoints and there was no quick way to verify if these endpoints were failing due to a misconfiguration on the server or they broke generally for everyone
- Added tests as they were clearly lacking
2021-03-09 22:10:27 +13:00
Kevin Ansfield
021cfecb59
Fixed __GHOST_URL__ appearing in settings values after edit (#12738)
refs https://github.com/TryGhost/Ghost/pull/12736
refs https://github.com/TryGhost/Team/issues/467

knex's `parse()` method is only called on data when directly fetched from the db. This was causing problems when model instances are passed around via events for example because `.get('key')` will return data that was directly set on the model without having gone through the `parse()` transformations. The result of this inconsistency was settings appearing correct when Ghost started up but then being broken as soon as a setting was changed.

- moved absolute/relative->transform-ready URL transformations from the API input serializers to the model's `format()` method and replaced with a relative->absolute transform in API input serializers
    - results in consistency because `.get()` on a settings model will always return an URL
- removed transform-ready->absolute transforms from the API output serializers as that is now handled at the model-layer
2021-03-08 18:41:43 +00:00
Kevin Ansfield
ee6ca9b654
Fixed AMP URLs not being transformed to absolute (#12737)
refs https://github.com/TryGhost/Team/issues/467
refs https://github.com/TryGhost/Ghost/pull/12731

- AMP helper fetches HTML directly from the database rather than fetching via the API so we can't rely on the API serializers to perform transforms for us
- switched the `relativeToAbsolute(html)` call to `transformReadyToAbsolute(html)` to match the new `__GHOST_URL__` storage format
2021-03-06 09:43:50 +00:00
Kevin Ansfield
28f0bc6bd2
Fixed settings images (cover_image, logo, etc) having wrong URL (#12736)
refs https://github.com/TryGhost/Team/issues/467
refs https://github.com/TryGhost/Ghost/pull/12731

- settings are mostly fetched directly from the settings cache rather than via the API so they aren't subject to the API-level output serializers that transform URLs meaning that URLs in the front-end ended up with raw `__GHOST_URL__` replacement strings
- added images to the Settings model's `parse()` method so they are transformed immediately when fetching from the database
2021-03-06 09:00:18 +00:00
Kevin Ansfield
a6f5eb71be
🏗 Changed internal URL storage format to use __GHOST_URL__ (#12731)
closes https://github.com/TryGhost/Team/issues/467

- switches to storing "transform-ready" URLs in the database
- transform-ready URLs contain a `__GHOST_URL__` placeholder that corresponds to the configured url that gives a few benefits
  - much faster and less memory intensive output transformations through not needing to parse html or markdown - the transform can be achieved using a straightforward regex find+replace
  - ability to change to/from or rename subdirectory without any manual updates to the database
- modified existing 4.0 url-transformation migration rather than adding another one and repeating the transformation on posts rows
2021-03-05 13:54:01 +00:00
Matt Hanley
b4140d4310
Updated default format for date helper to locale-based date string (#12733)
refs https://github.com/TryGhost/Casper/pull/741
closes https://github.com/TryGhost/Team/issues/524

- Use a local-based format as the default format as suggested in https://github.com/TryGhost/Casper/pull/741
- reworked the helper to be easier to read and follow the different use cases
- introduced setting and resetting locale in tests via settingsCache and themei18n
- updated tests to cover more cases e.g. passing a date, this.published_at and no date
- added validation for user inputted dates because they could literally be anything

Co-authored-by: Hannah Wolfe <erisds@gmail.com>
2021-03-05 13:35:31 +00:00
Fabien O'Carroll
f03e1dd863 Excluded member events tables from site exports
refs https://github.com/TryGhost/Team/issues/525

We expect the member event tables to be large, and they contain what is
considered metadata. For this reason we do not want to include them in
the export of sites.
2021-03-05 11:41:00 +00:00
Hannah Wolfe
e30b9735fa Added staff user limit
refs: https://github.com/TryGhost/Team/issues/510

- In the case that host config is provided, keep staff users within the limiti
- The definition of a staff user is a user with a role other than Contributor, and whose status is not inactive
   - Contributors don't count
   - Suspended (status inactive) users don't count
   - Locked users DO count
   - Invited users DO count
- You can't invite more staff users whilst there are pending invites
- You can't unsuspend a user, or change the role on a user in such a way as will take you over your limit
- You can't import staff users - all imported users are automatically set to Contributors
- As part of this work, we are changing the default Ghost user to a Contributor otherwise it uses up a staff user

Note: there is one known active bug with this commit.
- Assume you have one remaining user within your limit. You send an invite, this works.
- You cannot "resend" that invite, it will think you're sending a new invite and hit the limit
- You must "revoke" that invite first, and create a new one
- This bug exists because the resend function uses the add endpoint & does a delete+add, but this hits the permission check before the delete
2021-03-04 16:13:04 +00:00
Hannah Wolfe
84e5bdc46a Fixed accent color on pages with no context
refs: refs 74fe765410

- Some pages, like error pages have no context.
- In that case there is also no previous style or script tag and so the existingScriptIndex is -1, not 0/falsy :D
- This ensures we always add this style tag
2021-03-04 10:56:53 +00:00
Naz
4ac5feaa0a Fixed webhook model unit test 2021-03-04 10:56:58 +01:00
Naz
f57115d3cc Fixed fixture creation order in webhooks tests
- The tests need to have 'integrations' as a first fixture created so that webhooks can relate to an integration
2021-03-04 10:56:58 +01:00
Naz
cc0a655a3d Fixed data generator crating webhooks linked to intergrations
- This is needed to prevent FK failures
2021-03-04 10:56:58 +01:00
Thibaut Patel
e52dc87b7c Added a foreign key from webhooks to integrations
issue https://github.com/TryGhost/Team/issues/477
2021-03-04 10:56:58 +01:00
Naz
9995ae3616 Added support for locale key in Admin Settings API
refs https://github.com/TryGhost/Team/issues/509

- Allows to update and read 'locale' key along with the deprecated 'lang'
- In Ghost v5 the 'lang' key will be dropped and the migration in settings table will clean up the key name to match the one exposed through the APIs
2021-03-04 21:20:46 +13:00
Naz
7a11a9b3c4 Bumped gscan to 4.0.0-pre.5
refs https://github.com/TryGhost/Team/issues/509

- Updated version includes {{@site.lang}} deprecation
2021-03-04 21:18:27 +13:00
Naz
07254edfe3 Fixed cache test suite
refs 41c93f982d

- The public settings hash was "turned around" so that the object keys are now identified by "keys" on "values"
2021-03-04 18:35:02 +13:00
Naz
41c93f982d Added 'locale' property to public settings
refs https://github.com/TryGhost/Team/issues/509

- During 3.x we standardised on "lang" instead of "default_locale" for the site setting, which was an assumption based on an earlier change to @site.lang to make <html lang="@site.lang"> read nicer. This was a mistake as the field represents more than "lang" its a "locale". With this changeset we introduce a transition to use "locale" name for the value instead of "lang"
- Adds `@site.locale" value in as well as new 'locale' property in Content API's response
- "lang" will be considered as deprecated starting with API v4 and will be dropped completely with API v5
2021-03-04 16:00:02 +13:00
Naz
e133c45314 Cleaned up public settings test suite
refs https://github.com/TryGhost/Team/issues/509
refs c2a3297f5d

- Before introducing new public setting made sure the test is up to date and checks everything it was intended to.
2021-03-04 15:41:49 +13:00
Naz
e7e5f0ad15 Updated API versions used in regression test for webhooks
refs https://github.com/TryGhost/Team/issues/513

- Tests confused versions after doing a "tripplication"
- Extracted a global "API_VERSION" variable for each suite to make api version used in the test explicit
2021-03-04 13:06:16 +13:00
Rish
cb43a8e3a8 Updated fixture for test theme to use @site
no refs
refs b56e684258

The test theme fixture was using old `@blog`  helper which was deprecated in v2 and replaced with `@site`. Since the latest bump to Gscan - b56e684258 - now validates a theme by going through nested `*.hbs` files, this was missed so far as it didn't fail the tests. This commit updates the test theme fixture to use updated value.
2021-03-04 01:09:54 +05:30
Kevin Ansfield
1cc3f35043 Fixed accent color not updating in front-end preview
refs https://github.com/TryGhost/Ghost/pull/12717

- preview data is set on `options.data.site` so we need to read from that rather than directly from the settings cache
2021-03-03 08:00:41 +00:00
Hannah Wolfe
acd7e41e21 Added ghost scope to CSS variable
refs 74fe765410

- Added scoping to the global CSS variable being set by Ghost to prevent theme conflicts and create a forwards compatible pattern
2021-03-02 19:48:58 +00:00
Kevin Ansfield
74fe765410
Added accent color CSS variable to {{ghost_head}} (#12717)
closes https://github.com/TryGhost/Team/issues/508

- if an accent colour is set in site settings, output a `--accent-color` CSS variable in a `<style>` tag through `{{ghost_head}}`
- allows themes to use the accent colour without adding an additional conditional with CSS variable declaration to their default template
2021-03-02 11:40:45 +00:00
Rish
886f564dc4 Updated default visibility in foreach for posts to all
closes https://github.com/TryGhost/Team/issues/485

In order to loop over all posts, we currently need to pass a visibility="all" flag to a foreach as default for all items in current `visibility` helper is set to `public`. For a post, this behaviour is unintuitive, and inconsistent with the API. Instead, the default visibility should be "all" for the posts. The update allows themes to get all posts directly without passing in visibility -

```
{{#get "posts"}}
    {{#foreach posts}}
        //Loops over all posts, not just `public`
    {{/foreach}}
{{/get}}
```
2021-03-02 15:44:19 +05:30
Thibaut Patel
874ccaef53 💡 Enabled foreign key checks on sqlite3
issue https://github.com/TryGhost/Team/issues/476
2021-03-02 11:13:19 +01:00
Fabien O'Carroll
24afc5d4ff Fixed status code for unauthenticated requests
refs https://github.com/TryGhost/Team/issues/498

Requests to fetch the data of the logged in member made without a
session cookie were responsing with 400 Bad Request. This was incorrect
and always should have been a 401 Unauthorized.
2021-03-01 16:19:28 +00:00
Hannah Wolfe
1c7c246616 🐛 Fixed theme preview not decoding values properly
- Theme preview was not showing the same behaviour as a real theme because nulls were being encoded and decoded incorrectly causing nulls/empty strings to be treasted as truthy values
- Swap from using split to using proper query param parsing so that the code is more robust
- this still creates empty strings and the string 'null' so added a small function to decode these back to real nulls
- moved to its own file ready to be split out - there needs to be a bigger picture plan for this
- added unit tests to cover the known issues + some potential breakages from converting the header string to a query param object
2021-03-01 11:54:50 +00:00
Thibaut Patel
4a939054ba Added a primary key to the brute table
issue https://github.com/TryGhost/Team/issues/267
2021-03-01 12:17:26 +01:00
Naz
ecdc9eaefd Added instructions about theme fixtures maintenance
refs 492f115850

- Added quick copy-pasteable instruction on modifying theme fixtures
- Added notes about possible future improvemetns and current pitfalls when touching theme fixtures
2021-03-01 19:32:20 +13:00
Naz
492f115850 Bumped gscan to 4.0.0-pre.1
refs https://github.com/TryGhost/Team/issues/492
d0e0760dae

- With Ghost 4.0 it will detect deprecated {{@labs.members}}  warning and use of deprecated ghost-api v2 in theme's package.json
2021-03-01 19:26:17 +13:00
Rish
67bf3a77c1 Updated price helper to output well formatted prices
refs https://github.com/TryGhost/Team/issues/472

The current `{{price}}` helper only works with `amount` to convert it into right value but doesn't allow any formatting with currency etc, leaving most of the work to theme.  We want to be able to output well formatted prices. E.g. the API returns 5000 for 5 EUR but we want to output €5.

The updated {{price}} helper can take a plan object or plan amount currency and use them to output a well formatted price. It works with JS's built in Intl.NumberFormat behaviour to return output in different formats, also allowing theme devs to override formatting with options.

Examples:

With Plan object => `{{price plan}} → "€5"`
With Plan object and custom number format =>  `{{price plan numberFormat="long"}} → "€5.00"`
Output only currency symbol =>  `{{price currency='EUR'}} → "€"`
2021-02-25 13:01:24 +05:30
Kevin Ansfield
7cec1ecb57 Added acceptance test for github theme installs
refs https://github.com/TryGhost/Team/issues/480

- testing happy path
  - mock github api request with redirect to zip-file download endpoint
  - theme is installed with a name of the github repo
  - response matches a theme upload response
2021-02-24 10:16:25 +00:00
Naz
e63e4bb193 Hardened frontend tests checking API engine
refs 0f59537b96
refs https://github.com/TryGhost/Team/issues/221
refs 303046bc0a

- When the referenced changes were introduced they did not take into account upcoming engine versions and provided little guidance about what other areas might need to be checked and changed
- The last referenced commit shows an approximate scale of changes that might be beened when frontend engine defaults are modified in the future
2021-02-24 18:55:12 +13:00
Naz
11b2876c33 Removed unnecessary describe nesting
refs e71bb91541

- Simplified the file structure/nesting of the test suites
2021-02-24 14:32:03 +13:00
Naz
9dc71e1e84 Renamed site suite files to snake case patter
- The snake case pattern is used in all the rest of test suite file names
- Cleaned up these two files as they were sticking out in the folder I was touching
2021-02-24 14:22:22 +13:00
Naz
e71bb91541 Extracted api engine specific suites from site spec
refs https://github.com/TryGhost/Ghost/commit/abeabb764

- Continued work started in referenced commit in making sites_spec more manageable.
- Extracted out separate v2/v3/canary specs for each site configuration
- Now these files are easily diff'able and introducing new API version would include copying a file over instead of adding up to a gigantic file
2021-02-24 14:19:22 +13:00
Naz
abeabb7648 Moved site spec under separate folder
refs https://github.com/TryGhost/Ghost/commit/2f20930ff

- The aim is to split site test suite into separate files v2/v3/v4 after this move
- It is hard to grep or diff the file of this size.
- Having separate files per ghost-api engine will allow tracking changes between different API versions in the future
- It's a continuation of work started in refed commit
2021-02-24 14:02:13 +13:00
Naz
2f20930fff Moved vhosts tests out of site test suite
no issue

- The site_spec is a catch all suite with too many moving parts. While adding a new tests suite for v4 frontend configuration it felt overwhelming to add hundreds of lines to a >5000 line monstrocity
2021-02-24 13:55:54 +13:00
Thibaut Patel
05b77397b6 Fixed the tests
commit 26e20d223d
2021-02-23 15:18:32 +01:00
Thibaut Patel
0f59537b96 Added the v4 version to the themes engine
issue https://github.com/TryGhost/Team/issues/221
2021-02-23 11:38:44 +01:00
Hannah Wolfe
70ed998838 Replaced db.ready event with direct call to urlservice
refs dd715b33dc

- this is the last event that is used to trigger part of the standard boot process
- events make the code harder to read/reason about
- the urlservice is one of the most core and critical components in Ghost, possibly the biggest consumer of time and memory
- we want to have the work it is doing front and center so that we can improve it
2021-02-23 10:05:59 +00:00
Kevin Ansfield
08e1268aed
Added migration to remove surrounding <> in email_batches.provider_id (#12673)
refs https://github.com/TryGhost/Team/issues/221#issuecomment-759105424

- Mailgun responds to an email send with a provider id in the format `<x@y.com>` but everywhere else it's used in their API it uses the format `x@y.com`
- updates email batch save to strip the brackets, and migration removes brackets from existing records so we no longer have to add special handling for the stored id any time we use it
2021-02-23 08:48:21 +00:00
Hannah Wolfe
dd715b33dc Replaced themes.ready event with direct call
refs b1a98b0b67

- note: I already replaced server.start with themes.ready in the above commit
- events make the code harder to read/reason about
- long term it would be nice to have a concept of hooks for services, but for now explicit is clearer
2021-02-22 21:05:06 +00:00
Thibaut Patel
a551970315 Updated the configuration to include v4 pointing to canary
issue https://github.com/TryGhost/Team/issues/221
2021-02-22 15:39:48 +01:00
Hannah Wolfe
176433e307 Refactored notify to send started + ready
- In the old boot the server wasn't started til we were ready
- In new boot, we start the server immediately and send the old started event
- Then, when we are ready to accept some traffic, we send a ready event
- At the moment, ready isn't quite sent at the right time:
   - It _should_ be when we're ready to serve real traffic, not just send 503s
   - This is after the URL generation has finished
   - But this requires more refactoring work :(
   - So for now we send when everything else is ready
- This really needs some tests
2021-02-19 20:42:10 +00:00
Hannah Wolfe
2527efd6fc Moved notify out of GhostServer
- make this a standalone module
2021-02-19 20:22:56 +00:00
Hannah Wolfe
b65cb7bd7b Renamed announceServerReadiness to notifyServerStarted
- Notify is a more familiar name e.g. systemd has the sd_notify system which this is similar to
- We're actually announcing the server started, it's not actually ready for traffic (will serve 503s)
2021-02-19 20:11:35 +00:00
Hannah Wolfe
09eadad667 Removed extra console times for test utils
- Think it's pretty clear these functions take ~30ms consistently
- Not interesting to optimise these when the whole restart takes seconds
2021-02-19 15:30:40 +00:00
Hannah Wolfe
b1a98b0b67 Cleaned up global server events
- use theme.ready for loading themes instead of server.start and properly clean this up
- remove server.start and server.stop as they are no longer used (only server.start was used, and only for themes)
- we're moving away from the pattern of using global events like this as they are hard to reason about
2021-02-19 15:21:58 +00:00
Hannah Wolfe
481e2425af Finalised new boot process
- This commit removes the old boot process and any files that are no longer needed as a result
- Remove the duplicate event for triggering inactive themes to load
- Tidied up a few other bits
2021-02-19 13:15:12 +00:00
Hannah Wolfe
f1be3418d9 Switched tests to use new boot method
- We currently have 2 boot systems in the codebase, until now the tests were still running against the old one
- Regression tests using the forceStart + subdir flag no longer work. These need reworking, but this _should_ be easier later
- Note those tests work fine if they were the first tests run, it is only the case of trying to restart the server with a subdirectory after starting without that doesn't work
2021-02-18 20:24:49 +00:00
Kevin Ansfield
29f34468f5
Updated mobiledoc tests for lazy loaded images (#12672)
refs 074ce4efb0
2021-02-18 19:49:40 +00:00
Hannah Wolfe
5970f1df9e Split out old boot method from test utils
- clearly mark what counts as "boot" so we can swap it for new boot
2021-02-18 16:11:47 +00:00
Hannah Wolfe
469382eb95 Cleaned test utils start and stop Ghost functions
- create clarity around the two modes of "starting" ghost - one is just a reload of the DiB and some services!
- both of these modes ends the same way - with exposing fixtures and returning the server
2021-02-18 15:38:31 +00:00
Hannah Wolfe
d6a319aa3e Cleaned test utils exposing fixtures
- This is actually a really useful part of our test framework
- Rewrite it to be cleaner and clearer what does
- Add timing function to see if its worth optimising this later
2021-02-18 15:38:31 +00:00
Hannah Wolfe
9f718750b4 Added comments and TODOs to startGhost test util 2021-02-18 15:38:31 +00:00
Kevin Ansfield
c7a29b4e7c
🐛 Fixed unexpected members-only content appearing in excerpt field (#12670)
closes https://github.com/TryGhost/Team/issues/468

- updated post-gating
  - clears excerpt if there's no access
  - rebuilds excerpt from free preview if paywall card is used and there's no custom excerpt
2021-02-18 14:12:06 +00:00
Hannah Wolfe
cf93b168d8 Revert committing new test code 2021-02-18 10:27:19 +00:00
Hannah Wolfe
24bfb5567b Cleaned up test utils with async/await
- I'm on a mission to make this code comprehensible so we can work it into something better with new boot
- Who else loves async/await? :D
- Dried up a block of duplicated code
2021-02-18 10:15:19 +00:00
Kevin Ansfield
2c96df42ac
Added paywall card to mark end of free content preview (#12663)
closes https://github.com/TryGhost/Team/issues/466

- upgraded kg-default-cards to include paywall card
- extracted `htmlToPlaintext` from post model to shared util for re-use
- updated post-gating to set html+plaintext to the free preview if a paywall card has been used
  - re-generates plaintext from the truncated html using `htmlToPlaintext` util
- display free content in the `{{content}}` helper via the default CTA template
2021-02-17 23:00:26 +00:00
Fabien O'Carroll
7785fb6dc5 Refactored usage of pre v4 "unsplash" setting format
refs https://github.com/TryGhost/Ghost/issues/10318

- API changes introduced:

canary/v4 Admin API
GET /settings/ (browse)

+ "unsplash" present in response as boolean value

GET /settings/:settingName (read)

+ "unsplash" present in response as boolean value

PUT /settings/ (edit)

+ "unsplash" updates setting, accepts ONLY  boolean format

v3  Admin API
GET /settings/ (browse)

+ "unsplash" present in response with object value

GET /settings/:settingName (read)

+ "unsplash" present in response with object value

PUT /settings/ (edit)

+ "unsplash" updates setting, accepts either boolean or object formats

v2 Admin API
GET /settings/ (browse)

+ "unsplash" present in response with object value

GET /settings/:settingName (read)

+ "unsplash" present in response with object value

PUT /settings/ (edit)

+ "unsplash" updates setting, accepts object format
2021-02-18 10:55:59 +13:00
Fabien O'Carroll
9cb069eb8e 🏗 Updated "unsplash" setting handling to match updated format
refs https://github.com/TryGhost/Ghost/issues/10318

- JSON object format used in previous "unsplash" setting was considered an
anti-pattern. Flat structure was extracted out of the "unsplash.isActive" JSON.
- The naming convention uses `amp` as  a precedent (https://github.com/TryGhost/Team/issues/331#issuecomment-658815017)
2021-02-18 10:55:59 +13:00
Hannah Wolfe
9964a5c23a Moved cacheRules from testUtils into fixtures
- yet more tidy up of the huge test utils index file
2021-02-17 17:55:38 +00:00
Hannah Wolfe
1b4ebce3b0 Split urlServiceUtils from testUtils & unified
- There is now just one way to wait until the UrlService is finished across all of our tests!
- db.ready is only called in the one utility + the actual UrlService tests
2021-02-17 17:36:27 +00:00
Hannah Wolfe
a0bdba2516 Added theme preview mode
- Allow the frontend to accept post messages to generate previews of the frontend
- Created a new endpoint in admin we can use to render these previews, which is possibly not necessary
- Supports a limited group of settings, which can easily be expanded, but care should be taken if expanding to use user-provided strings
2021-02-17 13:49:41 +00:00
Naz
d0e0760dae Hardcoded labs to always return members:true
refs https://github.com/TryGhost/Ghost/issues/10318

- Because members is effectively "enabled" by default starting Ghost 4.0 have hardcoded labs setting to be such. The alternative of removing this key from labs would be equivalent to `labs.members === false` which is undesireable and would mean additional work on theme developer's side.
2021-02-17 19:55:16 +13:00
Naz
37ef40b46e Dropped support for labs setting parameter
refs https://github.com/TryGhost/Ghost/issues/10318

- `labs` setting is dropped from setting values as the use of JSON objec
to sore settings has been deprecated
- `labs` setting is no longer accepted as a paramter in the Settings API nor the
impoprter. The value is ignored if present in the POST/PUT requests and
returns 404 in case it is requested by key at `GET /settings/:key`
2021-02-17 19:55:16 +13:00
Naz
ea6d656457 🏗 Removed labs from setting
refs https://github.com/TryGhost/Team/issues/332

- The last value that has been used in the code was "members"
- By default members will be always "on" starting Ghost 4.0, so there's no need for this flag anymore
- Therefore there's no real need to keep "labs" around
2021-02-17 19:55:16 +13:00
Thibaut Patel
58be6d23db Split the "Too many requests" error in ping service
issue https://github.com/TryGhost/Team/issues/362
2021-02-17 13:18:45 +13:00
Hannah Wolfe
21b30c94f4 Split test utilities out into separate files
- The current huge test utilities file is really hard to reason about
- It is so big we have no idea what's in it anymore
- It's also full of terrible code we want to rework
- Splitting it down into smaller pieces makes it easier to see which are the worst bits!
2021-02-16 20:17:04 +00:00
Fabien O'Carroll
87471fd5c6 Revert "Updated plan_nickname column to be nullable"
This reverts commit 5d122c3c62.
2021-02-16 18:19:09 +00:00
Kevin Ansfield
33bd36b4d6 Updated mobiledoc tests to expect image width/height attributes
refs 4516577c3e
2021-02-16 16:09:57 +00:00
Kevin Ansfield
bb371017fe Updated expected mobiledoc handling missed importer tests
refs 2d091fa8f9
2021-02-16 12:34:27 +00:00
Kevin Ansfield
2d091fa8f9 Set mobiledoc.ghostVersion: '3.0' if missing on imported content
refs https://github.com/TryGhost/Ghost/issues/12646

- if the version is missing then the content was created before Ghost 4.0
- setting the version to `'3.0'` means it will continue to use the same rendering output so there are no unexpected breaking changes when migrating content
2021-02-16 12:08:40 +00:00
Kevin Ansfield
77f75808a7 Updated tests for new mobiledoc output
refs f6e7dac7bb
2021-02-16 11:42:07 +00:00
Fabien 'egg' O'Carroll
f4cb5c57c6
Updated members_status_events table (#12647)
refs https://github.com/TryGhost/Ghost/issues/12602

* Updated members_status_events table

By replacing the `status` column with a `from_status` and `to_status`
column, we are able to track the changes between multiple statuses
easier, and accumulate the data. e.g. the delta of paid members in a
given time range is the sum of the `to_status` columns set to 'paid'
minus the sum of the `from_status` columns set to 'paid' within that
time range

* Updated MEGA to handle addition of 'comped' status

With the addition of the 'comped' status, we need to ensure that MEGA
will still send emails to the correct recipients. I've opted to use an
"inverse" filter, as that is the intention of the free/paid split in
MEGA - as far as MEGA is concerned, "free" is the opposite of "paid"

* Updated customQuery for MemberStatusEvent

With the `status` column replaced with `from_status` and `to_status`
this allows us to fix and update the customQuery to correctly accumulate
the data into deltas over time, broken down by day.

* Populated members_status_events table

As the table will be used to generate deltas, we need to backfill the
data so that existing sites will be able to sum up the deltas and
calculate correct data.

The assumptions used in backfilling is that a Member's current status,
is their only status.
2021-02-16 10:38:36 +00:00
Kevin Ansfield
647529f56d Updated importer specs for mobiledoc.ghostVersion
refs ef76279084

- updated specs to expect `mobiledoc.ghostVersion` in blank documents
2021-02-15 19:32:36 +00:00
Kevin Ansfield
70486ccb4e
Updated importer to transform 'card-markdown' to 'markdown' (#12650)
refs https://github.com/TryGhost/Ghost/issues/12646

- `card-markdown` support is being removed from the default mobiledoc cards so we need to make sure imported content doesn't fail
- removed long-unused `cardName` payload property from tests
2021-02-15 16:42:01 +00:00
Fabien O'Carroll
8880cc82c7 Refactored usage of the pre v4 "slack" setting
refs https://github.com/TryGhost/Ghost/issues/10318

- Change/compatibility table for this changeset:

Importer

+ "slack_username"  import
- "slack_url" ignore
+ "slack.username" import
- "slack.url" ignore

v3 & canary/v4 Admin APIs
GET /settings/ (browse)

+ "slack_username" present in response
+ "slack_url" present in response
+ "slack" present in response

GET /settings/:settingName (read)

+ "slack_username" present in response
+ "slack_url" present in response
+ "slack" present in response

PUT /settings/ (edit)

+ "slack_username" updates setting
+ "slack_url" updates setting
+ "slack" !NOTE! updates setting unless "slack_username" or "slack_ur"l are set (updated keys take priority)

v2 Admin API
GET /settings/ (browse)

- "slack_username" NOT present in response
- "slack_url" NOT present in response
+ "slack" present in response

GET /settings/:settingName (read)

- "slack_username" ignored (404)
- "slack_url" ignored (404)
- "slack" present in response

PUT /settings/ (edit)

- "slack_username" ignored (no error)
- "slack_url" ignored (no error)
+ "slack" updates setting
2021-02-15 15:25:54 +13:00
Fabien O'Carroll
12c28fe66e 🏗 Updated "slack" setting into "slack_{url,username}"
refs https://github.com/TryGhost/Ghost/issues/10318

- Object format used in previous "slack" setting was considered an
anti-pattern. Flag structure of separate slack_url and slack_username
values was extracted out of the "slack" JSON.
2021-02-15 15:25:54 +13:00
Rishabh Garg
1d281581eb
Updated members_email_change_events to store previous email (#12641)
refs https://github.com/TryGhost/Ghost/issues/12602

As we only want to add events for when an email is changed, we need to store the previous email if we want a complete log of all emails for a member
2021-02-12 16:15:31 +00:00
Thibaut Patel
2f547b2974 Added the frontmatter column to meta
issue https://github.com/TryGhost/Team/issues/452
2021-02-12 15:31:04 +01:00
Fabien 'egg' O'Carroll
f745fa7621
Updated members_paid_subscription_events table (#12636)
refs https://github.com/TryGhost/Ghost/issues/12602

This allows us to store the stripe_id of the subscription events
2021-02-11 12:45:18 +00:00
Fabien 'egg' O'Carroll
601d135b43
Added members event tables (#12618)
refs https://github.com/TryGhost/Ghost/issues/12602

* Added members_payment_events table

This table will store successful and unsuccessful payment attempts, and
can be used to calculate gross volume over time.

* Added members_login_events table

This table can be used to audit member logins

* Added members_email_change_events table

This table will allow us to store a history of email addresses associated with a member

* Added members_status_events table

This table will allow us to track the change in status over time for members, as well
as calculate aggregates over time, e.g. paid members over time

* Added members_paid_subscription_events

This table will allow us to track subscriptions changes for members, as well as 
calculating MRR over time
2021-02-11 10:54:30 +00:00
Daniel Lockyer
8e05a375ad Updated code to reflect js-yaml dependency changes
no issue

- as per
  https://github.com/nodeca/js-yaml/blob/master/migrate_v3_to_v4.md,
  `safeLoad` is now `load` and safe by default, so we can just switch to
  that
2021-02-10 11:39:30 +00:00
Rish
1272968848 Updated {{content}} helper partial template name
no issue
refs e3a0bb535f

Previously, {{content}} helper was updated use default or custom template to show a CTA when trying to use helper without access to content.

While the change was expected to not affect any existing themes as `{{content}}` helper is not supposed to be used on member sites without `access` check, we found quite a few themes use a pattern of using `content.hbs` with `{{content}}` helper inside them as default, which causes infinite loop in how content helper works in certain cases.

Whilst this followed the pattern of the other helpers using a partial with the same name, there are 2 key differences:

- this partial template pattern is being introduced way after the inception of themes with a fairly generic name “content”
- this partial template isn’t used to render the helper all the time - just the CTA part under certain circumstances.

This change updates the template name to `content-cta.hbs` to which makes it less likely to clash, and makes more sense as to what it is.
2021-02-09 13:59:52 +05:30
Naz
e0178099a2 🏗 Altered slug unique constraint in posts table
refs https://github.com/TryGhost/Ghost/issues/12567

- Changing unique constraint from slug to slug+type should allow for posts and pages to be created with the same slug
- The constraint will be present on application layer for API v4 while we figure out how to deal with it in API v5
2021-02-09 13:31:12 +13:00