@@ -41,27 +41,63 @@ def is_it_an_xloader_format(cls, format_):
41
41
return format_ .lower () in cls ._formats
42
42
43
43
44
+ def awaiting_validation (res_dict ):
45
+ """
46
+ Checks the existence of a logic action from the ckanext-validation
47
+ plugin, thus supporting any extending of the Validation Plugin class.
48
+
49
+ Checks ckanext.xloader.validation.requiredSoWaitForReport config
50
+ option value.
51
+
52
+ Checks ckanext.xloader.validation.enforceDefaultsIfSchemaMissing config
53
+ option value. Then checks the Resource's Schema for the `validation_status` field.
54
+ """
55
+ try :
56
+ p .toolkit .get_action ('resource_validation_show' )
57
+ is_validation_plugin_loaded = True
58
+ except KeyError :
59
+ is_validation_plugin_loaded = False
60
+
61
+ if not is_validation_plugin_loaded or \
62
+ not p .toolkit .asbool (p .toolkit .config .get ('ckanext.xloader.validation.requiredSoWaitForReport' , False )):
63
+ # the validation plugin is not loaded or the validation.requiredSoWaitForReport is turned off
64
+ return False
65
+
66
+ if p .toolkit .asbool (p .toolkit .config .get ('ckanext.xloader.validation.enforceDefaultsIfSchemaMissing' , True )):
67
+ # validation.enforceDefaultsIfSchemaMissing is turned on, so we will expect Resources to have `validation_status`
68
+ if res_dict .get ('validation_status' , None ) != 'success' :
69
+ return True
70
+ else :
71
+ return False
72
+ else :
73
+ # TODO: check the Resource's schema to see if there is no `validation_status`,
74
+ # if there is not, then return False, otherwise check if it is `success` or not.
75
+ return True
76
+
77
+ return True
78
+
79
+
44
80
def resource_data (id , resource_id , rows = None ):
45
81
46
82
if p .toolkit .request .method == "POST" :
47
- if is_validation_plugin_loaded () and \
48
- p .toolkit .asbool (p .toolkit .config .get ('ckanext.xloader.requires_validation' )):
49
-
50
- context = {
51
- "ignore_auth" : True ,
52
- }
53
- resource_dict = p .toolkit .get_action ("resource_show" )(
54
- context ,
55
- {
56
- "id" : resource_id ,
57
- },
83
+
84
+ context = {
85
+ "ignore_auth" : True ,
86
+ }
87
+ resource_dict = p .toolkit .get_action ("resource_show" )(
88
+ context ,
89
+ {
90
+ "id" : resource_id ,
91
+ },
92
+ )
93
+
94
+ if awaiting_validation (resource_dict ):
95
+ h .flash_error (_ ("Cannot upload resource %s to the DataStore "
96
+ "because the resource did not pass validation yet." ) % resource_id )
97
+ return p .toolkit .redirect_to (
98
+ "xloader.resource_data" , id = id , resource_id = resource_id
58
99
)
59
- if resource_dict .get ('validation_status' , None ) != 'success' :
60
- h .flash_error (_ ("Cannot upload resource %s to the DataStore "
61
- "because the resource did not pass validation yet." ) % resource_id )
62
- return p .toolkit .redirect_to (
63
- "xloader.resource_data" , id = id , resource_id = resource_id
64
- )
100
+
65
101
try :
66
102
p .toolkit .get_action ("xloader_submit" )(
67
103
None ,
@@ -274,15 +310,3 @@ def datastore_resource_exists(resource_id):
274
310
except p .toolkit .ObjectNotFound :
275
311
return False
276
312
return response or {'fields' : []}
277
-
278
-
279
- def is_validation_plugin_loaded ():
280
- """
281
- Checks the existence of a logic action from the ckanext-validation
282
- plugin, thus supporting any extending of the Validation Plugin class.
283
- """
284
- try :
285
- p .toolkit .get_action ('resource_validation_show' )
286
- return True
287
- except KeyError :
288
- return False
0 commit comments