Skip to content

Commit

Permalink
MDL-82119 exemptions: Update privacy API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragonite committed Aug 14, 2024
1 parent 4d1a49f commit ff34a70
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 167 deletions.
16 changes: 10 additions & 6 deletions exemptions/classes/local/service/component_exemption_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_exemptions\local\service;

use core_exemptions\local\entity\exemption;
use core_exemptions\local\repository\exemption_repository_interface;

Expand Down Expand Up @@ -82,22 +83,25 @@ public function delete_exemptions_by_type_and_item(string $itemtype, int $itemid
* @param string $itemtype the type of the item being exempt.
* @param int $itemid the id of the item which is to be exempt.
* @param \context $context the context in which the item is to be exempt.
* @param string|null $reason optional reason for the exemption.
* @param int|null $reasonformat optional format of the reason for the exemption.
* @param int|null $ordering optional ordering integer used for sorting the exemptions in an area.
* @param array $options optional parameters including 'reason', 'reasonformat', 'ordering', and 'usermodified'.
* @return exemption the exemption, once created.
* @throws \moodle_exception if the component name is invalid, or if the repository encounters any errors.
*/
public function create_exemption(string $itemtype, int $itemid, \context $context,
?string $reason = null, ?int $reasonformat = null, ?int $ordering = null): exemption {
public function create_exemption(string $itemtype, int $itemid, \context $context, array $options = []): exemption {
// Access: Any component can ask to exempt something, we can't verify access to that 'something' here though.

// Validate the component name.
if (!in_array($this->component, \core_component::get_component_names())) {
throw new \moodle_exception("Invalid component name '$this->component'");
}

$exemption = new exemption($this->component, $itemtype, $itemid, $context->id, $reason, $reasonformat);
// Extract optional parameters with defaults.
$reason = $options['reason'] ?? null;
$reasonformat = $options['reasonformat'] ?? null;
$ordering = $options['ordering'] ?? null;
$usermodified = $options['usermodified'] ?? null;

$exemption = new exemption($this->component, $itemtype, $itemid, $context->id, $reason, $reasonformat, $usermodified);
$exemption->ordering = $ordering > 0 ? $ordering : null;
return $this->repo->add($exemption);
}
Expand Down
15 changes: 10 additions & 5 deletions exemptions/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ public static function get_exemptions_info_for_user(int $userid, \context $conte
}

return [
'component' => $component,
'itemtype' => $itemtype,
'itemid' => $itemid,
'contextid' => $context->id,
'ordering' => $exempt->ordering,
'timecreated' => transform::datetime($exempt->timecreated),
'timemodified' => transform::datetime($exempt->timemodified),
'usermodified' => $exempt->usermodified,
'reason' => $exempt->reason,
'reasonformat' => $exempt->reasonformat,
];
Expand Down Expand Up @@ -268,21 +273,21 @@ public static function delete_exemptions_for_userlist(\core_privacy\local\reques
* @throws \dml_exception
*/
public static function delete_exemptions_for_user(approved_contextlist $contextlist, string $component, string $itemtype,
int $itemid = 0) {
int $itemid = 0) {
global $DB;

$userid = $contextlist->get_user()->id;
$usermodified = $contextlist->get_user()->id;

list($insql, $inparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
[$insql, $inparams] = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$params = [
'userid' => $userid,
'usermodified' => $usermodified,
'component' => $component,
'itemtype' => $itemtype,
];
$params += $inparams;

$select = "userid = :userid AND component = :component AND itemtype =:itemtype AND contextid $insql";
$select = "usermodified = :usermodified AND component = :component AND itemtype = :itemtype AND contextid $insql";

if (!empty($itemid)) {
$select .= " AND itemid = :itemid";
Expand Down
Loading

0 comments on commit ff34a70

Please sign in to comment.