# oarepo\_config.workflows.simplified

## `oarepo_config.workflows.simplified`

OARepo application workflow configuration package.

Modules:

| Name | Description |
| --- | --- |
| `base` | Base workflow settings and helpers for OARepo workflow configuration. |
| `community` | Community workflow configuration for OARepo. |
| `individual` | Individual (non-community) workflow configuration for OARepo. |
| `workflow_permissions` | Definition of workflow permissions. |

### `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.

### `add_if_in_state(states: list[str], generators: tuple[Generator, ...] | list[Generator]) -> list[Generator]`

Wrap generators in an `IfInState` constraint when states are provided.

If *states* is non-empty, returns a single-element list containing an `IfInState` generator that activates *generators* only when the record is in one of the listed states. If *states* is empty the generators are returned unchanged as a plain list.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `states` | `list[str]` | Workflow state names that gate the generators. Pass an empty list to apply the generators unconditionally. | *required* |
| `generators` | `tuple[Generator, ...] \| list[Generator]` | Permission generators to conditionally wrap. | *required* |

Returns:

| Type | Description |
| --- | --- |
| `list[Generator]` | A list of generators, optionally wrapped in an `IfInState` |
| `list[Generator]` | constraint. |

### `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.
