Commit Graph

57 Commits

Author SHA1 Message Date
Simon Backx e5f644c27f
🐛 Fixed contain/starts/endsWith filters with /, _ or % in them (#19015)
fixes GRO-25

Updated @tryghost/nql to 0.12.0 and other packages that depend on it

1. SQLite: when a filter string contains /.

When we use a NQL contain/starts/endsWith filter that contains a slash,
underlyingly the whole filter will get converted to a MongoDB query, in
which we just use a regexp to represent the filter. In here we will
escape the slash: \/ as expected in a regexp. Later when we convert this
MongoDB query back to knex/SQL, we use a SQL LIKE query. Currently we
don't remove the escaping here for a normal slash. MySQL seems to ignore
this (kinda incorrect). SQLite doesn't like it, and this breaks queries
on SQLite that use slashes. The solution here is simple: remove the
backslash escaping when converting the regexp to LIKE, just like we do
with other special regexp characters.

2. We don't escape % and _, which have a special meaning in LIKE queries

Usage of % and _ is now as expected and doesn't have the special SQL
meaning anymore.
2023-11-16 09:35:20 +00:00
Nick Moreton b9b1502772
🐛Changed "free_signups" to "signups" in Post Exporter (#18883)
ref https://github.com/TryGhost/Product/issues/4110

Made this change to increase clarity in data export

---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 6c0508d</samp>

Renamed a column in posts export data and updated the corresponding test
case. This change makes the export data more consistent and clear for
users who have different member features enabled.
2023-11-07 09:52:28 +00:00
renovate[bot] 057d9599f5 Update TryGhost packages 2023-10-31 20:54:17 +01:00
Daniel Lockyer 85d41d0562 Aligned dependencies with resolution values
- this commit brings all dependencies up-to-date with the version set as
  a resolution
2023-10-13 08:37:36 +02:00
Fabien "egg" O'Carroll 6de0a2bfff Fixed `#bulkDestroy` from calling `bulkDestroy`
Rather than calling itself with the newly created transaction, it would call
the "parent" method, which meant that two events were dispatched. TBH I think
we can get rid of the check for a transaction here, and so the parent method
too, but not 100% sure.
2023-10-11 11:05:16 +02:00
Daniel Lockyer 85098e07d4 Configured all unit tests to use dot reporter
refs https://ghost.slack.com/archives/C02G9E68C/p1696490748701419

- this configures mocha to use the dot reporter because the default is
  way too verbose in CI
2023-10-05 12:24:24 +02:00
Fabien "egg" O'Carroll 3a624ec3a1 Fixed return values of CollectionService
Our service layer should not expose the Entities, it should return the DTOs.
This is to allow us to make internal refactors without having to modify the
entire stack.
2023-09-22 19:05:37 +07:00
Kevin Ansfield 1c68bd6779
Fixed transaction errors using PostsService inside of Post model's `onSaving` hook (#18148)
no issue

`PostsService` and `CollectionsService` were missing some passthroughs and had differing naming for a transaction instance on the `options` object which meant SQLite would hang if the Lexical renderer called out to `PostsService.browsePosts`

- added passthrough of `transacting` to the Lexical renderer ready for implementation of the collection-fetching function
- added rename of `options.transacting` to `options.transaction` and passthrough from `PostsService` to `CollectionsService` (passthrough from collections repository to bookshelf and required `transaction->transacting` was already in place)
2023-09-14 17:22:10 +00:00
Naz 11624e48ca Fixed filtering posts by empty collections error
https://github.com/TryGhost/Arch/issues/90

- Ghost produced an error when a collection filter was applied over Posts API and that collection contained no posts.
2023-09-14 14:31:23 +08:00
Daniel Lockyer c6cb35074a Updated linting and testing packages 2023-09-01 15:51:17 +02:00
Fabien 'egg' O'Carroll 7c934ebf46
Enabled `collection` param for Post APIs
This will allow us to browse posts based on their collection which will
be used for rendering the collections card. As with the Collections API
we're not opening up the write endpoints yet.
2023-08-28 07:34:58 +00:00
Naz 46f8c15448 Fixed flaky test behavior for bulk actions
refs https://ghost.slack.com/archives/C02G9E68C/p1692816097875899

- With introduction of extra e2e test coverage for Collections some tests started to fail at random. The root issue here was the transaction processing collections was started before the original bulk action (bulk edit, bulk publish/unpublish, etc.) was fully committed. The full transaction commit happens with the bulkAction method return inside of `if (!options.transacting) {` block.
2023-08-24 16:06:41 +08:00
Naz acccc16614 Added collections update after bulk adding tags
refs https://github.com/TryGhost/Arch/issues/77

- During initial development we have missed to support collections update when tags are added to posts in bulk. It's especially valid usecase since we can define automatic collection with a filter containing not yet existing tags.
2023-08-23 17:12:08 +08:00
Naz 18a4fa8cd9 Added bulk posts action events dispatching
refs https://github.com/TryGhost/Arch/issues/16

- Allows to subscribe to bulk unpublish/featured/unfeatured DomainEvents elsewhere in the system, for example, Collections.
2023-08-01 15:11:00 +08:00
Naz 9b257f3966 Update of collection posts on bulk destroy
refs https://github.com/TryGhost/Arch/issues/16

- When the bulk destroy is done on posts Collections need to know about the update and remove the stored posts from collections.
2023-08-01 15:11:00 +08:00
Naz ffa101b550 Added post events package
refs https://github.com/TryGhost/Arch/issues/16

- This package is meant to hold Domain Events associated with Post model/entity. The very first one here is PostsBulkDestroyedEvent needed to signal bulk destroy action completion from the posts service.
2023-08-01 15:11:00 +08:00
Naz 48ccea818a Fixed unpublished collection posts filtering
closes https://github.com/TryGhost/Arch/issues/58

- Following assumptions were broken:
- Posts Admin API should include posts of all statuses when filtering by collection
-  Posts Content API should not include any unpublished posts
- Updated the "status" filter which fixes the problem. We still disallow any custom filters to be applied on top of collections filter.
2023-07-26 16:45:57 +08:00
Naz 6361423ff7 Fixed ability to remove post from an automatic collection
refs https://github.com/TryGhost/Arch/issues/16

- Post can be removed from a manual collection, but never from an automatic collection.
2023-07-21 19:46:22 +08:00
renovate[bot] 7dce046786 Update Test & linting packages 2023-07-11 15:26:07 +02:00
Kevin Ansfield 5d8ea79788
Implemented `pages.hide_title_and_feature_image` property in API (#17211)
closes https://github.com/TryGhost/Product/issues/3557

- bumped `@tryghost/admin-api-schema` to allow passthrough of the new property in API requests
- updated output mapper to ensure property always returns a boolean rather than `null` in the case where `posts_meta` doesn't exist for a page
- updated `PostsService.copyPost()` to include the new property when copying
- updated `checkResponse` test util and snapshots to expect `hide_title_and_feature_image` property in page API responses
- fixed pages e2e test so it doesn't inadvertently modify the match object breaking later tests
2023-07-05 14:01:24 +00:00
Michael Barrett 998f862e87
🐛 Fixed newsletter post duplication (#17103)
closes https://github.com/TryGhost/Team/issues/3521

When duplicating a newsletter (email only post) some of the fields
relating to the newsletter (i.e `newsletter_id`) were being erroneously
copied over. Upon publishing this made the post appear as if it was an
email only post that had been sent to subscribers when it actually had
not
2023-06-23 11:18:35 +01:00
Simon Backx e94bdd57ae Updated posts exporter comment tests
fixes https://github.com/TryGhost/Team/issues/3505

I've investigated this, but luckily this is expected behaviour, and was just an error previously in the test:
- The `feedback_more_like_this` and `feedback_less_like_this` columns are only hidden if there is no newsletter with feedback enabled, or if member features are disabled.
- Having a post which is a draft, should not change the visible columns, only global settings should change the comments (so the format is consistent).
- Instead of that, the columns should be null, which means it will be visible but empty.
2023-06-21 16:57:54 +02:00
Hannah Wolfe 6161f94910
Updated to use assert/strict everywhere (#17047)
refs: https://github.com/TryGhost/Toolbox/issues/595

We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default.

This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results:
- Url matching needs to be done on `url.href` see aa58b354a4
- Null and undefined are not the same thing,  there were a few cases of this being confused
- Particularly questionable changes in [PostExporter tests](c1a468744b) tracked [here](https://github.com/TryGhost/Team/issues/3505).
- A typo see eaac9c293a

Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
2023-06-21 09:56:59 +01:00
Naz 09264261b7 Added ability to fetch posts by collection
closes https://github.com/TryGhost/Team/issues/3423

- For convenience we need a way to fetch posts that belong to a certain collection. This change adds support for `collection` query parameter: `/?collection=` which can be either an id or slug of the collections we are trying to fetch.
- When posts are fetched by collection we ignore any filters passed along in query parameters as collection is a "filter" by it's very nature.
2023-06-16 17:28:12 +07:00
Naz 1d214361ad
Refactored posts browsing to posts service
refs https://github.com/TryGhost/Team/issues/3423

- This refactor allow for smaller and cleaner change that's coming up when dealing with `?collection=` query parameter
2023-06-16 14:52:55 +07:00
Fabien "egg" O'Carroll 0d7f98f4d1 Supported adding/removing post to collection via Posts API
We've got some fairly simple diffing logic here to update the collections which
a post is in, the bulk of the changes here are to support the return of a DTO
rather than Bookshelf Model. This also helps improve the architecture because
we are step closer to removing infrastructure concerns (HTTP Response Headers)
from the business logic layer.

For now there is a crappy EventString which can be passed back to the
controller which can then handle any HTTP related concerns, although long term
these should be actual events like PostPublished or PostUpdated.
2023-06-16 09:28:19 +02:00
Fabien 'egg' O'Carroll 92172aca8e
Wired up collections to posts endpoint (#16945)
- Added support for `include=collections` to the Posts Admin API behind a flag
- Refactored some of the collections work to support it
2023-06-07 15:06:15 +02:00
Michael Barrett 59fe794b0c
Implemented duplicate post functionality (#16767)
refs: https://github.com/TryGhost/Team/issues/3139 https://github.com/TryGhost/Team/issues/3140

- Added duplicate post functionality to post list context menu
  - Currently only a single post can be duplicated at a time
  - Currently only enabled via the `Making it rain` flag
- Added admin API endpoint to copy a post - `POST ghost/api/admin/posts/<post_id>/copy/`
- Added admin API endpoint to copy a page - `POST ghost/api/admin/pages/<page_id>/copy/`
2023-05-15 09:30:32 +01:00
Simon Backx fbed93b866
🐛 Added missing history logs for post/page bulk actions (#16734)
no issue

The post/page bulk actions weren't logged in the history log / actions
table.

This change adds support for logging bulk actions.
- New `addActions` static method on models. It creates an action log in
the database for multiple models at once. If only one model was edited,
deleted or added, it will fallback to `addAction`
- `addAction` can also be called statically now
- `actionName` option is now supported when using `addActions`,
`addAction`, and as a result also in all bulk manipulation methods, and
CRUD methods. This allows you to replace the default '5 posts edited'
into something more specific like '5 posts featured'
- Fixed support for null resource_id in the parse-history-event helper
- Removed the default 'published' status requirement when using
Post.findOne for internal queries.
2023-05-05 09:45:36 +02:00
Simon Backx 1ff71dc36c Removed unused bulkRemoveTags
no issue

This bulk action is not used at the moment.
2023-04-27 14:56:54 +02:00
Simon Backx 57557cb2f7 Added E2E tests for bulk post API
refs https://github.com/TryGhost/Team/issues/2925
2023-04-27 12:45:24 +02:00
Simon Backx c4dd980421 Fixed transaction usage in bulk tag adding
refs https://github.com/TryGhost/Team/issues/2922
2023-04-13 17:47:00 +02:00
Simon Backx 788aa34c8b Added support for creating new tags when bulk editing posts
refs https://github.com/TryGhost/Team/issues/2922
2023-04-13 17:05:42 +02:00
Simon Backx 76fae2a724 Fixed unpublishing sent posts was allowed
refs https://github.com/TryGhost/Team/issues/2677
2023-04-13 16:20:58 +02:00
Fabien 'egg' O'Carroll 82393fa99d
Added bulk tag addition to post context menu
refs https://github.com/TryGhost/Team/issues/2922

Add multiple tags to multiple posts at once.

---------

Co-authored-by: Simon Backx <simon@ghost.org>
2023-04-13 16:17:36 +02:00
Simon Backx 9eb886d26d Added unpublish bulk action to posts
fixes https://github.com/TryGhost/Team/issues/2994
2023-04-12 15:28:09 +02:00
Simon Backx d4e9c23f84 Fixed select not happening inside transaction for bulk post actions
no issue

This potentially caused Knex timeout connection pool errors.
2023-04-12 12:48:17 +02:00
Simon Backx ab1ca90779
Implemented bulk editing post access (#16617)
fixes https://github.com/TryGhost/Team/issues/2924

This change adds a new bulk edit action for posts to update their
visibility. It also implements a modal to change the post access level
for multiple posts at once using this new API.

It also fixes a pattern that was used when modifying the Ember models in
memory. They previously were marked as dirty, this is fixed now. So when
going to the editor after modifying posts, you won't get a confirmation
dialog any longer.
2023-04-12 11:58:46 +02:00
Simon Backx a097f0e973 Fixed deleting email recipient failures before recipients
fixes https://github.com/TryGhost/Team/issues/2993

For the bulk destroy action of posts.
2023-04-12 11:55:18 +02:00
Simon Backx 66b353ed97
Added bulk destroy posts api (#16587)
fixes https://github.com/TryGhost/Team/issues/2921

Adds the bulk destroy API for posts, and implemented it in the admin UI.
2023-04-11 16:37:42 +02:00
renovate[bot] 07545541a8 Update @tryghost 2023-04-07 13:47:12 +02:00
Simon Backx f4d75388fd
Added post bulk edit api (#16576)
fixes https://github.com/TryGhost/Team/issues/2919

This pull request implements a new feature that allows bulk editing of
posts by a filter. It adds a new `bulkEdit` endpoint to the posts API
and new `PostsService` methods to handle the bulk actions.

The posts list component is duplicated, so we can keep working in a
copied version without affecting the old version without a flag. It
temporarily adds a star icon to indicate featured posts in the posts
list.
2023-04-07 11:48:14 +02:00
renovate[bot] 83373e1751 Update Test & linting packages 2023-04-05 15:16:08 +02:00
Daniel Lockyer b64d32cc26 Removed heavy dependency within `@tryghost/errors`
- we previously used `@stdlib/utils` instead of the child package
  `@stdlib/copy`, which is a lot smaller and contains our only use of
  the parent
- this saves 140+MB of dependencies
2023-04-05 13:46:15 +02:00
Simon Backx 0b26f09e88 Fixed exporting email only posts
refs https://github.com/TryGhost/Team/issues/2678

Default post filter was used because we didn't pass a filter.
2023-04-05 10:14:11 +02:00
Daniel Lockyer 7ec2656495 Added yarn resolution for `@tryghost/errors`
- we keep ending up with multiple versions of the depedency in our tree,
  and it's causing problems when comparing instances
- the workaround I'm implementing for now is to bump the package
  everywhere and set a resolution so we only have 1 shared instance
- hopefully we can come up with a better method down the line
2023-04-05 09:34:50 +02:00
Simon Backx d06e3dca60 Added id column to post analytics export
refs https://github.com/TryGhost/Team/issues/2678

Also fixes snapshots
2023-04-03 14:50:43 +02:00
Simon Backx 109cdeb492 Fixed exporting post metrics without email
no issue

Bookshelf by default returns an empty model when requesting .related('email') for a post without an email. So we need to be a bit smarter to know if a post has an email or not. This fixed an issue where we always showed 'published and emailed' instead of 'published only'.

Since this change also included some changes to test helpers, it also made some changes to the email service because coverage dropped below 100% as a result of fixing the .related method mocking. Ideally we want to move test test helpers to a seperate package in the future.
2023-03-28 12:41:32 +02:00
Simon Backx 7366f726e5 Removed post access copy in post exporter
no issue
2023-03-28 12:08:00 +02:00
Simon Backx 1f39040649 Added support for exportign posts with email recipients to specific tiers
no issue

Support for tiers was missing when traslating the email recipients NQL filter to a string. This is fixed now. It also improved some copy.
2023-03-28 12:06:01 +02:00