oarepo-runtime 1.5.22__py3-none-any.whl → 1.5.24__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- oarepo_runtime/records/__init__.py +16 -0
- oarepo_runtime/records/entity_resolvers/__init__.py +78 -2
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.24.dist-info}/METADATA +1 -1
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.24.dist-info}/RECORD +8 -8
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.24.dist-info}/LICENSE +0 -0
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.24.dist-info}/WHEEL +0 -0
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.24.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.22.dist-info → oarepo_runtime-1.5.24.dist-info}/top_level.txt +0 -0
@@ -9,3 +9,19 @@ def select_record_for_update(record_cls: Type[Record], persistent_identifier):
|
|
9
9
|
model_id = resolved_record.model.id
|
10
10
|
obj = record_cls.model_cls.query.filter_by(id=model_id).with_for_update().one()
|
11
11
|
return record_cls(obj.data, model=obj)
|
12
|
+
|
13
|
+
|
14
|
+
def is_record(record, ctx):
|
15
|
+
"""Shortcut for links to determine if record is a record."""
|
16
|
+
if not getattr(record, "is_draft", False):
|
17
|
+
return True
|
18
|
+
return not record.is_draft
|
19
|
+
|
20
|
+
|
21
|
+
def has_draft(record, ctx):
|
22
|
+
"""Shortcut for links to determine if record is a draft or a published one with a draft associated."""
|
23
|
+
if getattr(record, "is_draft", False):
|
24
|
+
return True
|
25
|
+
if getattr(record, 'has_draft', False):
|
26
|
+
return True
|
27
|
+
return False
|
@@ -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"]
|
@@ -42,11 +42,11 @@ oarepo_runtime/datastreams/writers/yaml.py,sha256=XchUJHQ58E2Mfgs8elImXbL38jFtI8
|
|
42
42
|
oarepo_runtime/i18n/__init__.py,sha256=G4PJ_kQlPDiBW6ntjQZ-O4qHQgkJWAXsNLUuOBcglNM,402
|
43
43
|
oarepo_runtime/info/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
44
|
oarepo_runtime/info/views.py,sha256=jtI2JJBdApuT5ZIxU2kskJBz6GpJVTgUGrM8EMNIiAk,11137
|
45
|
-
oarepo_runtime/records/__init__.py,sha256=
|
45
|
+
oarepo_runtime/records/__init__.py,sha256=3pTrYyhlDJ8-vnOcrEIqZGzBu9T65RuvS26OjJsdJ80,906
|
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.24.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
118
|
+
oarepo_runtime-1.5.24.dist-info/METADATA,sha256=108JUE4jNX8zWgn68ddFuCEqRS9_-uMSulGE7tEc0KE,4680
|
119
|
+
oarepo_runtime-1.5.24.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
120
|
+
oarepo_runtime-1.5.24.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
|
121
|
+
oarepo_runtime-1.5.24.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
122
|
+
oarepo_runtime-1.5.24.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|