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
6 changes: 6 additions & 0 deletions changes/fix-wordpress-content-roles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Fixed

- **A content CLI made from a config syncs an Author's or Contributor's posts.** The WordPress case gives the pages
call `optional.needs` on `capabilities.edit_pages` (cli-core 0.710.0): WordPress refuses both roles the pages list,
and that refusal failed the whole post sync. Pages now check `edit_others_pages`, not `edit_others_posts`. A
content CLI's seed tests that a sign-in without a call's right never sends it and still completes its sync.
1 change: 1 addition & 0 deletions contracts/help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Works with:
pbx Asterisk PBX calls and recordings, searchable with your other WireCat data
notion Notion pages and databases as local text, searchable with your other WireCat data
ydisk Yandex Disk folders as local text, searchable with your other WireCat data
wordpress WordPress posts and pages, searchable with your other WireCat data

Next: clidev commands every command, by section
clidev help options output, offline, timeouts, dry run
Expand Down
27 changes: 27 additions & 0 deletions kit/seeds/config/src/content-contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,30 @@ 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)))
})
29 changes: 20 additions & 9 deletions kit/test/from-config/wordpress/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: a contributor sees its own",
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},
"dependencies": {
"@wirecat/cli-base": "0.123.0",
"@wirecat/cli-core": "0.707.0",
"@wirecat/cli-core": "0.710.0",
"commander": "15.0.0",
"valibot": "1.5.0",
"yaml": "2.9.1"
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.

Loading