Skip to content

Commit

Permalink
MDL-62370 core_privacy: Directory-less subsystems are compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 14, 2018
1 parent ab65b87 commit 502344a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions admin/tool/dataprivacy/classes/metadata_registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function get_registry_metadata() {
if (isset($metadata[$component])) {
$collection = $metadata[$component]->get_collection();
$internaldata = $this->format_metadata($collection, $component, $internaldata);
} else if ($manager->is_empty_subsystem($component)) {
// This is an unused subsystem.
// Use the generic string.
$internaldata['nullprovider'] = get_string('privacy:subsystem:empty', 'core_privacy');
} else {
// Call get_reason for null provider.
$internaldata['nullprovider'] = get_string($manager->get_null_provider_reason($component), $component);
Expand Down
1 change: 1 addition & 0 deletions lang/en/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
*/

$string['privacy:metadata'] = 'The privacy subsystem does not store any data of its own and is designed to act as a channel between components and the interface used to describe, export, and remove their data.';
$string['privacy:subsystem:empty'] = 'This subsystem does not store any data.';
23 changes: 23 additions & 0 deletions privacy/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ public function component_is_compliant(string $component) : bool {
if ($this->component_implements($component, \core_privacy\local\metadata\null_provider::class)) {
return true;
}

if (static::is_empty_subsystem($component)) {
return true;
}

// Components which store user data must implement the local\metadata\provider and the local\request\data_provider.
if ($this->component_implements($component, \core_privacy\local\metadata\provider::class) &&
$this->component_implements($component, \core_privacy\local\request\data_provider::class)) {
return true;
}

return false;
}

Expand All @@ -145,6 +151,23 @@ public function get_null_provider_reason(string $component) : string {
}
}

/**
* Return whether this is an 'empty' subsystem - that is, a subsystem without a directory.
*
* @param string $component Frankenstyle component name.
* @return string The key to retrieve the language string for the null provider reason.
*/
public static function is_empty_subsystem($component) {
if (strpos($component, 'core_') === 0) {
if (null === \core_component::get_subsystem_directory(substr($component, 5))) {
// This is a subsystem without a directory.
return true;
}
}

return false;
}

/**
* Get the privacy metadata for all components.
*
Expand Down
73 changes: 73 additions & 0 deletions privacy/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,38 @@ public function test_component_is_compliant() {
$this->assertFalse($mockman->component_is_compliant('tool_thisisnotarealtool123'));
}

/**
* Provider for component_is_compliant tests.
*
* @return array
*/
public function component_is_compliant_provider() {
return [
'An empty subsystem' => [
'core_countries',
true,
],
'A real subsystem' => [
'core_privacy',
true,
],
];
}

/**
* Test verifying the output of component_is_compliant with specified
* components.
*
* @dataProvider component_is_compliant_provider
* @param string $component
* @param boolean $expected
*/
public function test_component_is_compliant_examples($component, $expected) {
$manager = new \core_privacy\manager();

$this->assertEquals($expected, $manager->component_is_compliant($component));
}

/**
* Test verifying only approved contextlists can be used with the export_user_data method.
*/
Expand Down Expand Up @@ -227,4 +259,45 @@ public function test_plugintype_class_callback() {
public function test_component_class_callback() {
\core_privacy\manager::component_class_callback('foo_bar', 'unusable', 'foo', ['bar']);
}

/**
* Test the manager::is_empty_subsystem function.
*
* @dataProvider is_empty_subsystem_provider
* @param string $component
* @param bool $expected
*/
public function test_is_empty_subsystem($component, $expected) {
$this->assertEquals($expected, \core_privacy\manager::is_empty_subsystem($component));
}

/**
* Test cases for the is_empty_subsystem function.
*
* @return array
*/
public function is_empty_subsystem_provider() {
return [
'A subsystem which has no directory' => [
'core_langconfig',
true,
],
'A subsystem with a directory' => [
'core_portfolio',
false,
],
'A plugin' => [
'mod_forum',
false,
],
'A plugintype' => [
'mod',
false,
],
'An unprefixed subsystem with no directory' => [
'langconfig',
false,
],
];
}
}

0 comments on commit 502344a

Please sign in to comment.