Skip to content

Commit 289fe1e

Browse files
committed
MDL-61307 core_privacy: Define and test providers
1 parent 1d58d59 commit 289fe1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5940
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* This file defines the core_privacy\local\metadata\collection class object.
19+
*
20+
* The collection class is used to organize a collection of types
21+
* objects, which contains the privacy field details of a component.
22+
*
23+
* @package core_privacy
24+
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
namespace core_privacy\local\metadata;
28+
29+
use core_privacy\local\metadata\types\type;
30+
31+
defined('MOODLE_INTERNAL') || die();
32+
33+
/**
34+
* A collection of metadata items.
35+
*
36+
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
37+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38+
*/
39+
class collection {
40+
41+
/**
42+
* @var string The component that the items in the collection belong to.
43+
*/
44+
protected $component;
45+
46+
/**
47+
* @var array The collection of metadata items.
48+
*/
49+
protected $collection = [];
50+
51+
/**
52+
* Constructor for a component's privacy collection class.
53+
*
54+
* @param string $component component name.
55+
*/
56+
public function __construct($component) {
57+
$this->component = $component;
58+
}
59+
60+
/**
61+
* Function to add an object that implements type interface to the current collection.
62+
*
63+
* @param type $type to add to collection.
64+
* @return $this
65+
*/
66+
public function add_type(type $type) {
67+
$this->collection[] = $type;
68+
69+
return $this;
70+
}
71+
72+
/**
73+
* Function to add a database table which contains user data to this collection.
74+
*
75+
* @param string $name the name of the database table.
76+
* @param array $privacyfields An associative array of fieldname to description.
77+
* @param string $summary A description of what the table is used for.
78+
* @return $this
79+
*/
80+
public function add_database_table($name, array $privacyfields, $summary = '') {
81+
$this->add_type(new types\database_table($name, $privacyfields, $summary));
82+
83+
return $this;
84+
}
85+
86+
/**
87+
* Function to link a subsystem to the component.
88+
*
89+
* @param string $name the name of the subsystem to link.
90+
* @param string $summary A description of what is stored within this subsystem.
91+
* @return $this
92+
*/
93+
public function link_subsystem($name, $summary = '') {
94+
$this->add_type(new types\subsystem_link($name, $summary));
95+
96+
return $this;
97+
}
98+
99+
/**
100+
* Function to link a plugin to the component.
101+
*
102+
* @param string $name the name of the plugin to link.
103+
* @param string $summary A description of what tis stored within this plugin.
104+
* @return $this
105+
*/
106+
public function link_plugintype($name, $summary = '') {
107+
$this->add_type(new types\plugintype_link($name, $summary));
108+
109+
return $this;
110+
}
111+
112+
/**
113+
* Function to indicate that data may be exported to an external location.
114+
*
115+
* @param string $name A name for the type of data exported.
116+
* @param array $privacyfields A list of fields with their description.
117+
* @param string $summary A description of what the table is used for. This is a language string identifier
118+
* within the component.
119+
* @return $this
120+
*/
121+
public function link_external_location($name, array $privacyfields, $summary = '') {
122+
$this->add_type(new types\external_location($name, $privacyfields, $summary));
123+
124+
return $this;
125+
}
126+
127+
/**
128+
* Add a type of user preference to the collection.
129+
*
130+
* Typically this is a single user preference, but in some cases the
131+
* name of a user preference fits a particular format.
132+
*
133+
* @param string $name The name of the user preference.
134+
* @param string $summary A description of what the preference is used for.
135+
* @return $this
136+
*/
137+
public function add_user_preference($name, $summary = '') {
138+
$this->add_type(new types\user_preference($name, $summary));
139+
140+
return $this;
141+
}
142+
143+
/**
144+
* Function to return the current component name.
145+
*
146+
* @return string
147+
*/
148+
public function get_component() {
149+
return $this->component;
150+
}
151+
152+
/**
153+
* The content of this collection.
154+
*
155+
* @return types\type[]
156+
*/
157+
public function get_collection() {
158+
return $this->collection;
159+
}
160+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* This file contains the core_privacy\nodata interface.
19+
*
20+
* Plugins implement this interface to declare that they don't store any personal information.
21+
*
22+
* @package core_privacy
23+
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
24+
*
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
namespace core_privacy\local\metadata;
28+
29+
defined('MOODLE_INTERNAL') || die();
30+
31+
interface null_provider {
32+
33+
/**
34+
* Get the language string identifier with the component's language
35+
* file to explain why this plugin stores no data.
36+
*
37+
* @return string
38+
*/
39+
public static function get_reason() : string ;
40+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* INterface for main metadata provider interface.
19+
*
20+
* @package core_privacy
21+
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
namespace core_privacy\local\metadata;
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
/**
29+
* INterface for main metadata provider interface.
30+
*
31+
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
32+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33+
*/
34+
interface provider {
35+
36+
/**
37+
* Returns meta data about this system.
38+
*
39+
* @param collection $collection The initialised collection to add items to.
40+
* @return collection A listing of user data stored through this system.
41+
*/
42+
public static function get_metadata(collection $collection) : collection ;
43+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* This file defines an item of metadata which encapsulates a database table.
19+
*
20+
* @package core_privacy
21+
* @copyright 2018 Zig Tan <zig@moodle.com>
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
namespace core_privacy\local\metadata\types;
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
/**
29+
* The database_table type.
30+
*
31+
* @copyright 2018 Zig Tan <zig@moodle.com>
32+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33+
*/
34+
class database_table implements type {
35+
36+
/**
37+
* @var string Database table name.
38+
*/
39+
protected $name;
40+
41+
/**
42+
* @var array Fields which contain user information within the table.
43+
*/
44+
protected $privacyfields;
45+
46+
/**
47+
* @var string A description of what this table is used for.
48+
*/
49+
protected $summary;
50+
51+
/**
52+
* Constructor to create a new database_table type.
53+
*
54+
* @param string $name The name of the database table being described.
55+
* @param array $privacyfields A list of fields with their description.
56+
* @param string $summary A description of what the table is used for.
57+
*/
58+
public function __construct($name, array $privacyfields = [], $summary = '') {
59+
if (debugging('', DEBUG_DEVELOPER)) {
60+
if (empty($privacyfields)) {
61+
debugging("Table '{$name}' was supplied without any fields.", DEBUG_DEVELOPER);
62+
}
63+
64+
foreach ($privacyfields as $key => $field) {
65+
$teststring = clean_param($field, PARAM_STRINGID);
66+
if ($teststring !== $field) {
67+
debugging("Field '{$key}' passed for table '{$name}' has an invalid langstring identifier: '{$field}'",
68+
DEBUG_DEVELOPER);
69+
}
70+
}
71+
72+
$teststring = clean_param($summary, PARAM_STRINGID);
73+
if ($teststring !== $summary) {
74+
debugging("Summary information for the '{$name}' table has an invalid langstring identifier: '{$summary}'",
75+
DEBUG_DEVELOPER);
76+
}
77+
}
78+
79+
$this->name = $name;
80+
$this->privacyfields = $privacyfields;
81+
$this->summary = $summary;
82+
}
83+
84+
/**
85+
* The name of the database table.
86+
*
87+
* @return string
88+
*/
89+
public function get_name() {
90+
return $this->name;
91+
}
92+
93+
/**
94+
* The list of fields within the table which contain user data, with a description of each field.
95+
*
96+
* @return array
97+
*/
98+
public function get_privacy_fields() {
99+
return $this->privacyfields;
100+
}
101+
102+
/**
103+
* A summary of what this table is used for.
104+
*
105+
* @return string
106+
*/
107+
public function get_summary() {
108+
return $this->summary;
109+
}
110+
}

0 commit comments

Comments
 (0)