# oarepo\_config.workflows

## `oarepo_config.workflows`

Configuration for workflows.

Modules:

| Name | Description |
| --- | --- |
| `low_level` | Configuration for workflows. |
| `simplified` | OARepo application workflow configuration package. |

### `BaseWorkflowSettings`

Shared configuration common to all workflow types.

#### `code: str = 'undefined'`

The code of the workflow type.

#### `label: LazyString = _('Undefined policy')`

The label of the workflow type.

#### `base_permission_policy: type[Any] = DefaultRDMWorkflowPermissions`

The base permission policy class for this workflow that will be configured.

#### `base_request_policy: type[WorkflowRequestPolicy] = WorkflowRequestPolicy`

The base requests policy class for this workflow that will be configured.

#### `review_request_states: list[str] = dataclasses.field(default_factory=lambda: ['draft'])`

Record workflow states in which a review request may be submitted.

#### `record_view_permissions: dict[str, list[Generator]] = dataclasses.field(default_factory=dict)`

View permissions for records in this workflow.

It is a dictionary, the key is record state and the value is a list of generators.

#### `publish_after_review: bool = True`

Publish immediately after reviewer approves the review request.

#### `extra_permissions: type[BasePermissionPolicy] | Callable[[type[BasePermissionPolicy]], type[BasePermissionPolicy]] | None = None`

Extra permissions to apply to the record permission policy.

If a callable is provided, it will be called with the generated permission policy as an argument and should return a modified permission policy. If a class is provided, it will be used as a mixin for the generated permission policy.

#### `extra_requests: type[WorkflowRequestPolicy] | Callable[[type[WorkflowRequestPolicy]], type[WorkflowRequestPolicy]] | None = None`

Extra requests to apply to the workflow request policy.

If a callable is provided, it will be called with the generated request policy as an argument and should return a modified request policy. If a class is provided, it will be used as a mixin for the generated request policy.

#### `authenticated_draft_creation: bool = False`

Allow authenticated users to create draft records.

When enabled and no role- or need-based restrictions are configured, any authenticated user may create a draft. Subclasses may override this default (e.g. `IndividualWorkflow` sets it to `True`).

#### `draft_creation_roles: list[str] = dataclasses.field(default_factory=list)`

Restrict draft creation to users who hold at least one of these site-wide roles.

When non-empty, takes priority over `authenticated_draft_creation`.

#### `draft_creation_needs: list[str] = dataclasses.field(default_factory=list)`

Restrict draft creation to users who hold at least one of these permission needs.

When non-empty, takes priority over `authenticated_draft_creation`.

#### `build_workflow() -> Workflow`

Build and return the workflow instance.

### `CommunityWorkflow`

Bases: `BaseWorkflowSettings`

Workflow configuration for deposits inside communities.

#### `draft_creation_community_roles: list[str] = dataclasses.field(default_factory=lambda: ['submitter', 'curator', 'owner'])`

Restrict draft creation to community members with at least one of these roles.

If not specified (empty list), any member of the community can create a draft. Used in addition to the site-wide `draft_creation_roles` / `draft_creation_needs` restrictions.

#### `read_restricted_community_roles: list[str] = dataclasses.field(default_factory=lambda: ['curator', 'owner'])`

Community roles that may read restricted (published) records without requesting access.

If empty, only the record owner can read the content after publishing. By default allowing curators and community owners to access restricted records.

> [!NOTE]
>
> Community roles are used instead of `RecordCommunitiesAction` so that each workflow can have independent read/draft/manage permissions.

#### `read_draft_community_roles: list[str] = dataclasses.field(default_factory=list)`

Community roles that may read draft records without requesting access.

If empty, only the record owner can read the content of a draft. Curators can always read draft records when the record is submitted for review.

> [!NOTE]
>
> Community roles are used instead of `RecordCommunitiesAction` so that each workflow can have independent read/draft/manage permissions.

#### `record_manage_community_roles: list[str] = dataclasses.field(default_factory=lambda: ['curator', 'owner'])`

Community roles that may manage (edit, delete, publish) records.

If empty, only the record owner can manage the record. By default allowing curators and community owners to manage all records.

> [!NOTE]
>
> Community roles are used instead of `RecordCommunitiesAction` so that each workflow can have independent read/draft/manage permissions.

#### `community_curator_roles: list[str] = dataclasses.field(default_factory=lambda: ['curator'])`

Community roles that allow users to review and curate records.

### `IndividualWorkflow`

Bases: `BaseWorkflowSettings`

Workflow configuration for deposits outside of communities.

#### `code: str = 'individual'`

Unique code identifier for this workflow.

#### `label: LazyString = _('Individual Submission Workflow')`

Human-readable label for this workflow.

#### `authenticated_draft_creation: bool = True`

Allow authenticated users to create drafts in this workflow.

Overrides the base-class default of `False`; any authenticated user can create a draft unless more-specific role or need restrictions are configured via `draft_creation_roles` or `draft_creation_needs`.

#### `publish_without_review: bool = False`

Allow draft owners to publish without submitting a review request.

When enabled, draft owners can publish directly, subject to `publish_without_review_states`.

#### `publish_without_review_roles: list[str] = dataclasses.field(default_factory=list)`

Roles that allow a draft owner to publish without a review request.

Users must still be owners of the draft record. If the list is non-empty, `publish_without_review` is ignored.

#### `publish_without_review_needs: list[str] = dataclasses.field(default_factory=list)`

Permission needs that allow a draft owner to publish without a review request.

Users must still be owners of the draft record. If the list is non-empty, `publish_without_review` is ignored.

#### `publish_without_review_states: list[str] = dataclasses.field(default_factory=lambda: ['draft'])`

Record workflow states in which publication without review is allowed.

#### `review_required: bool = False`

Require a review request before publication.

If `publish_without_review` is `False` and `review_required` is `False`, records can only be published through a community workflow.

#### `reviewer_roles: list[str] = dataclasses.field(default_factory=list)`

Roles that allow users to review and curate records.

Users with these roles are also granted read access to draft records.

#### `reviewer_needs: list[str] = dataclasses.field(default_factory=list)`

Permission needs that allow users to review and curate records.

Users with these needs are also granted read access to draft records.

#### `self_review_enabled: bool = False`

Allow the record owner to approve their own review request.

Normally, submitting a record for review prevents the owner from approving it themselves. When set to `True`, the review request is still created on submission, but the owner is permitted to accept it.

This is primarily useful when `invenio-checks` is active: checks are tied to an open request, so the request must exist even when no external reviewer is needed. With this option the owner can see and act on the check results without waiting for a curator.

Has no effect when `publish_without_review` is `True`, because in that case user can bypass the review request and publish the record directly.

#### `record_owners_with_correct_roles(record_owner_generator: RecordOwners) -> list[Generator]`

Return the record owner generator with the correct roles/needs.

### `register_workflow(workflow_code: str, workflow_name: str | LazyString, permissions_policy: str | type, requests_policy: str | type, use_low_level_workflows: bool = False) -> None`

Register a submission/review workflow that records can go through.

A workflow defines the path a record takes from being created to being published - for example, who may create it, whether it needs review/approval before publishing, and who may perform each of those steps. This adds one such workflow to the repository, so that it can be selected when configuring where records may be submitted (e.g. a community).

This is a low-level, single-workflow building block. Repositories that use the community-based workflow shape provided by the `oarepo_app` package typically use its higher-level `configure_workflows(IndividualWorkflow(...), CommunityWorkflow(...))` helper instead - see this package's README for the difference.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `workflow_code` | `str` | A short, unique identifier for the workflow, e.g. `"default"`. | *required* |
| `workflow_name` | `str \| LazyString` | The human-readable name of the workflow, shown to users, e.g. `_("Default workflow")`. | *required* |
| `permissions_policy` | `str \| type` | Who is allowed to do what with records that use this workflow (create, edit, delete, publish, ...). Pass either a permissions policy class or its import path as a string. | *required* |
| `requests_policy` | `str \| type` | What review/approval requests are available for records using this workflow (e.g. a publish request that needs a curator's approval). Pass either a request policy class or its import path as a string. | *required* |
| `use_low_level_workflows` | `bool` | Set to `True` to silence the warning recommending [`configure_workflows`](<https://oarepo.github.io/oarepo-config/reference/index.html#oarepo_config.configure_workflows> "configure_workflows(*workflow_definitions: BaseWorkflowSettings, default_individual_workflow: str = 'individual', default_community_workflow: str = 'community', context: dict \| None = None) -> list[Workflow]") instead, for the (uncommon) cases that genuinely need this low-level, single-workflow API. | `False` |

Requires the optional `oarepo_workflows` (and, for its defaults, `oarepo_requests`) package to be installed.

Invenio configuration variables set:

- `WORKFLOWS` - the new workflow is appended; workflows already registered (by earlier calls) are kept.
- `REQUESTS_PERMISSION_POLICY` - only if not already set by an earlier call; defaults to `oarepo_config.requests.RequestsPermissionPolicy` (workflow-based, plus creation of community-topic request types).

> [!NOTE]
>
> **Example**
>
> ```
> from oarepo_workflows.services.permissions import (
>     DefaultWorkflowPermissions,
> )
> from oarepo_requests.services.permissions.workflow_policies import (
>     CreatorsFromWorkflowRequestsPermissionPolicy,
> )
>
> config.register_workflow(
>     workflow_code="default",
>     workflow_name=_("Default workflow"),
>     permissions_policy=DefaultWorkflowPermissions,
>     requests_policy=CreatorsFromWorkflowRequestsPermissionPolicy,
> )
> ```

### `configure_workflows(*workflow_definitions: BaseWorkflowSettings, default_individual_workflow: str = 'individual', default_community_workflow: str = 'community', context: dict | None = None) -> list[Workflow]`

Set up workflows based on the provided workflow definitions.

This function is intended to be called from within invenio.cfg and will create a "WORKFLOWS" entry in the invenio.cfg context (in the caller's globals).

> [!NOTE]
>
> **Example**
>
> ```
> # invenio.cfg
> from oarepo_app.config import (
>     configure_workflows,
>     IndividualWorkflow,
>     CommunityWorkflow,
> )
>
> configure_workflows(
>     IndividualWorkflow(
>         authenticated_draft_creation=False,
>         review_required=True,
>         publish_without_review=False,
>     ),
>     CommunityWorkflow(),
> )
> # no need to assign the result to WORKFLOWS, that is done automatically
> ```

If the workflow definitions are empty, a permissive IndividualWorkflow will be created (authenticated draft creation, publish without review allowed).

If there is no IndividualWorkflow definition in the workflow definitions (but there are other workflow types), a restricted IndividualWorkflow (no deposition allowed) will be created with default settings.

The default\_individual\_workflow parameter should be the code of the workflow to use as the default one for individual deposits, where no community is involved and the workflow code is not provided by the caller.

If the context is provided, the "WORKFLOWS" entry will be added to it instead of the caller's globals.

See https://nrp-cz.github.io/docs/customize/workflows for more information on how to customize the workflows.
