Permalink
Browse files

Merge branch 'MDL-62560-master'

  • Loading branch information...
dmonllao committed Oct 22, 2018
2 parents 53f14ee + 9e217d8 commit f7642bebc5636477a5199114dff5fd801f216c6d
Showing with 11,906 additions and 335 deletions.
  1. +36 −1 admin/tool/dataprivacy/classes/api.php
  2. +177 −8 admin/tool/dataprivacy/classes/expired_context.php
  3. +338 −53 admin/tool/dataprivacy/classes/expired_contexts_manager.php
  4. +120 −6 admin/tool/dataprivacy/classes/expiry_info.php
  5. +6 −13 admin/tool/dataprivacy/classes/external/purpose_exporter.php
  6. +63 −0 admin/tool/dataprivacy/classes/filtered_userlist.php
  7. +455 −30 admin/tool/dataprivacy/classes/form/purpose.php
  8. +160 −34 admin/tool/dataprivacy/classes/output/expired_contexts_table.php
  9. +40 −0 admin/tool/dataprivacy/classes/privacy/provider.php
  10. +9 −1 admin/tool/dataprivacy/classes/purpose.php
  11. +143 −0 admin/tool/dataprivacy/classes/purpose_override.php
  12. +1 −1 admin/tool/dataprivacy/classes/task/delete_expired_contexts.php
  13. +1 −1 admin/tool/dataprivacy/classes/task/expired_retention_period.php
  14. +7 −0 admin/tool/dataprivacy/db/caches.php
  15. +26 −1 admin/tool/dataprivacy/db/install.xml
  16. +64 −0 admin/tool/dataprivacy/db/upgrade.php
  17. +36 −3 admin/tool/dataprivacy/editpurpose.php
  18. +22 −0 admin/tool/dataprivacy/lang/en/tool_dataprivacy.php
  19. +17 −2 admin/tool/dataprivacy/templates/purposes.mustache
  20. +287 −0 admin/tool/dataprivacy/tests/api_test.php
  21. +1,112 −45 admin/tool/dataprivacy/tests/expired_contexts_test.php
  22. +99 −0 admin/tool/dataprivacy/tests/filtered_userlist_test.php
  23. +1 −1 admin/tool/dataprivacy/version.php
  24. +56 −1 admin/tool/monitor/classes/privacy/provider.php
  25. +126 −0 admin/tool/monitor/tests/privacy_test.php
  26. +50 −5 auth/mnet/classes/privacy/provider.php
  27. +116 −0 auth/mnet/tests/privacy_provider_test.php
  28. +48 −5 auth/oauth2/classes/privacy/provider.php
  29. +106 −0 auth/oauth2/tests/privacy_provider_test.php
  30. +33 −1 blocks/comments/classes/privacy/provider.php
  31. +131 −0 blocks/comments/tests/privacy_provider_test.php
  32. +53 −6 blocks/community/classes/privacy/provider.php
  33. +134 −0 blocks/community/tests/privacy_test.php
  34. +44 −0 blocks/html/classes/privacy/provider.php
  35. +93 −0 blocks/html/tests/privacy_provider_test.php
  36. +22 −2 blocks/recent_activity/classes/privacy/provider.php
  37. +46 −1 blocks/rss_client/classes/privacy/provider.php
  38. +92 −3 blocks/rss_client/tests/privacy_test.php
  39. +22 −1 blocks/tag_flickr/classes/privacy/provider.php
  40. +24 −2 cache/stores/memcached/classes/privacy/provider.php
  41. +24 −2 cache/stores/mongodb/classes/privacy/provider.php
  42. +24 −2 cache/stores/redis/classes/privacy/provider.php
  43. +24 −2 cache/stores/session/classes/privacy/provider.php
  44. +49 −0 cohort/classes/privacy/provider.php
  45. +121 −0 cohort/tests/privacy_test.php
  46. +61 −0 comment/classes/privacy/provider.php
  47. +98 −0 comment/tests/privacy_test.php
  48. +68 −0 enrol/classes/privacy/provider.php
  49. +46 −20 enrol/cohort/classes/privacy/provider.php
  50. +145 −4 enrol/cohort/tests/privacy_test.php
  51. +49 −2 enrol/flatfile/classes/privacy/provider.php
  52. +76 −4 enrol/flatfile/tests/privacy_provider_test.php
  53. +45 −20 enrol/meta/classes/privacy/provider.php
  54. +108 −4 enrol/meta/tests/privacy_test.php
  55. +96 −0 enrol/tests/privacy_test.php
  56. +21 −2 files/converter/classes/privacy/provider.php
  57. +122 −7 group/classes/privacy/provider.php
  58. +153 −0 group/tests/privacy_provider_test.php
  59. +5 −2 lang/en/privacy.php
  60. +48 −1 message/output/airnotifier/classes/privacy/provider.php
  61. +88 −0 message/output/airnotifier/tests/privacy_test.php
  62. +22 −1 message/output/email/classes/privacy/provider.php
  63. +19 −0 message/output/jabber/classes/privacy/provider.php
  64. +78 −1 mod/assignment/classes/privacy/provider.php
  65. +137 −0 mod/assignment/tests/privacy_test.php
  66. +52 −0 mod/chat/classes/privacy/provider.php
  67. +122 −0 mod/chat/tests/privacy_test.php
  68. +116 −0 mod/data/classes/privacy/provider.php
  69. +72 −0 mod/data/tests/privacy_provider_test.php
  70. +77 −0 mod/feedback/classes/privacy/provider.php
  71. +137 −0 mod/feedback/tests/privacy_test.php
  72. +152 −1 mod/forum/classes/privacy/provider.php
  73. +515 −0 mod/forum/tests/privacy_provider_test.php
  74. +125 −0 mod/glossary/classes/privacy/provider.php
  75. +146 −1 mod/glossary/tests/privacy_provider_test.php
  76. +88 −0 mod/lesson/classes/privacy/provider.php
  77. +133 −0 mod/lesson/tests/privacy_test.php
  78. +76 −0 mod/lti/classes/privacy/provider.php
  79. +86 −0 mod/lti/tests/privacy_provider_test.php
  80. +67 −0 mod/scorm/classes/privacy/provider.php
  81. +74 −1 mod/scorm/tests/privacy_test.php
  82. +96 −0 mod/survey/classes/privacy/provider.php
  83. +112 −0 mod/survey/tests/privacy_test.php
  84. +148 −0 mod/wiki/classes/privacy/provider.php
  85. +121 −0 mod/wiki/tests/privacy_test.php
  86. +46 −0 plagiarism/classes/privacy/plagiarims_user_provider.php
  87. +10 −0 plagiarism/classes/privacy/provider.php
  88. +56 −0 portfolio/classes/privacy/provider.php
  89. +102 −6 portfolio/tests/privacy_provider_test.php
  90. +61 −0 privacy/classes/local/request/approved_userlist.php
  91. +51 −0 privacy/classes/local/request/core_userlist_provider.php
  92. +12 −0 privacy/classes/local/request/helper.php
  93. +103 −0 privacy/classes/local/request/userlist.php
  94. +220 −0 privacy/classes/local/request/userlist_base.php
  95. +177 −0 privacy/classes/local/request/userlist_collection.php
  96. +83 −0 privacy/classes/manager.php
  97. +100 −0 privacy/tests/approved_userlist_test.php
  98. +241 −0 privacy/tests/userlist_base_test.php
  99. +161 −0 privacy/tests/userlist_collection.php
  100. +93 −0 privacy/tests/userlist_test.php
  101. +26 −0 rating/classes/privacy/provider.php
  102. +21 −1 repository/boxnet/classes/privacy/provider.php
  103. +46 −1 repository/classes/privacy/provider.php
  104. +21 −1 repository/dropbox/classes/privacy/provider.php
  105. +19 −0 repository/flickr/classes/privacy/provider.php
  106. +21 −1 repository/flickr_public/classes/privacy/provider.php
  107. +21 −1 repository/googledocs/classes/privacy/provider.php
  108. +21 −1 repository/merlot/classes/privacy/provider.php
  109. +67 −1 repository/onedrive/classes/privacy/provider.php
  110. +129 −0 repository/onedrive/tests/privacy_test.php
  111. +21 −1 repository/picasa/classes/privacy/provider.php
  112. +96 −0 repository/tests/privacy_test.php
  113. +19 −0 repository/wikimedia/classes/privacy/provider.php
  114. +21 −1 repository/youtube/classes/privacy/provider.php
  115. +44 −1 user/classes/privacy/provider.php
  116. +47 −0 user/profile/field/checkbox/classes/privacy/provider.php
  117. +107 −3 user/profile/field/checkbox/tests/privacy_test.php
  118. +47 −0 user/profile/field/datetime/classes/privacy/provider.php
  119. +110 −3 user/profile/field/datetime/tests/privacy_test.php
  120. +47 −0 user/profile/field/menu/classes/privacy/provider.php
  121. +107 −3 user/profile/field/menu/tests/privacy_test.php
  122. +47 −0 user/profile/field/text/classes/privacy/provider.php
  123. +107 −3 user/profile/field/text/tests/privacy_test.php
  124. +47 −0 user/profile/field/textarea/classes/privacy/provider.php
  125. +107 −3 user/profile/field/textarea/tests/privacy_test.php
  126. +125 −0 user/tests/privacy_test.php
  127. +58 −0 webservice/classes/privacy/provider.php
  128. +183 −0 webservice/tests/privacy_test.php
@@ -988,6 +988,7 @@ public static function set_expired_context_status(expired_context $expiredctx, $
*/
public static function add_request_contexts_with_status(contextlist_collection $clcollection, int $requestid, int $status) {
$request = new data_request($requestid);
$user = \core_user::get_user($request->get('userid'));
foreach ($clcollection as $contextlist) {
// Convert the \core_privacy\local\request\contextlist into a contextlist persistent and store it.
$clp = \tool_dataprivacy\contextlist::from_contextlist($contextlist);
@@ -998,10 +999,14 @@ public static function add_request_contexts_with_status(contextlist_collection $
foreach ($contextlist->get_contextids() as $contextid) {
if ($request->get('type') == static::DATAREQUEST_TYPE_DELETE) {
$context = \context::instance_by_id($contextid);
if (($purpose = static::get_effective_context_purpose($context)) && !empty($purpose->get('protected'))) {
$purpose = static::get_effective_context_purpose($context);
// Data can only be deleted from it if the context is either expired, or unprotected.
if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $user)) {
continue;
}
}
$context = new contextlist_context();
$context->set('contextid', $contextid)
->set('contextlistid', $contextlistid)
@@ -1099,6 +1104,15 @@ public static function get_approved_contextlist_collection_for_request(data_requ
$contexts = [];
}
if ($request->get('type') == static::DATAREQUEST_TYPE_DELETE) {
$context = \context::instance_by_id($record->contextid);
$purpose = static::get_effective_context_purpose($context);
// Data can only be deleted from it if the context is either expired, or unprotected.
if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $foruser)) {
continue;
}
}
$contexts[] = $record->contextid;
$lastcomponent = $record->component;
}
@@ -1196,4 +1210,25 @@ public static function set_context_defaults($contextlevel, $categoryid, $purpose
return true;
}
/**
* Format the supplied date interval as a retention period.
*
* @param \DateInterval $interval
* @return string
*/
public static function format_retention_period(\DateInterval $interval) : string {
// It is one or another.
if ($interval->y) {
$formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
} else if ($interval->m) {
$formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
} else if ($interval->d) {
$formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
} else {
$formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
}
return $formattedtime;
}
}
@@ -60,21 +60,36 @@ class expired_context extends \core\persistent {
* @return array
*/
protected static function define_properties() {
return array(
'contextid' => array(
return [
'contextid' => [
'type' => PARAM_INT,
'description' => 'The context id.',
),
'status' => array(
],
'defaultexpired' => [
'type' => PARAM_INT,
'description' => 'Whether to default retention period for the purpose has been reached',
'default' => 1,
],
'expiredroles' => [
'type' => PARAM_TEXT,
'description' => 'This list of roles to include during deletion',
'default' => '',
],
'unexpiredroles' => [
'type' => PARAM_TEXT,
'description' => 'This list of roles to exclude during deletion',
'default' => '',
],
'status' => [
'choices' => [
self::STATUS_EXPIRED,
self::STATUS_APPROVED,
self::STATUS_CLEANED,
],
'type' => PARAM_INT,
'description' => 'The deletion status of the context.',
),
);
],
];
}
/**
@@ -160,21 +175,130 @@ public static function get_record_count_by_contextlevel($contextlevel = null, $s
return $DB->count_records_sql($sql, $params);
}
/**
* Set the list of role IDs for either expiredroles, or unexpiredroles.
*
* @param string $field
* @param int[] $roleids
* @return expired_context
*/
protected function set_roleids_for(string $field, array $roleids) : expired_context {
$roledata = json_encode($roleids);
$this->raw_set($field, $roledata);
return $this;
}
/**
* Get the list of role IDs for either expiredroles, or unexpiredroles.
*
* @param string $field
* @return int[]
*/
protected function get_roleids_for(string $field) {
$value = $this->raw_get($field);
if (empty($value)) {
return [];
}
return json_decode($value);
}
/**
* Set the list of unexpired role IDs.
*
* @param int[] $roleids
* @return expired_context
*/
protected function set_unexpiredroles(array $roleids) : expired_context {
$this->set_roleids_for('unexpiredroles', $roleids);
return $this;
}
/**
* Add a set of role IDs to the list of expired role IDs.
*
* @param int[] $roleids
* @return expired_context
*/
public function add_expiredroles(array $roleids) : expired_context {
$existing = $this->get('expiredroles');
$newvalue = array_merge($existing, $roleids);
$this->set('expiredroles', $newvalue);
return $this;
}
/**
* Add a set of role IDs to the list of unexpired role IDs.
*
* @param int[] $roleids
* @return unexpired_context
*/
public function add_unexpiredroles(array $roleids) : expired_context {
$existing = $this->get('unexpiredroles');
$newvalue = array_merge($existing, $roleids);
$this->set('unexpiredroles', $newvalue);
return $this;
}
/**
* Set the list of expired role IDs.
*
* @param int[] $roleids
* @return expired_context
*/
protected function set_expiredroles(array $roleids) : expired_context {
$this->set_roleids_for('expiredroles', $roleids);
return $this;
}
/**
* Get the list of expired role IDs.
*
* @return int[]
*/
protected function get_expiredroles() {
return $this->get_roleids_for('expiredroles');
}
/**
* Get the list of unexpired role IDs.
*
* @return int[]
*/
protected function get_unexpiredroles() {
return $this->get_roleids_for('unexpiredroles');
}
/**
* Create a new expired_context based on the context, and expiry_info object.
*
* @param \context $context
* @param expiry_info $info
* @param boolean $save
* @return expired_context
*/
public static function create_from_expiry_info(\context $context, expiry_info $info) : expired_context {
public static function create_from_expiry_info(\context $context, expiry_info $info, bool $save = true) : expired_context {
$record = (object) [
'contextid' => $context->id,
'status' => self::STATUS_EXPIRED,
'defaultexpired' => (int) $info->is_default_expired(),
];
$expiredcontext = new static(0, $record);
$expiredcontext->save();
$expiredcontext->set('expiredroles', $info->get_expired_roles());
$expiredcontext->set('unexpiredroles', $info->get_unexpired_roles());
if ($save) {
$expiredcontext->save();
}
return $expiredcontext;
}
@@ -186,7 +310,42 @@ public static function create_from_expiry_info(\context $context, expiry_info $i
* @return $this
*/
public function update_from_expiry_info(expiry_info $info) : expired_context {
$save = false;
// Compare the expiredroles.
$thisexpired = $this->get('expiredroles');
$infoexpired = $info->get_expired_roles();
sort($thisexpired);
sort($infoexpired);
if ($infoexpired != $thisexpired) {
$this->set('expiredroles', $infoexpired);
$save = true;
}
// Compare the unexpiredroles.
$thisunexpired = $this->get('unexpiredroles');
$infounexpired = $info->get_unexpired_roles();
sort($thisunexpired);
sort($infounexpired);
if ($infounexpired != $thisunexpired) {
$this->set('unexpiredroles', $infounexpired);
$save = true;
}
if (empty($this->get('defaultexpired')) == $info->is_default_expired()) {
$this->set('defaultexpired', (int) $info->is_default_expired());
$save = true;
}
if ($save) {
$this->set('status', self::STATUS_EXPIRED);
$this->save();
}
return $this;
}
/**
@@ -206,4 +365,14 @@ public function can_process_deletion() : bool {
public function is_complete() : bool {
return ($this->get('status') == self::STATUS_CLEANED);
}
/**
* Whether this context has 'fully' expired.
* That is to say that the default retention period has been reached, and that there are no unexpired roles.
*
* @return bool
*/
public function is_fully_expired() : bool {
return $this->get('defaultexpired') && empty($this->get('unexpiredroles'));
}
}
Oops, something went wrong.

0 comments on commit f7642be

Please sign in to comment.