Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0 # We need the full history to determine the source branch
fetch-depth: 0 # Fetch all branches so the version bump can be pushed to the target branch
- name: Setup Node.js
uses: actions/setup-node@v7
with:
Expand Down Expand Up @@ -37,12 +37,21 @@ jobs:
echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
echo "NPM_TAG=latest" >> $GITHUB_OUTPUT
fi
- name: Get source branch
- name: Get target branch
id: get_branch
env:
TARGET: ${{ github.event.release.target_commitish }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
RELEASE_COMMIT=$(git rev-list -n 1 ${{ steps.get_version.outputs.VERSION }})
SOURCE_BRANCH=$(git branch -r --contains $RELEASE_COMMIT | grep -v HEAD | head -n 1 | sed 's/.*origin\///')
echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> $GITHUB_OUTPUT
# Push the version bump to the branch the release targets. If the release targets a
# commit SHA instead of a branch, fall back to the default branch.
if git show-ref --verify --quiet "refs/remotes/origin/$TARGET"; then
TARGET_BRANCH="$TARGET"
else
TARGET_BRANCH="$DEFAULT_BRANCH"
fi
echo "Pushing version bump to $TARGET_BRANCH"
echo "TARGET_BRANCH=$TARGET_BRANCH" >> $GITHUB_OUTPUT
- name: Set package version
run: npm version "${{ steps.get_version.outputs.VERSION }}" --no-git-tag-version
- name: Publish package
Expand All @@ -54,4 +63,4 @@ jobs:
with:
commit_message: 'chore: Bump version to ${{ steps.get_version.outputs.VERSION }}'
file_pattern: 'package.json'
branch: ${{ steps.get_branch.outputs.SOURCE_BRANCH }}
branch: ${{ steps.get_branch.outputs.TARGET_BRANCH }}
13 changes: 10 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Use **Yarn 4** (`.yarn/releases`, `nodeLinker: node-modules`; a global Yarn 1 de
- `yarn playground:strapi <cmd>` — run any Strapi CLI command in the playground
- `yarn verify` — `strapi-plugin verify`: checks the built package before publishing
- `yarn consumer-test --dir <empty folder outside the repo> [--strapi minimum|current|<version>] [--clean] [--tarball <tgz>]` — packs the plugin, creates a fresh Strapi app with its own npm-installed `node_modules` (plugin from the tarball, playground config/content types, `npm install --before` = 7-day cooldown) and runs the smoke test against it; catches packaging, undeclared-dependency and Strapi-version issues the playground can't
- `yarn playground:smoke [--skip-build] [--app <dir>]` — end-to-end smoke test (needs `yarn build`): builds the playground admin, starts it on port 1339 with its own DB (`playground/.tmp/smoke-test.db`) and admin, schedules publish/unpublish actions for Article and Homepage and asserts they run, are removed and call all four hooks
- `yarn playground:smoke [--skip-build] [--app <dir>]` — end-to-end smoke test (needs `yarn build`; `playground/scripts/smoke-test/`, Node's built-in `node:test`): builds the playground admin, starts it once on port 1339 with its own DB (`playground/.tmp/smoke-test.db`) and admin, then runs `tests/endpoints.js`, `tests/scheduling.js` (publish/unpublish actions for Article and Homepage run, are removed and call all four hooks) and `tests/permissions.js` (issue #212: a user without publish permission gets 403s and a filtered list; a non-super-admin who may publish articles can manage article actions but not homepage actions). Shared helpers live in `lib/` (`config`, `app` = build/start/stop, `client` = HTTP, `fixtures`). Test files are required from `index.js` instead of run with `node --test`, so Strapi starts only once. Run part of it with `node --test-reporter=spec --test-name-pattern="Permissions" playground/scripts/smoke-test`

There is no unit test suite. CI (`.github/workflows/ci.yml`) runs `yarn install --immutable`, lint, build, `verify`, `npm pack`, the playground smoke test and the consumer test (Node 20 + Strapi minimum, Node 24 + Strapi current) on every PR. The publish workflow uses `npm version`/`npm publish` (Yarn 4 has no `yarn publish`).

Expand All @@ -29,7 +29,13 @@ Only use dependency versions published at least 7 days ago. Yarn enforces this d

## Playground

`playground/` is a minimal Strapi app (Article collection type + Homepage single type, both draft & publish, seeded with drafts and an auto-created super admin in `playground/src/index.js`). Article has a **required** manyToOne `author` relation to the Author collection type (no draft & publish); keep it required, it is the regression coverage for scheduling entries with a filled required to-one relation.
`playground/` is a small Strapi app with realistic content, seeded as drafts (plus an auto-created super admin) in `playground/src/index.js`. All of it is draft & publish except Author and Category:
- **Article** (collection type): a **required** manyToOne relation to Author, a manyToMany relation to Categories, a required `shared.seo` component and a `blocks` dynamic zone. Keep `author` required: it is the regression coverage for scheduling entries with a filled required to-one relation (#240). The seeded "Incomplete article" is missing required fields (author, SEO), so scheduling it to be published shows validation errors.
- **Homepage** (single type): a required `blocks.hero` component (with a nested `shared.link`), a `sections` dynamic zone and SEO.
- **Page** (collection type, i18n `en` + `nl`): localized SEO, sections and a repeatable FAQ component. The seed creates the `nl` locale, two pages in both locales and "Nieuws" in `nl` only. Use it to test locale-restricted publish permissions.
- **Author** and **Category**: relation targets without draft & publish.
- Components live in `playground/src/components/{shared,blocks}`. `blocks.media` has a required media field, to test media validation.
- The seed only runs on an empty database; run `yarn playground:reset` after changing it.

- Its dependencies live in the **root** `package.json`; never run `yarn install` inside `playground/` (plugin and app must share one copy of Strapi/React).
- `playground/config/plugins.js` loads the plugin via `resolve:` an absolute path to the repo root, so Strapi uses the root `exports` → **`dist/`**, not the source. Changes only take effect after `strapi-plugin watch` rebuilds.
Expand All @@ -43,7 +49,7 @@ Two halves, each built by `@strapi/sdk-plugin` from the entry points in `package
### Server: how a scheduled action flows

1. **Storage** — Each schedule is an `action` document (`server/content-types/action-content-type`, table `actions`, hidden from Content Manager/CTB) with `executeAt`, `mode` (`publish` | `unpublish`), `entityId` (target `documentId`), `entitySlug` (target UID).
2. **API** — Admin and content-api routes both expose CRUD on `/actions` using the core controller (`factories.createCoreController`). Admin also has `GET /settings` returning the plugin config (used by the admin UI for `contentTypes` whitelist and date picker options).
2. **API** — Admin and content-api routes both expose CRUD on `/actions` using the core controller (`factories.createCoreController`). Content-api access is managed by Users & Permissions / API tokens. Admin routes are open to every admin user, so they are restricted to the user's Content Manager permissions on the target content type (issue #212): the policy `plugin::publisher.can-manage-action` (`server/policies`) requires **publish** permission (incl. conditions and the action's locale) for POST/PUT/DELETE, and the route middleware `plugin::publisher.limit-to-readable-content-types` limits GET to content types the user can read. Both use `permissionService`. Admin also has `GET /settings` returning the plugin config (used by the admin UI for `contentTypes` whitelist and date picker options).
3. **Validation before scheduling** — `server/register.js` registers a **Document Service middleware** (`server/middlewares/validate-before-scheduling.js`). On create/update of a `publish` action it loads the target draft (deep-populated) and runs Strapi's entity validator plus a custom required-media/relation/component/dynamic-zone check, throwing a `ValidationError` so the admin can show field errors *at scheduling time* rather than failing silently later.
4. **Scheduling** — `server/services/action-service.js` extends the core service: `create`/`update`/`delete` add/replace/remove a one-off `strapi.cron` job named `publisherAction_<documentId>` that fires at `executeAt`. On boot, `server/config/cron-tasks.js` (called from `bootstrap`, deferred with `setImmediate`) loads all actions, immediately executes overdue ones, and schedules future ones. The `actions.syncFrequency` config option is still in the defaults/schema but is no longer used by this per-action mechanism.
5. **Execution** — `publicationService.toggle(record, mode)` compares published vs draft versions (publishes if never published or draft is newer; unpublishes if published), then **deletes the action**. `publish`/`unpublish` call the user's `before*` hooks (returning `false` aborts), use `strapi.documents(uid).publish/unpublish`, optionally overwrite `publishedAt` with `executeAt` via `strapi.db.query`, emit `entry.publish`/`entry.unpublish` on the eventHub (`emitService`, so webhooks fire), then call `after*` hooks. Errors are logged, not thrown.
Expand All @@ -65,3 +71,4 @@ Multi-instance deployments will execute the same action on every node (issue #19
- Conventional Commits (`feat:`, `fix:`, `refactor:`, `docs:`, `chore:`).
- Releases: publishing a GitHub release triggers `.github/workflows/npm-publish.yml`, which builds, sets `package.json` version from the tag (pre-release suffix → npm dist-tag), publishes, and commits the version bump back. Don't bump the version manually in PRs.
- When changing plugin config options, update both `server/config/index.js` (defaults) and `server/config/schema.js` (yup validator), plus the README config table.
- `@strapi/utils` is an **optional** peer dependency (`peerDependenciesMeta`) on purpose. As a required peer, npm installs the newest `@strapi/utils` at the app root while Strapi keeps its own exact-pinned nested copies, so errors the plugin throws (`errors.PolicyError`, `ValidationError`, …) are not `instanceof` Strapi's `ApplicationError` and become 500s (seen in the consumer test with Strapi minimum). Don't remove it from `peerDependencies` either: `strapi-plugin build` only keeps declared (peer) dependencies external and would bundle a private copy into `dist/`.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ Once the plugin has been installed, configured and enabled a `Publisher` section

> If the Publisher section does not appear in the admin after the plugin is enabled then a clean rebuild of the admin is required. This can be done by deleting the generated `.cache` and `build` folders and then re-running the `develop` command.

### Permissions

Scheduling, editing and deleting a (un)publish date requires the same permission as publishing directly: the Content Manager `Publish` permission for that content type (including its conditions and locales) on the user's role. Users without it can't manage scheduled dates through the admin API either, and only see the scheduled dates of content types they are allowed to read.

The Content API routes (`/api/publisher/actions`) are not affected by this; access to them is managed with the Users & Permissions plugin or API token permissions.

### Single Content Type

![Sample single content type publisher section](https://github.com/PluginPal/strapi-plugin-publisher/blob/master/assets/single.png?raw=true)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"playground:strapi": "cd playground && strapi",
"playground:reset": "node -e \"require('fs').rmSync('playground/.tmp', { recursive: true, force: true })\"",
"check:lockfile-age": "node scripts/check-lockfile-age.js",
"playground:smoke": "node playground/scripts/smoke-test.js",
"playground:smoke": "node --test-reporter=spec playground/scripts/smoke-test",
"consumer-test": "node scripts/consumer-test.js"
},
"exports": {
Expand Down Expand Up @@ -92,6 +92,11 @@
"react-router-dom": "^6.0.0",
"styled-components": "^6.0.0"
},
"peerDependenciesMeta": {
"@strapi/utils": {
"optional": true
}
},
"strapi": {
"displayName": "Publisher",
"name": "publisher",
Expand Down
Binary file added playground/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading