|
9 | 9 |
|
10 | 10 | from invenio_records_resources.services.base.links import Link, LinksTemplate
|
11 | 11 | from invenio_requests.customizations import RequestActions
|
12 |
| -from invenio_requests.proxies import current_requests_service |
| 12 | +from invenio_requests.proxies import ( |
| 13 | + current_request_type_registry, |
| 14 | + current_requests_service, |
| 15 | +) |
13 | 16 | from invenio_requests.resolvers.registry import ResolverRegistry
|
14 | 17 | from uritemplate import URITemplate
|
15 | 18 |
|
16 | 19 |
|
17 |
| -class MemberLinksTemplate(LinksTemplate): |
18 |
| - """A links template that passes the request type in the context. |
19 |
| -
|
20 |
| - This template is useful to avoid having to dereference the request type into |
21 |
| - members at the DB-level. It's legitimate (for now), because we know what |
22 |
| - kind of request type we are dealing with at the service search method (e.g. when |
23 |
| - searching for invitations we know the request type of requests associated with |
24 |
| - Members is CommunityInvitation). |
25 |
| - """ |
26 |
| - |
27 |
| - def __init__(self, links, context=None, request_type=None): |
28 |
| - """Constructor. |
29 |
| -
|
30 |
| - :param links: a dict of Links (or objects that have same interface) |
31 |
| - :param context: dict of context values |
32 |
| - :param request_type: a RequestType |
33 |
| - """ |
34 |
| - context = context or {} |
35 |
| - context["request_type"] = request_type |
36 |
| - super().__init__(links, context=context) |
37 |
| - |
38 |
| - |
39 | 20 | class LinksForActionsOfMember:
|
40 | 21 | """Intermediary template of links.
|
41 | 22 |
|
@@ -88,8 +69,8 @@ def __init__(self, obj, context):
|
88 | 69 | :param context: dict of context values
|
89 | 70 | """
|
90 | 71 | self.id = obj.request_id
|
91 |
| - self.type = context["request_type"] |
92 | 72 | request_relation = obj["request"]
|
| 73 | + self.type = current_request_type_registry.lookup(request_relation["type"]) |
93 | 74 | self.status = request_relation["status"]
|
94 | 75 | self.created_by = self._get_created_by(obj)
|
95 | 76 | self.receiver = self._get_receiver(obj)
|
@@ -129,8 +110,6 @@ def _get_receiver(self, obj):
|
129 | 110 | receiver_ref_type = self.type.allowed_receiver_ref_types[0]
|
130 | 111 | return self._get_proxy_by_ref_type(receiver_ref_type, obj)
|
131 | 112 |
|
132 |
| - # assert 1 == len(self.type.allowed_topic_ref_types) |
133 |
| - |
134 | 113 | def _get_proxy_by_ref_type(self, ref_type, obj):
|
135 | 114 | """Returns proxy for given ref type.
|
136 | 115 |
|
|
0 commit comments