Skip to content

Commit

Permalink
various minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Jan 14, 2025
1 parent 56ee372 commit c51fc8d
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 43 deletions.
4 changes: 2 additions & 2 deletions oarepo_communities/cf/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def __init__(self, **kwargs: Any) -> None:


class WorkflowCF(KeywordCF):
def __init__(self, name: str, **kwargs) -> None:
def __init__(self, name: str, **kwargs: Any) -> None:
super().__init__(name, field_cls=WorkflowSchemaField, **kwargs)


# hack to get lazy choices serialized to JSON
class LazyChoices(list):
def __init__(self, func):
def __init__(self, func: callable):
self._func = func

def __iter__(self):
Expand Down
1 change: 0 additions & 1 deletion oarepo_communities/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#---
from flask import Flask
from typing import Any
from invenio_records_resources.records import Record



Expand Down
6 changes: 1 addition & 5 deletions oarepo_communities/resolvers/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ def pick_resolved_fields(self, identity: Identity, resolved_dict: dict) -> dict:


class CommunityRoleResolver(EntityResolver):
"""Community entity resolver.
The entity resolver enables Invenio-Requests to understand communities as
receiver and topic of a request.
"""
"""Community role entity resolver."""

type_id = "community_role"
"""Type identifier for this resolver."""
Expand Down
1 change: 1 addition & 0 deletions oarepo_communities/resolvers/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


class CommunityRoleUIResolver(OARepoUIResolver):
"""UI resolver for community role entity references."""
def _get_community_label(self, record: dict, reference: dict[str, str]) -> str:
if (
"metadata" not in record or "title" not in record["metadata"]
Expand Down
2 changes: 1 addition & 1 deletion oarepo_communities/resources/community_records/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class CommunityRecordsResource(RecordResource):
"""RDM community's records resource."""
"""Communities-specific records resource."""

def create_url_rules(self) -> list[dict]:
"""Create the URL rules for the record resource."""
Expand Down
2 changes: 1 addition & 1 deletion oarepo_communities/services/community_inclusion/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from oarepo_communities.errors import CommunityNotIncludedException

#---
from invenio_records_resources.records import Record
from invenio_drafts_resources.records import Record
from invenio_records_resources.services.records.service import RecordService
from invenio_records_resources.services.uow import UnitOfWork

Expand Down
9 changes: 0 additions & 9 deletions oarepo_communities/services/community_records/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#---
from typing import Any

from flask_principal import Identity
from invenio_records_resources.services.base.links import LinksTemplate
from invenio_records_resources.services.records.results import (
Expand All @@ -49,14 +48,6 @@ def community_record_schema(self) -> ServiceSchemaWrapper:
"""Returns the community schema instance."""
return ServiceSchemaWrapper(self, schema=self.config.community_record_schema)

"""
params: dict[str, Any] | None = None,
search_preference: Any | None = None,
expand: bool = False,
extra_filter: Query | None = None,
**kwargs: Any,
"""

def _search(
self,
identity: Identity,
Expand Down
2 changes: 1 addition & 1 deletion oarepo_communities/services/components/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#---
from typing import Any
from flask_principal import Identity
from invenio_records_resources.records import Record
from invenio_drafts_resources.records import Record


class CommunityInclusionComponent(ServiceComponent):
Expand Down
4 changes: 2 additions & 2 deletions oarepo_communities/services/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from uritemplate import URITemplate

#---
from invenio_records_resources.records import Record
from invenio_drafts_resources.records import Record


class CommunitiesLinks(Link):
Expand All @@ -20,7 +20,7 @@ def __init__(
self._when_func = when
self._vars_func = vars

def expand(self, obj: Record, context) -> dict:
def expand(self, obj: Record, context: dict) -> dict:
"""Expand the URI Template."""
ids = obj.parent.communities.ids
links = {}
Expand Down
24 changes: 12 additions & 12 deletions oarepo_communities/services/permissions/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#---
from typing import Any
from flask_principal import Need
from invenio_drafts_resources.records import Record as RecordWithDraft #should probably replace with drafts record where parent is expected
from invenio_drafts_resources.records import Record
from flask_principal import Identity

def _user_in_community_need(user, community):
Expand Down Expand Up @@ -59,7 +59,7 @@ def needs(self, **kwargs: Any) -> list[Need]:

class CommunityWorkflowPermission(WorkflowPermission):

def _get_workflow_id(self, record: RecordWithDraft = None, **kwargs: Any) -> str:
def _get_workflow_id(self, record: Record = None, **kwargs: Any) -> str:
# todo - check the record branch too? idk makes more sense to not use the default community's workflow, there is a deeper problem if there's no workflow on the record
try:
return super()._get_workflow_id(record=None, **kwargs)
Expand All @@ -75,7 +75,7 @@ def _get_workflow_id(self, record: RecordWithDraft = None, **kwargs: Any) -> str
raise MissingWorkflowError("Workflow not defined on record.")


def convert_community_ids_to_uuid(community_id: str) -> str:
def convert_community_ids_to_uuid(community_id: str) -> str | uuid.UUID:
# if it already is a string representation of uuid, keep it as it is
try:
uuid.UUID(community_id, version=4) #?
Expand All @@ -86,7 +86,7 @@ def convert_community_ids_to_uuid(community_id: str) -> str:


class CommunityRoleMixin:
def _get_record_communities(self, record: RecordWithDraft = None, **kwargs: Any)->list[str]:
def _get_record_communities(self, record: Record = None, **kwargs: Any)->list[str]:
try:
return record.parent.communities.ids
except AttributeError:
Expand All @@ -100,7 +100,7 @@ def _get_data_communities(self, data: dict=None, **kwargs: Any)->list[str]:


class DefaultCommunityRoleMixin:
def _get_record_communities(self, record: RecordWithDraft = None, **kwargs: Any)->list[str]:
def _get_record_communities(self, record: Record = None, **kwargs: Any)->list[str]:
try:
return [str(record.parent.communities.default.id)]
except (AttributeError, TypeError) as e:
Expand Down Expand Up @@ -134,7 +134,7 @@ def communities(self, identity: Identity)->list[str]:
return list(community_ids)

@abc.abstractmethod
def _get_record_communities(self, record: RecordWithDraft=None, **kwargs: Any) -> list[str]:
def _get_record_communities(self, record: Record=None, **kwargs: Any) -> list[str]:
raise NotImplementedError()

@abc.abstractmethod
Expand All @@ -145,7 +145,7 @@ def _get_data_communities(self, data: dict = None, **kwargs: Any) -> list[str]:
def roles(self, **kwargs: Any)->list[str]:
raise NotImplementedError()

def needs(self, record: RecordWithDraft=None, data:dict=None, **kwargs:Any) -> list[Need]:
def needs(self, record: Record=None, data:dict=None, **kwargs:Any) -> list[Need]:
"""Set of Needs granting permission."""
if record:
community_ids = self._get_record_communities(record)
Expand Down Expand Up @@ -251,14 +251,14 @@ def query_filter_field(self)->str:
class RecordOwnerInDefaultRecordCommunity(DefaultCommunityRoleMixin, Generator):
default_or_ids = "default"

def _record_communities(self, record: RecordWithDraft=None, **kwargs: Any) -> set[str]:
def _record_communities(self, record: Record=None, **kwargs: Any) -> set[str]:
return set(self._get_record_communities(record, **kwargs))

def needs(self, record: RecordWithDraft=None, data:dict=None, **kwargs:Any) -> list[Need]:
def needs(self, record: Record=None, data:dict=None, **kwargs:Any) -> list[Need]:
record_communities = set(self._get_record_communities(record, **kwargs))
return self._needs(record_communities, record=record)

def _needs(self, record_communities: set[str], record: RecordWithDraft = None) -> list[Need]:
def _needs(self, record_communities: set[str], record: Record = None) -> list[Need]:
owners = getattr(record.parent, "owners", None)
ret = []
for owner in owners:
Expand Down Expand Up @@ -298,9 +298,9 @@ class RecordOwnerInRecordCommunity(
default_or_ids = "ids"

# trick to use CommunityRoleMixin instead of DefaultCommunityRoleMixin
def _record_communities(self, record: RecordWithDraft=None, **kwargs: Any) -> set[str]:
def _record_communities(self, record: Record=None, **kwargs: Any) -> set[str]:
return set(self._get_record_communities(record, **kwargs))

def needs(self, record: RecordWithDraft=None, data:dict=None, **kwargs:Any) -> list[Need]:
def needs(self, record: Record=None, data:dict=None, **kwargs:Any) -> list[Need]:
record_communities = set(self._get_record_communities(record, **kwargs))
return self._needs(record_communities, record=record)
9 changes: 8 additions & 1 deletion tests/test_communities/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from oarepo_communities.services.permissions.policy import (
CommunityDefaultWorkflowPermissions,
)
from tests.test_communities.utils import link2testclient
from deepmerge import always_merger

pytest_plugins = [
Expand All @@ -59,6 +58,14 @@
"pytest_oarepo.users",
]

@pytest.fixture(autouse=True)
def init_cf(init_cf):
return init_cf

@pytest.fixture(scope="module", autouse=True)
def location(location):
return location

@pytest.fixture()
def urls():
return {"BASE_URL": "/thesis/", "BASE_URL_REQUESTS": "/requests/"}
Expand Down
3 changes: 1 addition & 2 deletions tests/test_communities/test_community_requests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest
from pytest_oarepo.functions import link2testclient

from oarepo_communities.errors import (
CommunityAlreadyIncludedException,
CommunityNotIncludedException,
PrimaryCommunityException,
)

from .utils import link2testclient

REPO_NAME = "thesis"


Expand Down
2 changes: 1 addition & 1 deletion tests/test_communities/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from invenio_communities.communities.records.api import Community
from invenio_communities.proxies import current_communities
from invenio_users_resources.proxies import current_users_service
from tests.test_communities.utils import link2testclient
from pytest_oarepo.functions import link2testclient


def test_disabled_endpoints(
Expand Down
5 changes: 0 additions & 5 deletions tests/test_communities/utils.py

This file was deleted.

0 comments on commit c51fc8d

Please sign in to comment.