Skip to content

Commit

Permalink
MDL-62600 tool_dataprivacy: Corrected availability of PO pages to admins
Browse files Browse the repository at this point in the history
  • Loading branch information
mickhawkins committed Aug 14, 2018
1 parent 1f29727 commit 41b6287
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 61 deletions.
19 changes: 19 additions & 0 deletions admin/tool/dataprivacy/classes/api.php
Expand Up @@ -127,6 +127,25 @@ public static function check_can_manage_data_registry($contextid = false) {
require_capability('tool/dataprivacy:managedataregistry', $context);
}

/**
* Fetches the role shortnames of Data Protection Officer roles.
*
* @return array An array of the DPO role shortnames
*/
public static function get_dpo_role_names() {
global $DB;

$dporoleids = explode(',', str_replace(' ', '', get_config('tool_dataprivacy', 'dporoles')));
$dponames = array();

if (!empty($dporoleids)) {
list($insql, $inparams) = $DB->get_in_or_equal($dporoleids);
$dponames = $DB->get_fieldset_select('role', 'shortname', "id {$insql}", $inparams);
}

return $dponames;
}

/**
* Fetches the list of users with the Data Protection Officer role.
*
Expand Down
22 changes: 14 additions & 8 deletions admin/tool/dataprivacy/datadeletion.php
Expand Up @@ -37,13 +37,19 @@

echo $OUTPUT->header();

$table = new \tool_dataprivacy\output\expired_contexts_table($filter);
$table->baseurl = $url;
$table->baseurl->param('filter', $filter);

$datadeletionpage = new \tool_dataprivacy\output\data_deletion_page($filter, $table);

$output = $PAGE->get_renderer('tool_dataprivacy');
echo $output->render($datadeletionpage);
if (\tool_dataprivacy\api::is_site_dpo($USER->id)) {
$table = new \tool_dataprivacy\output\expired_contexts_table($filter);
$table->baseurl = $url;
$table->baseurl->param('filter', $filter);

$datadeletionpage = new \tool_dataprivacy\output\data_deletion_page($filter, $table);

$output = $PAGE->get_renderer('tool_dataprivacy');
echo $output->render($datadeletionpage);
} else {
$dponamestring = implode (',', tool_dataprivacy\api::get_dpo_role_names());
$message = get_string('privacyofficeronly', 'tool_dataprivacy', $dponamestring);
echo $OUTPUT->notification($message, 'error');
}

echo $OUTPUT->footer();
11 changes: 8 additions & 3 deletions admin/tool/dataprivacy/dataregistry.php
Expand Up @@ -38,7 +38,12 @@
$output = $PAGE->get_renderer('tool_dataprivacy');
echo $output->header();

$dataregistry = new tool_dataprivacy\output\data_registry_page($contextlevel, $contextid);

echo $output->render($dataregistry);
if (\tool_dataprivacy\api::is_site_dpo($USER->id)) {
$dataregistry = new tool_dataprivacy\output\data_registry_page($contextlevel, $contextid);
echo $output->render($dataregistry);
} else {
$dponamestring = implode (', ', tool_dataprivacy\api::get_dpo_role_names());
$message = get_string('privacyofficeronly', 'tool_dataprivacy', $dponamestring);
echo $OUTPUT->notification($message, 'error');
}
echo $OUTPUT->footer();
64 changes: 35 additions & 29 deletions admin/tool/dataprivacy/datarequests.php
Expand Up @@ -36,39 +36,45 @@
echo $OUTPUT->header();
echo $OUTPUT->heading($title);

$filtersapplied = optional_param_array('request-filters', [-1], PARAM_NOTAGS);
$filterscleared = optional_param('filters-cleared', 0, PARAM_INT);
if ($filtersapplied === [-1]) {
// If there are no filters submitted, check if there is a saved filters from the user preferences.
$filterprefs = get_user_preferences(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, null);
if ($filterprefs && empty($filterscleared)) {
$filtersapplied = json_decode($filterprefs);
} else {
$filtersapplied = [];
if (\tool_dataprivacy\api::is_site_dpo($USER->id)) {
$filtersapplied = optional_param_array('request-filters', [-1], PARAM_NOTAGS);
$filterscleared = optional_param('filters-cleared', 0, PARAM_INT);
if ($filtersapplied === [-1]) {
// If there are no filters submitted, check if there is a saved filters from the user preferences.
$filterprefs = get_user_preferences(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, null);
if ($filterprefs && empty($filterscleared)) {
$filtersapplied = json_decode($filterprefs);
} else {
$filtersapplied = [];
}
}
}
// Save the current applied filters to the user preferences.
set_user_preference(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, json_encode($filtersapplied));
// Save the current applied filters to the user preferences.
set_user_preference(\tool_dataprivacy\local\helper::PREF_REQUEST_FILTERS, json_encode($filtersapplied));

$types = [];
$statuses = [];
foreach ($filtersapplied as $filter) {
list($category, $value) = explode(':', $filter);
switch($category) {
case \tool_dataprivacy\local\helper::FILTER_TYPE:
$types[] = $value;
break;
case \tool_dataprivacy\local\helper::FILTER_STATUS:
$statuses[] = $value;
break;
$types = [];
$statuses = [];
foreach ($filtersapplied as $filter) {
list($category, $value) = explode(':', $filter);
switch($category) {
case \tool_dataprivacy\local\helper::FILTER_TYPE:
$types[] = $value;
break;
case \tool_dataprivacy\local\helper::FILTER_STATUS:
$statuses[] = $value;
break;
}
}
}

$table = new \tool_dataprivacy\output\data_requests_table(0, $statuses, $types, true);
$table->baseurl = $url;
$table = new \tool_dataprivacy\output\data_requests_table(0, $statuses, $types, true);
$table->baseurl = $url;

$requestlist = new tool_dataprivacy\output\data_requests_page($table, $filtersapplied);
$requestlistoutput = $PAGE->get_renderer('tool_dataprivacy');
echo $requestlistoutput->render($requestlist);
$requestlist = new tool_dataprivacy\output\data_requests_page($table, $filtersapplied);
$requestlistoutput = $PAGE->get_renderer('tool_dataprivacy');
echo $requestlistoutput->render($requestlist);
} else {
$dponamestring = implode (', ', tool_dataprivacy\api::get_dpo_role_names());
$message = get_string('privacyofficeronly', 'tool_dataprivacy', $dponamestring);
echo $OUTPUT->notification($message, 'error');
}

echo $OUTPUT->footer();
1 change: 1 addition & 0 deletions admin/tool/dataprivacy/lang/en/tool_dataprivacy.php
Expand Up @@ -186,6 +186,7 @@
$string['pluginregistry'] = 'Plugin privacy registry';
$string['pluginregistrytitle'] = 'Plugin privacy compliance registry';
$string['privacy'] = 'Privacy';
$string['privacyofficeronly'] = 'Only users who are assigned a privacy officer role ({$a}) have access to this content';
$string['privacy:metadata:preference:tool_dataprivacy_request-filters'] = 'The filters currently applied to the data requests page.';
$string['privacy:metadata:request'] = 'Information from personal data requests (subject access and deletion requests) made for this site.';
$string['privacy:metadata:request:comments'] = 'Any user comments accompanying the request.';
Expand Down
17 changes: 12 additions & 5 deletions admin/tool/dataprivacy/pluginregistry.php
Expand Up @@ -38,11 +38,18 @@
$output = $PAGE->get_renderer('tool_dataprivacy');
echo $output->header();

// Get data!
$metadatatool = new \tool_dataprivacy\metadata_registry();
$metadata = $metadatatool->get_registry_metadata();
if (\tool_dataprivacy\api::is_site_dpo($USER->id)) {
// Get data!
$metadatatool = new \tool_dataprivacy\metadata_registry();
$metadata = $metadatatool->get_registry_metadata();

$dataregistry = new tool_dataprivacy\output\data_registry_compliance_page($metadata);
$dataregistry = new tool_dataprivacy\output\data_registry_compliance_page($metadata);

echo $output->render($dataregistry);
} else {
$dponamestring = implode (', ', tool_dataprivacy\api::get_dpo_role_names());
$message = get_string('privacyofficeronly', 'tool_dataprivacy', $dponamestring);
echo $OUTPUT->notification($message, 'error');
}

echo $output->render($dataregistry);
echo $OUTPUT->footer();
35 changes: 19 additions & 16 deletions admin/tool/dataprivacy/settings.php
Expand Up @@ -57,22 +57,25 @@
}
}

// Link that leads to the data requests management page.
$ADMIN->add('privacy', new admin_externalpage('datarequests', get_string('datarequests', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/datarequests.php'), 'tool/dataprivacy:managedatarequests')
);
// Restrict config links to the DPO.
if (tool_dataprivacy\api::is_site_dpo($USER->id)) {
// Link that leads to the data requests management page.
$ADMIN->add('privacy', new admin_externalpage('datarequests', get_string('datarequests', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/datarequests.php'), 'tool/dataprivacy:managedatarequests')
);

// Link that leads to the data registry management page.
$ADMIN->add('privacy', new admin_externalpage('dataregistry', get_string('dataregistry', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/dataregistry.php'), 'tool/dataprivacy:managedataregistry')
);
// Link that leads to the data registry management page.
$ADMIN->add('privacy', new admin_externalpage('dataregistry', get_string('dataregistry', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/dataregistry.php'), 'tool/dataprivacy:managedataregistry')
);

// Link that leads to the review page of expired contexts that are up for deletion.
$ADMIN->add('privacy', new admin_externalpage('datadeletion', get_string('datadeletion', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/datadeletion.php'), 'tool/dataprivacy:managedataregistry')
);
// Link that leads to the review page of expired contexts that are up for deletion.
$ADMIN->add('privacy', new admin_externalpage('datadeletion', get_string('datadeletion', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/datadeletion.php'), 'tool/dataprivacy:managedataregistry')
);

// Link that leads to the other data registry management page.
$ADMIN->add('privacy', new admin_externalpage('pluginregistry', get_string('pluginregistry', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/pluginregistry.php'), 'tool/dataprivacy:managedataregistry')
);
// Link that leads to the other data registry management page.
$ADMIN->add('privacy', new admin_externalpage('pluginregistry', get_string('pluginregistry', 'tool_dataprivacy'),
new moodle_url('/admin/tool/dataprivacy/pluginregistry.php'), 'tool/dataprivacy:managedataregistry')
);
}

0 comments on commit 41b6287

Please sign in to comment.