Skip to content

Commit

Permalink
Merge pull request #88 from oarepo/miroslavsimek/be-545-move-autoappr…
Browse files Browse the repository at this point in the history
…ove-to-oarepo-workflows

Incorporated changes from next oarepo-workflows and oarepo-requests
  • Loading branch information
mesemus authored Nov 22, 2024
2 parents 294bb70 + 3f6637a commit 97bac46
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: Cache pip
uses: actions/cache@v4
with:
Expand Down
36 changes: 23 additions & 13 deletions oarepo_communities/resolvers/ui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from __future__ import annotations


from typing import TYPE_CHECKING

from invenio_communities.proxies import current_communities, current_roles
from invenio_records_resources.resources.errors import PermissionDeniedError
from invenio_requests.resolvers.registry import ResolverRegistry
from oarepo_requests.resolvers.ui import OARepoUIResolver, fallback_label_result
from oarepo_requests.resolvers.ui import OARepoUIResolver, fallback_label_result, UIResolvedReference
from oarepo_runtime.i18n import gettext as _

if TYPE_CHECKING:
from oarepo_requests.typing import EntityReference

class CommunityRoleUIResolver(OARepoUIResolver):
def _get_community_label(self, record, reference):
Expand Down Expand Up @@ -39,7 +46,8 @@ def _search_many(self, identity, values, *args, **kwargs):
actual_results.append(actual_result)
return actual_results

def _search_one(self, identity, reference, *args, **kwargs):
def _search_one(self, identity, _id, *args, **kwargs):
reference = {self.reference_type: _id}
proxy = ResolverRegistry.resolve_entity_proxy(reference)
community_id, role = proxy._parse_ref_dict()
try:
Expand All @@ -48,17 +56,19 @@ def _search_one(self, identity, reference, *args, **kwargs):
return None
return {"community": community, "role": role}

def _resolve(self, record, reference):
# the 'record' here is dict with community object and role string
community_record = record["community"]
def _get_entity_ui_representation(
self, entity: dict, reference: EntityReference
) -> UIResolvedReference:

community_record = entity["community"]
community_label = self._get_community_label(community_record, reference)
role_label = self._get_role_label(record["role"])
ret = {
"reference": reference,
"type": "community role",
"label": _(
role_label = self._get_role_label(entity["role"])

return UIResolvedReference(
reference = reference,
type = "community role",
label = _(
"%(role)s of %(community)s", role=role_label, community=community_label
),
"links": self._resolve_links(community_record),
}
return ret
links = self._extract_links_from_resolved_reference(community_record),
)
13 changes: 8 additions & 5 deletions oarepo_communities/services/permissions/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from invenio_records_permissions.generators import Generator
from invenio_search.engine import dsl
from oarepo_workflows.errors import MissingWorkflowError
from oarepo_workflows.requests.policy import RecipientGeneratorMixin
from oarepo_workflows.requests import RecipientGeneratorMixin
from oarepo_workflows.services.permissions.generators import WorkflowPermission

from oarepo_communities.errors import (
Expand Down Expand Up @@ -99,10 +99,13 @@ class DefaultCommunityRoleMixin:
def _get_record_communities(self, record=None, **kwargs):
try:
return [str(record.parent.communities.default.id)]
except AttributeError:
raise MissingDefaultCommunityError(
f"Default community missing on record {record}."
)
except (AttributeError, TypeError) as e:
try:
return [str(record['parent']['communities']['default'])]
except KeyError:
raise MissingDefaultCommunityError(
f"Default community missing on record {record}."
)

def _get_data_communities(self, data=None, **kwargs):
community_id = (
Expand Down
4 changes: 2 additions & 2 deletions oarepo_communities/services/permissions/policy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from oarepo_requests.services.permissions.workflow_policies import (
RequestBasedWorkflowPermissions,
)
from oarepo_workflows.services.permissions.policy import WorkflowPermissionPolicy
from oarepo_workflows import WorkflowRecordPermissionPolicy

from oarepo_communities.services.permissions.generators import (
CommunityWorkflowPermission,
Expand Down Expand Up @@ -29,6 +29,6 @@ class MyWorkflowPermissions(CommunityDefaultWorkflowPermissions):
]


class CommunityWorkflowPermissionPolicy(WorkflowPermissionPolicy):
class CommunityWorkflowPermissionPolicy(WorkflowRecordPermissionPolicy):
can_create = [CommunityWorkflowPermission("create")]
can_view_deposit_page = [InAnyCommunity(CommunityWorkflowPermission("create"))]
2 changes: 1 addition & 1 deletion oarepo_communities/worklows/permissive_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from oarepo_runtime.services.permissions.generators import RecordOwners
from oarepo_workflows import (
AutoApprove,
DefaultWorkflowPermissions,
IfInState,
Workflow,
WorkflowRequest,
WorkflowRequestPolicy,
WorkflowTransitions,
)
from oarepo_workflows.services.permissions import DefaultWorkflowPermissions

from oarepo_communities.services.permissions.generators import PrimaryCommunityMembers

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-communities
version = 5.0.24
version = 5.1.0
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 97bac46

Please sign in to comment.