11
11
12
12
from flask import current_app , g , render_template
13
13
from flask_login import current_user , login_required
14
+ from invenio_checks .utils import resolve_checks
14
15
from invenio_communities .config import COMMUNITIES_ROLES
15
16
from invenio_communities .members .services .request import CommunityInvitation
16
- from invenio_communities .proxies import current_communities , current_identities_cache
17
+ from invenio_communities .proxies import current_identities_cache
17
18
from invenio_communities .subcommunities .services .request import (
18
19
SubCommunityInvitationRequest ,
19
20
SubCommunityRequest ,
31
32
from invenio_requests .resolvers .registry import ResolverRegistry
32
33
from invenio_requests .views .decorators import pass_request
33
34
from invenio_users_resources .proxies import current_user_resources
34
- from sqlalchemy import case
35
35
from sqlalchemy .orm .exc import NoResultFound
36
36
37
37
from ...records_ui .utils import get_external_resources
@@ -174,72 +174,6 @@ def _resolve_record_or_draft_media_files(record, request):
174
174
return None
175
175
176
176
177
- def _resolve_checks (record_uuid , request , community = None ):
178
- """Resolve the checks for this draft/record related to the community and the request."""
179
- # FIXME: Move this logic to invenio-checks
180
-
181
- # Early exit if checks are not enabled.
182
- enabled = current_app .config .get ("CHECKS_ENABLED" , False )
183
-
184
- if not enabled :
185
- return None
186
-
187
- # Early exit if not draft submission nor record inclusion
188
- request_type = request ["type" ]
189
- is_draft_submission = request_type == CommunitySubmission .type_id
190
- is_record_inclusion = request_type == CommunityInclusion .type_id
191
-
192
- if not is_draft_submission and not is_record_inclusion :
193
- return None
194
-
195
- # Early exit if there is no record UUID (for instance for some closed requests)
196
- if not record_uuid :
197
- return None
198
-
199
- # Resolve the target community from the request if the community was not passed as an argument
200
- if not community :
201
- community_uuid = request ["receiver" ]["community" ]
202
- community = current_communities .service .read (
203
- id_ = community_uuid , identity = g .identity
204
- )
205
-
206
- # Collect the community UUID and the potential parent community UUID
207
- communities = []
208
- community_parent_id = community .to_dict ().get ("parent" , {}).get ("id" )
209
- if community_parent_id :
210
- # Add the parent community first for later ordering of check configs
211
- communities .append (community_parent_id )
212
- communities .append (community .id )
213
-
214
- # Early exit if no check config found for the communities
215
- from invenio_checks .models import CheckConfig , CheckRun
216
-
217
- check_configs = (
218
- CheckConfig .query .filter (CheckConfig .community_id .in_ (communities ))
219
- .order_by (
220
- # Order by the communities (parent first if any) and then by check IDs for deterministic ordering
221
- case ((CheckConfig .community_id == communities [0 ], 0 ), else_ = 1 ),
222
- CheckConfig .check_id ,
223
- )
224
- .all ()
225
- )
226
-
227
- if not check_configs :
228
- return None
229
-
230
- # Find check runs for the given check configs
231
- check_config_ids = [check_config .id for check_config in check_configs ]
232
- checks = CheckRun .query .filter (
233
- CheckRun .config_id .in_ (check_config_ids ),
234
- CheckRun .record_id == record_uuid ,
235
- ).all ()
236
- # For a given record, there is one check run corresponding to one check config
237
- # Order the check runs by the same order as the check configs for deterministic ordering
238
- checks = sorted (checks , key = lambda check : check_config_ids .index (check .config_id ))
239
-
240
- return checks
241
-
242
-
243
177
@login_required
244
178
@pass_request (expand = True )
245
179
def user_dashboard_request_view (request , ** kwargs ):
@@ -261,7 +195,7 @@ def user_dashboard_request_view(request, **kwargs):
261
195
record = topic ["record" ]
262
196
record_uuid = topic ["record_uuid" ]
263
197
is_draft = record_ui ["is_draft" ] if record_ui else False
264
- checks = _resolve_checks (record_uuid , request )
198
+ checks = resolve_checks (record_uuid , request )
265
199
266
200
files = _resolve_record_or_draft_files (record_ui , request )
267
201
media_files = _resolve_record_or_draft_media_files (record_ui , request )
@@ -341,7 +275,7 @@ def community_dashboard_request_view(request, community, community_ui, **kwargs)
341
275
record = topic ["record" ]
342
276
record_uuid = topic ["record_uuid" ]
343
277
is_draft = record_ui ["is_draft" ] if record_ui else False
344
- checks = _resolve_checks (record_uuid , request , community )
278
+ checks = resolve_checks (record_uuid , request , community )
345
279
346
280
permissions .update (topic ["permissions" ])
347
281
files = _resolve_record_or_draft_files (record_ui , request )
0 commit comments