MDL-63401 tool_dataprivacy: Move final cap check to endpoint
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 9 Oct 2018 00:21:25 +0000 (08:21 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 9 Oct 2018 00:21:25 +0000 (08:21 +0800)
admin/tool/dataprivacy/classes/api.php
admin/tool/dataprivacy/classes/external.php
admin/tool/dataprivacy/tests/api_test.php

index ee22ee0..f626371 100644 (file)
@@ -1125,8 +1125,6 @@ class api {
     public static function set_context_defaults($contextlevel, $categoryid, $purposeid, $activity = null, $override = false) {
         global $DB;
 
-        self::check_can_manage_data_registry();
-
         // Get the class name associated with this context level.
         $classname = context_helper::get_class_for_level($contextlevel);
         list($purposevar, $categoryvar) = data_registry::var_names_from_context($classname, $activity);
index f1ecec1..3dd839e 100644 (file)
@@ -1344,6 +1344,7 @@ class external extends external_api {
         // Validate context.
         $context = context_system::instance();
         self::validate_context($context);
+        api::check_can_manage_data_registry();
 
         // Set the context defaults.
         $result = api::set_context_defaults($contextlevel, $category, $purpose, $activity, $override);
index 0f45846..3ae2f1f 100644 (file)
@@ -1418,8 +1418,6 @@ class tool_dataprivacy_api_testcase extends advanced_testcase {
      * @param bool $override Whether to override instances.
      */
     public function test_set_context_defaults($contextlevel, $inheritcategory, $inheritpurpose, $foractivity, $override) {
-        $this->setAdminUser();
-
         $this->resetAfterTest();
 
         $generator = $this->getDataGenerator();