mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-61307 core_privacy: Define and test providers
- Loading branch information
1 parent
1d58d59
commit 289fe1e
Showing
48 changed files
with
5,940 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file defines the core_privacy\local\metadata\collection class object. | ||
* | ||
* The collection class is used to organize a collection of types | ||
* objects, which contains the privacy field details of a component. | ||
* | ||
* @package core_privacy | ||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace core_privacy\local\metadata; | ||
|
||
use core_privacy\local\metadata\types\type; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* A collection of metadata items. | ||
* | ||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class collection { | ||
|
||
/** | ||
* @var string The component that the items in the collection belong to. | ||
*/ | ||
protected $component; | ||
|
||
/** | ||
* @var array The collection of metadata items. | ||
*/ | ||
protected $collection = []; | ||
|
||
/** | ||
* Constructor for a component's privacy collection class. | ||
* | ||
* @param string $component component name. | ||
*/ | ||
public function __construct($component) { | ||
$this->component = $component; | ||
} | ||
|
||
/** | ||
* Function to add an object that implements type interface to the current collection. | ||
* | ||
* @param type $type to add to collection. | ||
* @return $this | ||
*/ | ||
public function add_type(type $type) { | ||
$this->collection[] = $type; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Function to add a database table which contains user data to this collection. | ||
* | ||
* @param string $name the name of the database table. | ||
* @param array $privacyfields An associative array of fieldname to description. | ||
* @param string $summary A description of what the table is used for. | ||
* @return $this | ||
*/ | ||
public function add_database_table($name, array $privacyfields, $summary = '') { | ||
$this->add_type(new types\database_table($name, $privacyfields, $summary)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Function to link a subsystem to the component. | ||
* | ||
* @param string $name the name of the subsystem to link. | ||
* @param string $summary A description of what is stored within this subsystem. | ||
* @return $this | ||
*/ | ||
public function link_subsystem($name, $summary = '') { | ||
$this->add_type(new types\subsystem_link($name, $summary)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Function to link a plugin to the component. | ||
* | ||
* @param string $name the name of the plugin to link. | ||
* @param string $summary A description of what tis stored within this plugin. | ||
* @return $this | ||
*/ | ||
public function link_plugintype($name, $summary = '') { | ||
$this->add_type(new types\plugintype_link($name, $summary)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Function to indicate that data may be exported to an external location. | ||
* | ||
* @param string $name A name for the type of data exported. | ||
* @param array $privacyfields A list of fields with their description. | ||
* @param string $summary A description of what the table is used for. This is a language string identifier | ||
* within the component. | ||
* @return $this | ||
*/ | ||
public function link_external_location($name, array $privacyfields, $summary = '') { | ||
$this->add_type(new types\external_location($name, $privacyfields, $summary)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add a type of user preference to the collection. | ||
* | ||
* Typically this is a single user preference, but in some cases the | ||
* name of a user preference fits a particular format. | ||
* | ||
* @param string $name The name of the user preference. | ||
* @param string $summary A description of what the preference is used for. | ||
* @return $this | ||
*/ | ||
public function add_user_preference($name, $summary = '') { | ||
$this->add_type(new types\user_preference($name, $summary)); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Function to return the current component name. | ||
* | ||
* @return string | ||
*/ | ||
public function get_component() { | ||
return $this->component; | ||
} | ||
|
||
/** | ||
* The content of this collection. | ||
* | ||
* @return types\type[] | ||
*/ | ||
public function get_collection() { | ||
return $this->collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file contains the core_privacy\nodata interface. | ||
* | ||
* Plugins implement this interface to declare that they don't store any personal information. | ||
* | ||
* @package core_privacy | ||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> | ||
* | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace core_privacy\local\metadata; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
interface null_provider { | ||
|
||
/** | ||
* Get the language string identifier with the component's language | ||
* file to explain why this plugin stores no data. | ||
* | ||
* @return string | ||
*/ | ||
public static function get_reason() : string ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* INterface for main metadata provider interface. | ||
* | ||
* @package core_privacy | ||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace core_privacy\local\metadata; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* INterface for main metadata provider interface. | ||
* | ||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
interface provider { | ||
|
||
/** | ||
* Returns meta data about this system. | ||
* | ||
* @param collection $collection The initialised collection to add items to. | ||
* @return collection A listing of user data stored through this system. | ||
*/ | ||
public static function get_metadata(collection $collection) : collection ; | ||
} |
110 changes: 110 additions & 0 deletions
110
privacy/classes/local/metadata/types/database_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This file defines an item of metadata which encapsulates a database table. | ||
* | ||
* @package core_privacy | ||
* @copyright 2018 Zig Tan <zig@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
namespace core_privacy\local\metadata\types; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* The database_table type. | ||
* | ||
* @copyright 2018 Zig Tan <zig@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class database_table implements type { | ||
|
||
/** | ||
* @var string Database table name. | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @var array Fields which contain user information within the table. | ||
*/ | ||
protected $privacyfields; | ||
|
||
/** | ||
* @var string A description of what this table is used for. | ||
*/ | ||
protected $summary; | ||
|
||
/** | ||
* Constructor to create a new database_table type. | ||
* | ||
* @param string $name The name of the database table being described. | ||
* @param array $privacyfields A list of fields with their description. | ||
* @param string $summary A description of what the table is used for. | ||
*/ | ||
public function __construct($name, array $privacyfields = [], $summary = '') { | ||
if (debugging('', DEBUG_DEVELOPER)) { | ||
if (empty($privacyfields)) { | ||
debugging("Table '{$name}' was supplied without any fields.", DEBUG_DEVELOPER); | ||
} | ||
|
||
foreach ($privacyfields as $key => $field) { | ||
$teststring = clean_param($field, PARAM_STRINGID); | ||
if ($teststring !== $field) { | ||
debugging("Field '{$key}' passed for table '{$name}' has an invalid langstring identifier: '{$field}'", | ||
DEBUG_DEVELOPER); | ||
} | ||
} | ||
|
||
$teststring = clean_param($summary, PARAM_STRINGID); | ||
if ($teststring !== $summary) { | ||
debugging("Summary information for the '{$name}' table has an invalid langstring identifier: '{$summary}'", | ||
DEBUG_DEVELOPER); | ||
} | ||
} | ||
|
||
$this->name = $name; | ||
$this->privacyfields = $privacyfields; | ||
$this->summary = $summary; | ||
} | ||
|
||
/** | ||
* The name of the database table. | ||
* | ||
* @return string | ||
*/ | ||
public function get_name() { | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* The list of fields within the table which contain user data, with a description of each field. | ||
* | ||
* @return array | ||
*/ | ||
public function get_privacy_fields() { | ||
return $this->privacyfields; | ||
} | ||
|
||
/** | ||
* A summary of what this table is used for. | ||
* | ||
* @return string | ||
*/ | ||
public function get_summary() { | ||
return $this->summary; | ||
} | ||
} |
Oops, something went wrong.