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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ More: [permissions](https://github.com/WireCatLabs/wordpress-cli/blob/main/docs/

- Only self-hosted WordPress with application passwords. WordPress.com sites, which sign in with OAuth, are not
supported. Sign-in through the browser is not there yet: you paste the password.
- An Author or Contributor gets only part of the site. WordPress refuses the pages list to both, so the posts sync
stays partial and changes on the site do not reach the copy. A Contributor also sees only their own posts. Only an
Administrator gets the users list. Sign in as an Administrator for a full copy.
- An Author or Contributor gets only their own posts, and no pages: WordPress refuses the pages list to both, and the
sync says so. A Contributor gets only their drafts and posts waiting for review. For both, a post that leaves their
view stays in the copy as it was: one deleted for good, or a Contributor's post an editor published. Only an Administrator gets the users list. Sign in as an Administrator for a full
copy.
- No view counts. WordPress itself keeps none, and Jetpack stats are not supported.
- A post with galleries, columns, embeds or iframes keeps its body: `posts update` changes its title, excerpt, tags
and status only, unless you add `--replace-body`.
Expand Down
5 changes: 5 additions & 0 deletions changes/fix-content-roles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Fixed

- **An Author or Contributor sign-in syncs their own posts again.** WordPress refuses both roles the pages list, and
that refusal stopped the whole sync of posts: after the first run, changes on the site no longer reached the copy.
The sync now skips the pages for a role without the right to edit pages, says so in its gaps, and copies the posts.
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ password.

- Only self-hosted WordPress with application passwords. WordPress.com sites are not supported.
- You paste the application password. Sign-in through the browser is on the [roadmap](roadmap.md).
- An Author or Contributor gets only part of the site. WordPress refuses the pages list to both, so the posts sync
stays partial and changes on the site do not reach the copy. A Contributor also sees only their own posts. Only an
Administrator gets the users list. Sync reports each of these as a gap.
- An Author or Contributor gets only their own posts, and no pages: WordPress refuses the pages list to both. A
Contributor gets only their drafts and posts waiting for review. For both, a post that leaves their view stays in
the copy as it was: one deleted for good, or a Contributor's post an editor published. Only an Administrator gets the users list. Sync reports each of these as a gap.
- No view counts. WordPress itself keeps none, and Jetpack stats are not supported. `posts stats` shows only what the
copy has.
- Plugin fields, such as those of SEO or custom field plugins, have no flags. The `api` group sends them in a raw
Expand Down
2 changes: 0 additions & 2 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ and trash a post, each with its own permission. `wordpress blog api` reaches eve

## Next

- **Full sync for Authors and Contributors.** Copy what an Author or Contributor may read, without stopping at the
pages list.
- **Sign in with the browser.** Approve the tool in wp-admin, in place of pasting an application password.
- **Plugin fields.** Read and set common plugin fields, such as an SEO title, without a raw `--body`.

Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ wordpress blog session status --check # asks your site whose password it is
| No **Application Passwords** section in your profile | The site needs WordPress 5.7 or later over https, and a plugin or the host may turn the section off. Ask the site's admin. |
| A WordPress.com address | WordPress.com sites are not supported, only self-hosted WordPress. |
| `posts list` is empty | Run `wordpress blog sync` first. Posts are read from the copy it makes. |
| `sync` ends partial, or pages are missing | An Author or Contributor sign-in cannot list pages, and a Contributor sees only their own posts. Only an Administrator lists the users. Sign in as an Administrator for a full copy, or as an Editor for every post and page. |
| A change on the site is missing from the copy | Run `sync`. If it still ends partial, see the row above. |
| `sync` names gaps, or pages are missing | An Author or Contributor sign-in cannot list pages and gets only their own posts; a Contributor only their drafts and posts waiting for review. Only an Administrator lists the users. Sign in as an Administrator for a full copy, or as an Editor for every post and page. |
| A change on the site is missing from the copy | Run `sync`. If the post is not yours and you sign in as an Author or Contributor, see the row above. |
| `content.conflict` | The post changed on the site since the last sync. Run `sync`, look at the post again, then retry. |
| `content.lossy-body` | The post has galleries, columns, embeds or iframes that Markdown cannot keep. Change only its title, excerpt, tags or status, or add `--replace-body` to write the body anyway and flatten them. See [when a write stops](usage.md#when-a-write-stops). |
| `content.schedule-past` | `--at-time` must be ahead of now. |
Expand Down
10 changes: 6 additions & 4 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ tags and categories, and the users who write. A post's text is kept as Markdown.
Later syncs ask WordPress only for posts changed since then. Once a day a sync also finds the posts the site deleted
for good. A post in the trash stays in the copy, with its status.

A sync can end partial and still succeed: it names each gap. With an Author or Contributor sign-in, WordPress
refuses the pages list, so the posts stay partial and changes on the site do not reach the copy. A Contributor also
sees only their own posts. Only an Administrator gets the users list, so an Editor's copy has every post and page but
no users. Sign in as an Administrator for a full copy.
A sync names each gap: what your WordPress role may not read. With an Author or Contributor sign-in, the sync copies
your own posts and skips the pages, as WordPress refuses the pages list to both. A Contributor gets only their drafts
and posts waiting for review. For both, each sync reads all of your posts again, not only the changes, and a post
that leaves your view stays in the copy as it was: one deleted for good, or a Contributor's post an editor published.
Only an Administrator gets the users list, so an Editor's copy has every post and page but no users. Sign in as an
Administrator for a full copy.

`--max-pages` caps the requests in one run. The next sync goes on from where it stopped.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"dependencies": {
"@wirecat/cli-base": "0.124.0",
"@wirecat/cli-core": "0.707.0",
"@wirecat/cli-core": "0.710.0",
"commander": "15.0.0",
"valibot": "1.5.0"
},
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions skills/wordpress-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ unless the task says.
`type:page`, `tag:<id>`, `author:<id>`, `published:` with a time, `>=`, or `[a TO b]`.
- **Ids are strings.** Pass them back unchanged.
- **Missing is not absent.** A sync can be partial and still exit `0`: read `complete` and its gaps. An Author or
Contributor sign-in cannot list pages, a Contributor sees only their own posts, and only an Administrator lists the
users. Say so when it matters, and do not claim a post is not there.
Contributor sign-in gets only their own posts and no pages, and only an Administrator lists the users. Say so when
it matters, and do not claim a post is not there.
- **No view counts.** WordPress keeps none. `posts stats` holds only what the store has.

## Write and publish
Expand Down
72 changes: 72 additions & 0 deletions src/content-contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,75 @@ it("sync before session start says to sign in, and sends nothing", async () => {
expect(unsigned.json()).toMatchObject({ error: { code: "authentication_error" } })
expect(sent).toEqual([])
})

// A call a role may not make names its right in `optional.needs`: a sign-in without it never sends the call (the fake
// would list it in `refusals`), and the sync ends complete with that gap.
type Needs = { check: string; message: string }
const needs = Object.values(SOURCE.entities as Record<string, { optional?: { needs?: Needs } }[]>)
.flat()
.flatMap((entity) => (entity.optional?.needs ? [entity.optional.needs] : []))

if (needs.length)
it("a sign-in without a call's right skips that call, says so, and the sync completes", async () => {
const keyring = memoryKeyring()
// A store of its own: the file's other tests sync every call's rows into the shared one.
const env = { MESSAGING_STORE: join(mkdtempSync(join(tmpdir(), "content-needs-")), "store.db") }
const started = await runCli(["personal", "session", "start", "--site", FAKE_SITE, "--login", login, "--json"], {
keyring,
service: fakeServiceApi(),
stdin: password,
})
expect(started.code, started.err).toBe(0)
const fake = contentManifestFake(SOURCE, { api: API.manifest, lacks: needs.map((one) => one.check) })
fakes.push(fake)
const synced = await runCli(["personal", "sync", "--json"], { keyring, service: fake, env })
expect(synced.code, synced.err).toBe(0)
const report = synced.json().item as { state: string; gaps: { message: string }[] }
expect(report.state).toBe("complete")
expect(report.gaps.map((one) => one.message)).toEqual(expect.arrayContaining(needs.map((one) => one.message)))
})

// What WordPress 6.9.4 gives each role (checked on a local site): no right to edit others' posts or any page, and no
// users list. The pages list with a private status is refused to both, HTTP 400 with 403 in its details.
const ROLES = {
author: ["edit_others_posts", "edit_pages", "edit_others_pages"],
contributor: ["edit_others_posts", "edit_pages", "edit_others_pages"],
}

for (const [role, rights] of Object.entries(ROLES))
it(`${role === "author" ? "An Author" : "A Contributor"} syncs their posts, never asks for the pages, and gets later edits`, async () => {
const keyring = memoryKeyring()
// A store of its own: the file's other tests sync pages into the shared one.
const env = { MESSAGING_STORE: join(mkdtempSync(join(tmpdir(), "content-role-")), "store.db") }
const started = await runCli(["personal", "session", "start", "--site", FAKE_SITE, "--login", login, "--json"], {
keyring,
service: fakeServiceApi(),
stdin: password,
})
expect(started.code, started.err).toBe(0)
const fake = contentManifestFake(SOURCE, {
api: API.manifest,
lacks: rights.map((one) => `capabilities.${one}`),
denied: ["getWpV2Users"],
})
fakes.push(fake)
const sync = async () => {
const synced = await runCli(["personal", "sync", "--json"], { keyring, service: fake, env })
expect(synced.code, synced.err).toBe(0)
return synced.json().item as { state: string; gaps: { scope?: string; message: string }[] }
}
const first = await sync()
expect(first.state).toBe("complete")
expect(first.gaps.find((one) => one.scope === "edit_pages")?.message).toBe(
"only an editor or administrator reads the pages",
)
const [posts] = fake.rows.post ?? []
const post = posts?.[0] as { id: number; title: { raw: string } }
post.title = { raw: "Edited on the site" }
fake.touch("post", String(post.id))
expect((await sync()).state).toBe("complete")
const listed = await runCli(["personal", "posts", "list", "--json"], { keyring, service: fake, env })
const items = (listed.json() as { items: { external_id: string; type: string; title: string }[] }).items
expect(items.map((one) => one.type)).not.toContain("page")
expect(items.find((one) => one.external_id === String(post.id))?.title).toBe("Edited on the site")
})
18 changes: 14 additions & 4 deletions src/generated/wirecat-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const SOURCE: Readonly<Record<string, unknown>> & {
},
},
optional: {
message: "the sign-in may not read every post or page: an author or a contributor reads only some",
message: "the sign-in may not read every post: an author or a contributor reads only their own",
scope: "edit_others_posts",
requires: {
operation: "getWpV2UsersMe",
Expand Down Expand Up @@ -275,15 +275,25 @@ export const SOURCE: Readonly<Record<string, unknown>> & {
},
},
optional: {
message: "the sign-in may not read every post or page: an author or a contributor reads only some",
scope: "edit_others_posts",
message: "the sign-in may not read every page",
scope: "edit_others_pages",
requires: {
operation: "getWpV2UsersMe",
query: {
context: "edit",
_fields: "capabilities",
},
check: "capabilities.edit_others_posts",
check: "capabilities.edit_others_pages",
},
needs: {
operation: "getWpV2UsersMe",
query: {
context: "edit",
_fields: "capabilities",
},
check: "capabilities.edit_pages",
message: "only an editor or administrator reads the pages",
scope: "edit_pages",
},
},
},
Expand Down
29 changes: 20 additions & 9 deletions wirecat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineCli } from "@wirecat/cli-core/manifest"

// WordPress's posts and pages: every status, sorted by id to list and by change time to sync.
const STATUSES = "publish,future,draft,pending,private,trash"
const ME = { operation: "getWpV2UsersMe", query: { context: "edit", _fields: "capabilities" } }
const posts = (operation: string, type: "post" | "page") => {
const list = { operation, query: { context: "edit", status: STATUSES, per_page: 100, orderby: "id", order: "asc" } }
return {
Expand Down Expand Up @@ -44,15 +45,25 @@ const posts = (operation: string, type: "post" | "page") => {
format: "wp-blocks" as const,
fallback: { path: "content.rendered", format: "html" as const },
},
optional: {
message: "the sign-in may not read every post or page: an author or a contributor reads only some",
scope: "edit_others_posts",
requires: {
operation: "getWpV2UsersMe",
query: { context: "edit", _fields: "capabilities" },
check: "capabilities.edit_others_posts",
},
},
optional:
type === "post"
? {
message: "the sign-in may not read every post: an author or a contributor reads only their own",
scope: "edit_others_posts",
requires: { ...ME, check: "capabilities.edit_others_posts" },
}
: {
message: "the sign-in may not read every page",
scope: "edit_others_pages",
requires: { ...ME, check: "capabilities.edit_others_pages" },
// WordPress refuses an author or a contributor pages with a private status (HTTP 400, 403 inside).
needs: {
...ME,
check: "capabilities.edit_pages",
message: "only an editor or administrator reads the pages",
scope: "edit_pages",
},
},
}
}

Expand Down
Loading