MDL-62075 tool_dataprivacy: Display correctly requests for other users
authorDavid Monllao <davidm@moodle.com>
Thu, 10 May 2018 15:43:56 +0000 (17:43 +0200)
committerDavid Monllao <davidm@moodle.com>
Thu, 10 May 2018 15:43:59 +0000 (17:43 +0200)
admin/tool/dataprivacy/classes/output/my_data_requests_page.php
admin/tool/dataprivacy/lang/en/tool_dataprivacy.php

index 6b90669..25229f0 100644 (file)
@@ -67,6 +67,8 @@ class my_data_requests_page implements renderable, templatable {
      * @throws moodle_exception
      */
     public function export_for_template(renderer_base $output) {
+        global $USER;
+
         $data = new stdClass();
         $data->newdatarequesturl = new moodle_url('/admin/tool/dataprivacy/createdatarequest.php');
 
@@ -80,10 +82,24 @@ class my_data_requests_page implements renderable, templatable {
             $requestid = $request->get('id');
             $status = $request->get('status');
             $userid = $request->get('userid');
-            $usercontext = context_user::instance($userid);
-            $requestexporter = new data_request_exporter($request, ['context' => $usercontext]);
+
+            $usercontext = context_user::instance($userid, IGNORE_MISSING);
+            if (!$usercontext) {
+                // Use the context system.
+                $outputcontext = \context_system::instance();
+            } else {
+                $outputcontext = $usercontext;
+            }
+
+            $requestexporter = new data_request_exporter($request, ['context' => $outputcontext]);
             $item = $requestexporter->export($output);
 
+            if ($request->get('userid') != $USER->id) {
+                // Append user name if it differs from $USER.
+                $a = (object)['typename' => $item->typename, 'user' => $item->foruser->fullname];
+                $item->typename = get_string('requesttypeuser', 'tool_dataprivacy', $a);
+            }
+
             $candownload = false;
             $cancancel = true;
             switch ($status) {
@@ -107,7 +123,7 @@ class my_data_requests_page implements renderable, templatable {
                 $canceltext = get_string('cancelrequest', 'tool_dataprivacy');
                 $actions[] = new action_menu_link_secondary($cancelurl, null, $canceltext, $canceldata);
             }
-            if ($candownload) {
+            if ($candownload && $usercontext) {
                 $downloadurl = moodle_url::make_pluginfile_url($usercontext->id, 'tool_dataprivacy', 'export', $requestid, '/',
                         'export.zip', true);
                 $downloadtext = get_string('download', 'tool_dataprivacy');
index ea87d52..c4461f5 100644 (file)
@@ -188,6 +188,7 @@ $string['requestfor'] = 'Requesting for';
 $string['requeststatus'] = 'Status';
 $string['requestsubmitted'] = 'Your request has been submitted to the site\'s Data Protection Officer';
 $string['requesttype'] = 'Type';
+$string['requesttypeuser'] = '{$a->typename} ({$a->user})';
 $string['requesttype_help'] = 'Select the reason why you would like to contact the site\'s Data Protection Officer';
 $string['requesttypedelete'] = 'Delete all of my personal data';
 $string['requesttypedeleteshort'] = 'Delete';