Skip to content

Commit

Permalink
membership-request [inveniosoftware#855]: remove MemberLinks template
Browse files Browse the repository at this point in the history
  • Loading branch information
fenekku committed Jul 23, 2024
1 parent 67a28b4 commit 828ff70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
31 changes: 5 additions & 26 deletions invenio_communities/members/services/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@

from invenio_records_resources.services.base.links import Link, LinksTemplate
from invenio_requests.customizations import RequestActions
from invenio_requests.proxies import current_requests_service
from invenio_requests.proxies import (
current_request_type_registry,
current_requests_service,
)
from invenio_requests.resolvers.registry import ResolverRegistry
from uritemplate import URITemplate


class MemberLinksTemplate(LinksTemplate):
"""A links template that passes the request type in the context.
This template is useful to avoid having to dereference the request type into
members at the DB-level. It's legitimate (for now), because we know what
kind of request type we are dealing with at the service search method (e.g. when
searching for invitations we know the request type of requests associated with
Members is CommunityInvitation).
"""

def __init__(self, links, context=None, request_type=None):
"""Constructor.
:param links: a dict of Links (or objects that have same interface)
:param context: dict of context values
:param request_type: a RequestType
"""
context = context or {}
context["request_type"] = request_type
super().__init__(links, context=context)


class LinksForActionsOfMember:
"""Intermediary template of links.
Expand Down Expand Up @@ -88,8 +69,8 @@ def __init__(self, obj, context):
:param context: dict of context values
"""
self.id = obj.request_id
self.type = context["request_type"]
request_relation = obj["request"]
self.type = current_request_type_registry.lookup(request_relation["type"])
self.status = request_relation["status"]
self.created_by = self._get_created_by(obj)
self.receiver = self._get_receiver(obj)
Expand Down Expand Up @@ -129,8 +110,6 @@ def _get_receiver(self, obj):
receiver_ref_type = self.type.allowed_receiver_ref_types[0]
return self._get_proxy_by_ref_type(receiver_ref_type, obj)

# assert 1 == len(self.type.allowed_topic_ref_types)

def _get_proxy_by_ref_type(self, ref_type, obj):
"""Returns proxy for given ref type.
Expand Down
9 changes: 2 additions & 7 deletions invenio_communities/members/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from ...proxies import current_roles
from ..errors import AlreadyMemberError, InvalidMemberError
from ..records.api import ArchivedInvitation
from .links import MemberLinksTemplate
from .request import CommunityInvitation, MembershipRequestRequestType
from .schemas import (
AddBulkSchema,
Expand Down Expand Up @@ -452,9 +451,7 @@ def search_invitations(
params=params,
search_preference=search_preference,
endpoint="invitations",
links_item_tpl=MemberLinksTemplate(
self.config.links_item, request_type=CommunityInvitation
),
links_item_tpl=LinksTemplate(self.config.links_item),
**kwargs
)

Expand Down Expand Up @@ -880,9 +877,7 @@ def search_membership_requests(
params=params,
search_preference=search_preference,
endpoint="membership-requests",
links_item_tpl=MemberLinksTemplate(
self.config.links_item, request_type=MembershipRequestRequestType
),
links_item_tpl=LinksTemplate(self.config.links_item),
**kwargs
)

Expand Down

0 comments on commit 828ff70

Please sign in to comment.