Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Jul 22, 2024
1 parent be9f9cf commit 0025685
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 24 deletions.
17 changes: 14 additions & 3 deletions oarepo_workflows/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from .permissions import IfInState, WorkflowPermission, DefaultWorkflowPermissionPolicy, WorkflowPermissionPolicy
from .requests import WorkflowRequestPolicy, WorkflowRequest, WorkflowTransitions, RecipientGeneratorMixin, AutoRequest, AutoApprove
from .base import Workflow

from .permissions import (
DefaultWorkflowPermissionPolicy,
IfInState,
WorkflowPermission,
WorkflowPermissionPolicy,
)
from .requests import (
AutoApprove,
AutoRequest,
RecipientGeneratorMixin,
WorkflowRequest,
WorkflowRequestPolicy,
WorkflowTransitions,
)

__all__ = (
'IfInState',
Expand Down
1 change: 1 addition & 0 deletions oarepo_workflows/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dataclasses
from typing import Type

from flask_babel import LazyString

from .permissions import DefaultWorkflowPermissionPolicy
Expand Down
4 changes: 2 additions & 2 deletions oarepo_workflows/permissions/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from invenio_search.engine import dsl

from oarepo_workflows.proxies import current_oarepo_workflows
from oarepo_workflows.utils import get_workflow_from_record, get_from_requests_workflow
from oarepo_workflows.utils import get_from_requests_workflow, get_workflow_from_record


class WorkflowPermission(Generator):
Expand Down Expand Up @@ -40,7 +40,7 @@ def _get_generators(self, record, **kwargs):

def needs(self, record=None, **kwargs):
generators = self._get_generators(record, **kwargs)
# todo ui record is RecordItem, it doesn't have state and owners on parent - either do ui serialization of those or resolve them
# todo ui record is RecordItem, it doesn't have state and owners on parent - either do ui serialization of those or resolve them - made a change into oarepo-ui for this
needs = [
g.needs(
record=record,
Expand Down
9 changes: 8 additions & 1 deletion oarepo_workflows/requests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .policy import WorkflowRequestPolicy, WorkflowRequest, WorkflowTransitions, RecipientGeneratorMixin, AutoRequest, AutoApprove
from .policy import (
AutoApprove,
AutoRequest,
RecipientGeneratorMixin,
WorkflowRequest,
WorkflowRequestPolicy,
WorkflowTransitions,
)

__all__ = (
'WorkflowRequestPolicy',
Expand Down
11 changes: 5 additions & 6 deletions oarepo_workflows/requests/policy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import List, Tuple, Optional
import dataclasses
from invenio_records_permissions.generators import Generator
from typing import List, Optional, Tuple

from invenio_access.permissions import SystemRoleNeed
from invenio_records_permissions.generators import Generator


@dataclasses.dataclass
Expand Down Expand Up @@ -84,6 +85,8 @@ def reference_receivers(self, record=None, request_type=None, **kwargs):

auto_request_need = SystemRoleNeed("auto_request")
auto_approve_need = SystemRoleNeed("auto_approve")


class AutoRequest(Generator):
"""
Auto request generator. This generator is used to automatically create a request
Expand All @@ -94,10 +97,6 @@ def needs(self, **kwargs):
return [auto_request_need]






class AutoApprove(RecipientGeneratorMixin, Generator):
"""
Auto approve generator. If the generator is used within recipients of a request,
Expand Down
1 change: 1 addition & 0 deletions oarepo_workflows/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from itertools import chain

from oarepo_workflows.proxies import current_oarepo_workflows


Expand Down
23 changes: 15 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

import pytest
import yaml
from flask_principal import ActionNeed
from flask_security import login_user
from invenio_accounts.testutils import login_user_via_session
from invenio_app.factory import create_api
from invenio_i18n import lazy_gettext as _
from invenio_records_permissions.generators import AuthenticatedUser, SystemProcess, Generator
from invenio_records_permissions.generators import (
AuthenticatedUser,
Generator,
SystemProcess,
)
from invenio_users_resources.records import UserAggregate
from oarepo_runtime.services.generators import RecordOwners
from oarepo_workflows import Workflow

from oarepo_workflows.permissions import IfInState, DefaultWorkflowPermissionPolicy
from oarepo_workflows.requests import WorkflowRequestPolicy, WorkflowRequest, WorkflowTransitions

from flask_principal import ActionNeed
from oarepo_workflows import Workflow
from oarepo_workflows.permissions import DefaultWorkflowPermissionPolicy, IfInState
from oarepo_workflows.requests import (
WorkflowRequest,
WorkflowRequestPolicy,
WorkflowTransitions,
)

# tests should not depend on specified default configuration

Expand Down Expand Up @@ -71,11 +78,11 @@ class MyWorkflowRequests(WorkflowRequestPolicy):

@pytest.fixture
def mappings():
from thesis.records.api import ThesisDraft, ThesisRecord

# update the mappings
from oarepo_runtime.services.custom_fields.mappings import prepare_cf_indices

from thesis.records.api import ThesisDraft, ThesisRecord

prepare_cf_indices()
ThesisDraft.index.refresh()
ThesisRecord.index.refresh()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask_security import logout_user

from thesis.resources.records.config import ThesisResourceConfig
from thesis.thesis.records.api import ThesisRecord, ThesisDraft
from thesis.thesis.records.api import ThesisDraft, ThesisRecord


def test_workflow_read(users, logged_client, search_clear):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_workflow_requests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from invenio_access.permissions import system_identity
from oarepo_workflows.requests import WorkflowRequest, RecipientGeneratorMixin
from oarepo_runtime.services.generators import RecordOwners
from invenio_records_permissions.generators import Generator
from oarepo_runtime.services.generators import RecordOwners

from oarepo_workflows.requests import RecipientGeneratorMixin, WorkflowRequest
from thesis.thesis.records.api import ThesisRecord


Expand Down

0 comments on commit 0025685

Please sign in to comment.