diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3417990..3375403 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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: diff --git a/oarepo_communities/resolvers/ui.py b/oarepo_communities/resolvers/ui.py index fab8f3b..a69ef79 100644 --- a/oarepo_communities/resolvers/ui.py +++ b/oarepo_communities/resolvers/ui.py @@ -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): @@ -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: @@ -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), + ) \ No newline at end of file diff --git a/oarepo_communities/services/permissions/generators.py b/oarepo_communities/services/permissions/generators.py index 95def84..16be710 100644 --- a/oarepo_communities/services/permissions/generators.py +++ b/oarepo_communities/services/permissions/generators.py @@ -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 ( @@ -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 = ( diff --git a/oarepo_communities/services/permissions/policy.py b/oarepo_communities/services/permissions/policy.py index 757a825..e5c1ca1 100644 --- a/oarepo_communities/services/permissions/policy.py +++ b/oarepo_communities/services/permissions/policy.py @@ -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, @@ -29,6 +29,6 @@ class MyWorkflowPermissions(CommunityDefaultWorkflowPermissions): ] -class CommunityWorkflowPermissionPolicy(WorkflowPermissionPolicy): +class CommunityWorkflowPermissionPolicy(WorkflowRecordPermissionPolicy): can_create = [CommunityWorkflowPermission("create")] can_view_deposit_page = [InAnyCommunity(CommunityWorkflowPermission("create"))] diff --git a/oarepo_communities/worklows/permissive_workflow.py b/oarepo_communities/worklows/permissive_workflow.py index b745375..3de3f39 100644 --- a/oarepo_communities/worklows/permissive_workflow.py +++ b/oarepo_communities/worklows/permissive_workflow.py @@ -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 diff --git a/setup.cfg b/setup.cfg index d4e1bc1..1baa07b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-communities -version = 5.0.24 +version = 5.1.0 description = authors = Ronald Krist readme = README.md