Support plone.restapi's @content-types, @behaviors and @workflows services

Aperta
#116 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
12/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api, backend

Direzione di ricerca

Start from SITE_TYPE in restapi/dexterityTypes.ts, which the issue says assumes Plone Site and must detect @content-types another way. The type, behavior and workflow json tables named in the issue are the data sources. Scope is the whole endpoint table, staged in four steps, so a first contribution would be one step, not the full issue. Done means the listed endpoints respond with the documented shapes and return 404 for unknown types and workflows.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

03 type: feature

plone.restapi is getting new services for managing content types, behaviors and workflows (plone/plone.restapi#2061). The new content types control panel, @plone/controlpanels, uses them in Plone Aurora (plone/aurora#269, merged) and Volto (plone/volto#8500). Nick should support them too, so Nick sites get the whole control panel.

[!NOTE]
The plone.restapi PRs are in review, so details may still change: plone/plone.restapi#2070 (@content-types), plone/plone.restapi#2080 (@behaviors), plone/plone.restapi#2081 (@workflows and workflow changes) and plone/plone.restapi#2090 (the workflow chain). The full documentation, with example requests and responses, is in the stack's top branch: content-types.md, behaviors.md, workflows.md and types.md, and the example responses (content_types_*, behaviors_*, workflows_*, types_get_with_behaviors*).

Today

The control panel works on Nick already, through @controlpanels/dexterity-types and @types: listing, adding and deleting types, a type's title, description and allowed types, and its fields. Everything else is turned off, because those endpoints don't have it.

The services

All of them are at the site root, and need the "Plone Site Setup: Types" permission in Plone.

Method Path Result
GET /@content-types Every content type with its settings.
GET /@content-types/{type} One content type with its settings.
POST /@content-types Create a type, or copy one with copy_from.
PATCH /@content-types/{type} Change some settings of a type.
DELETE /@content-types/{type} Delete a type that has no items.
GET /@content-types/{type}/workflow The workflow of a type.
POST /@content-types/{type}/workflow Change a type's workflow, with a dry_run preview.
GET /@behaviors The behaviors, and the fields each one adds.
GET /@workflows The workflows, and the default workflow.
GET /@workflows/{id} One workflow, with its states and transitions.
POST /@workflows Change the default workflow, with a dry_run preview.
GET /@types/{type}?behaviors=a,b The type's schema with these behaviors, in this order, without changing the type.

Type IDs are URL-encoded in paths. Unknown types and workflows return 404.

@content-types

A type looks like this (shortened from content_types_get_item.resp):

{
  "@id": "http://localhost:55001/plone/@content-types/Event",
  "id": "Event",
  "title": "Event",
  "content_count": 0,
  "schema": { "fieldsets": [{ "id": "general", "title": "General", "fields": ["title", "description"] }], "properties": {}, "required": [] },
  "data": {
    "title": "Event",
    "description": "Events can be shown in calendars.",
    "global_allow": true,
    "allowed_content_types_mode": { "token": "none", "title": "No types" },
    "allowed_content_types": [],
    "searchable": true,
    "default_page": true,
    "in_navigation": true,
    "allow_discussion": false,
    "behaviors": [{ "token": "plone.dublincore", "title": "Dublin Core metadata" }],
    "versioning": { "token": "automatic", "title": "Automatic" }
  },
  "workflow": { "chain": ["simple_publication_workflow"], "follows_default": true }
}
  • content_count: the number of items of the type, including those the user can't see.

  • schema and data: the settings come as a JSON schema with fieldsets, and their values. The frontend renders the fieldsets it doesn't know, so add-ons can add their own settings to every type. Choices are { token, title }, like in control panels.

  • The core settings, by fieldset:

    Fieldset Field Value
    general title, description Not empty, and free text.
    contents global_allow Whether the type can be added inside types that allow every type.
    contents allowed_content_types_mode all, selected or none.
    contents allowed_content_types The selected type IDs. selected needs at least one, none needs none, and all keeps them for later.
    visibility searchable Whether items show in search results.
    visibility default_page Whether items can be a folder's default page.
    visibility in_navigation Whether items show in the navigation.
    comments allow_discussion Whether items allow comments. Only when comments are enabled.
    behaviors behaviors The complete, ordered list of the type's behaviors. Their order sets where their fields appear in the edit form.
    versioning versioning off, manual or automatic.
  • workflow (read-only here): chain lists the type's workflows in order, the first one setting the state, and is empty without a workflow. follows_default is true when the type uses the site's default workflow.

  • PATCH: only the fields sent change. A choice is its token or a { token } object. Every change is validated before any is stored: invalid, unknown or read-only fields return 400 with the field names and messages. behaviors replaces the whole list.

  • POST: title is required, id and description are optional (the ID comes from the title). An existing ID returns 409. copy_from copies the schema, behaviors, settings and workflow of another type.

  • DELETE: returns 409 with the number of items while the type has items. It also removes the type from the allowed types of the others.

Workflow changes

POST /@content-types/{type}/workflow takes workflow (an ID, or null for none) or follows_default: true, an optional state_map (current state → new state, "" for items without a workflow), and dry_run.

With dry_run, it changes nothing and returns the plan, which the control panel shows as a mapping step:

{
  "workflow": "intranet_workflow",
  "current": "simple_publication_workflow",
  "states": [
    { "id": "private", "count": 1, "suggested": "private" },
    { "id": "published", "count": 1, "suggested": "external" }
  ],
  "unaffected": 0
}

Without it, it assigns the workflow, moves the items to their new states (states left out of state_map get the suggested one), updates their security, and returns { "workflow", "follows_default", "changed" }.

POST /@workflows changes the default workflow the same way, with default instead of workflow. Its plan also lists the types that follow the default.

The suggested state keeps who can see the items: the most visible state of the new workflow that isn't more visible than the current one. Ties go to the state with the same ID, then the same title, then the initial state.

@workflows

The list has default (the default workflow's ID, or null) and items, each with @id, id, title, description, initial_state and the IDs of its states. GET /@workflows/{id} adds:

  • states, each with id, title, description, its transitions, permission_roles (permission → roles), and its visibility, from the roles with View: anyone (Anonymous), members (Authenticated or Member), restricted (only other roles) or unknown. The control panel colors the states with it.
  • transitions, each with id, title, description, new_state and a guard.
  • types: the types using the workflow.
@behaviors

items sorted by name, each with name, title, description and fieldsets (id, title, fields): the fields the behavior adds. The control panel shows them when adding behaviors, and searches by name. The plone.restapi.Behaviors vocabulary lists them for the behaviors setting.

For Nick

Nick has most of what this needs:

  • Types: the type table has global_allow, filter_content_types, allowed_content_types, the behaviors in schema.behaviors, and one workflow per type.
  • Behaviors: the behavior table, with each behavior's schema, so @behaviors and the preview can be built from it, with mergeSchemas.
  • Workflows: the json of each workflow has its states with roles → permissions, so visibility comes from the roles with View.
  • Jobs: @jobs could run workflow changes on large sites later. The control panel's driver already expects workflow changes as jobs, so this can come later.

Open questions:

  • The default workflow: Nick assigns one workflow to each type, and has no default workflow. Either Nick gets one, or follows_default is always false, and POST /@workflows waits.
  • The chain: Nick has one workflow per type, so chain has one item.
  • Where searchable, default_page, in_navigation, allow_discussion and versioning live: in_navigation matches displayed_types in the navigation control panel, and versioning the versioning behavior. The others may need new storage.
  • Add-on settings: in plone.restapi, each fieldset is an adapter, and add-ons register their own. Nick could let profiles contribute fieldsets.

In the frontend

@plone/controlpanels detects the services with GET /@content-types/Plone%20Site, GET /@behaviors and GET /@workflows. A 404 means a service is missing. Nick's site type is Site, so the frontend needs to detect @content-types another way, and not assume Plone Site (SITE_TYPE in restapi/dexterityTypes.ts). plone/aurora#438 makes that change: the driver reads the site root's type, and asks for /@content-types/{that type}.

Suggested order

  1. GET and PATCH /@content-types for the settings Nick already has, and POST, DELETE and copy_from.
  2. @behaviors, the ordered behaviors setting, and @types/{type}?behaviors=.
  3. @workflows, and changing a type's workflow, with dry_run.
  4. The other settings, the default workflow, and add-on fieldsets.

Assisted-by: Claude Opus 5.5

Lingua principale
TypeScript
Stelle
20
Fork
6
Merge medio
8h 30m
PR unite (30g)
43

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di plone/nick

Tutte le issue di plone/nick

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.