oarepo-runtime 1.5.22__py3-none-any.whl → 1.5.23__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- oarepo_runtime/records/entity_resolvers/__init__.py +78 -2
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.23.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.23.dist-info}/RECORD +7 -7
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.23.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.23.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.23.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.23.dist-info}/top_level.txt +0 -0
@@ -7,8 +7,84 @@ from oarepo_runtime.records.entity_resolvers.proxies import DraftProxy
|
|
7
7
|
if oarepo_version.split(".")[0] == "11":
|
8
8
|
from invenio_records_resources.references import EntityResolver, RecordResolver
|
9
9
|
from invenio_users_resources.resolvers import UserResolver
|
10
|
+
|
11
|
+
#copyied from newer invenio_users_resources, GroupResolver isn't in older versions
|
12
|
+
from flask_principal import RoleNeed
|
13
|
+
from invenio_accounts.models import Role
|
14
|
+
from invenio_records_resources.references.resolvers import (
|
15
|
+
EntityProxy,
|
16
|
+
EntityResolver,
|
17
|
+
)
|
18
|
+
from invenio_users_resources.services.groups.config import GroupsServiceConfig
|
19
|
+
from sqlalchemy.exc import NoResultFound
|
20
|
+
|
21
|
+
class GroupProxy(EntityProxy):
|
22
|
+
"""Resolver proxy for a Role entity."""
|
23
|
+
|
24
|
+
def _resolve(self):
|
25
|
+
"""Resolve the User from the proxy's reference dict, or system_identity."""
|
26
|
+
# Resolves to role name, not id
|
27
|
+
role_id = self._parse_ref_dict_id()
|
28
|
+
try:
|
29
|
+
return Role.query.filter(
|
30
|
+
Role.name == role_id # TODO to be changed to role id
|
31
|
+
).one()
|
32
|
+
except NoResultFound:
|
33
|
+
return {}
|
34
|
+
|
35
|
+
def pick_resolved_fields(self, identity, resolved_dict):
|
36
|
+
"""Select which fields to return when resolving the reference."""
|
37
|
+
serialized_role = {}
|
38
|
+
|
39
|
+
return serialized_role
|
40
|
+
|
41
|
+
def get_needs(self, ctx=None):
|
42
|
+
"""Return needs based on the given roles."""
|
43
|
+
role_id = self._parse_ref_dict_id()
|
44
|
+
return [RoleNeed(role_id)]
|
45
|
+
|
46
|
+
def ghost_record(self, value):
|
47
|
+
"""Return default representation of not resolved group.
|
48
|
+
|
49
|
+
.. note::
|
50
|
+
|
51
|
+
Only groups that are not indexed should need this. Non-indexed groups include groups that were not created by users
|
52
|
+
e.g. user-moderation.
|
53
|
+
"""
|
54
|
+
return {}
|
55
|
+
|
56
|
+
|
57
|
+
class GroupResolver(EntityResolver):
|
58
|
+
"""Group entity resolver."""
|
59
|
+
|
60
|
+
type_id = "group"
|
61
|
+
"""Type identifier for this resolver."""
|
62
|
+
|
63
|
+
def __init__(self):
|
64
|
+
"""Constructor."""
|
65
|
+
# There's a bit of a mixup of type_key and type_id. Base resolver has no
|
66
|
+
# type_key, but RecordResolvers have.
|
67
|
+
self.type_key = self.type_id
|
68
|
+
super().__init__(GroupsServiceConfig.service_id)
|
69
|
+
|
70
|
+
def matches_reference_dict(self, ref_dict):
|
71
|
+
"""Check if the reference dict references a role."""
|
72
|
+
return self._parse_ref_dict_type(ref_dict) == self.type_id
|
73
|
+
|
74
|
+
def _reference_entity(self, entity):
|
75
|
+
"""Create a reference dict for the given user."""
|
76
|
+
return {"group": str(entity.id)}
|
77
|
+
|
78
|
+
def matches_entity(self, entity):
|
79
|
+
"""Check if the entity is a Role."""
|
80
|
+
return isinstance(entity, Role)
|
81
|
+
|
82
|
+
def _get_entity_proxy(self, ref_dict):
|
83
|
+
"""Return a GroupProxy for the given reference dict."""
|
84
|
+
return GroupProxy(self, ref_dict)
|
85
|
+
|
10
86
|
else:
|
11
87
|
from invenio_records_resources.references import EntityResolver, RecordResolver
|
12
|
-
from invenio_users_resources.entity_resolvers import UserResolver
|
88
|
+
from invenio_users_resources.entity_resolvers import UserResolver, GroupResolver
|
13
89
|
|
14
|
-
__all__ = ["DraftProxy", "UserResolver", "RecordResolver", "EntityResolver"]
|
90
|
+
__all__ = ["DraftProxy", "UserResolver", "GroupResolver", "RecordResolver", "EntityResolver"]
|
@@ -46,7 +46,7 @@ oarepo_runtime/records/__init__.py,sha256=Bxm2XNtB9j6iOAKGSVsjXTKIZS-iXKPzakCqyN
|
|
46
46
|
oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
|
47
47
|
oarepo_runtime/records/dumpers/edtf_interval.py,sha256=YCShZAoqBQYaxVilEVotS-jXZsxxoXO67yu2urhkaMA,1198
|
48
48
|
oarepo_runtime/records/dumpers/multilingual_dumper.py,sha256=PbNFCLsiH4XV3E1v8xga_fzlcEImHy8OXn_UKh_8VBU,1090
|
49
|
-
oarepo_runtime/records/entity_resolvers/__init__.py,sha256=
|
49
|
+
oarepo_runtime/records/entity_resolvers/__init__.py,sha256=QvGxjfDRCg21eD5zDjWf0TSGFotEYG1PydrjT2wG7DY,3465
|
50
50
|
oarepo_runtime/records/entity_resolvers/proxies.py,sha256=hHUzJA1yDhp7nM35gHoAAv7w4zWuaSE-tLBNvIR0tD8,882
|
51
51
|
oarepo_runtime/records/owners/__init__.py,sha256=R4hudCBqLRRzgCnkEjXIL7hSp068z-s6YOwYSkWyuaw,93
|
52
52
|
oarepo_runtime/records/owners/registry.py,sha256=fYgBuW5nBKn6pyz2OBgfNlynk64_yhQ9J7FzPk8QU1U,795
|
@@ -114,9 +114,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
114
114
|
oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
|
115
115
|
oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
|
116
116
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
117
|
-
oarepo_runtime-1.5.
|
118
|
-
oarepo_runtime-1.5.
|
119
|
-
oarepo_runtime-1.5.
|
120
|
-
oarepo_runtime-1.5.
|
121
|
-
oarepo_runtime-1.5.
|
122
|
-
oarepo_runtime-1.5.
|
117
|
+
oarepo_runtime-1.5.23.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
118
|
+
oarepo_runtime-1.5.23.dist-info/METADATA,sha256=JLABtcMnZtHXdB-EmREq34LgYDAxJq5cswfxaz9YJ8w,4680
|
119
|
+
oarepo_runtime-1.5.23.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
120
|
+
oarepo_runtime-1.5.23.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
|
121
|
+
oarepo_runtime-1.5.23.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
122
|
+
oarepo_runtime-1.5.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|