MDL-63897 tool_dataprivacy: Send notifications for new requests
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 8 Nov 2018 23:53:08 +0000 (07:53 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 9 Nov 2018 03:25:57 +0000 (11:25 +0800)
admin/tool/dataprivacy/classes/api.php
admin/tool/dataprivacy/classes/data_request.php

index a7e587f..695fef7 100644 (file)
@@ -225,14 +225,22 @@ class api {
      * @param int $type The request type.
      * @param string $comments Request comments.
      * @param int $creationmethod The creation method of the data request.
+     * @param bool $notify Notify DPOs of this pending request.
      * @return data_request
      * @throws invalid_persistent_exception
      * @throws coding_exception
      */
     public static function create_data_request($foruser, $type, $comments = '',
-                                               $creationmethod = data_request::DATAREQUEST_CREATION_MANUAL) {
+            $creationmethod = data_request::DATAREQUEST_CREATION_MANUAL,
+            $notify = null
+        ) {
         global $USER, $ADMIN;
 
+        if (null === $notify && data_request::DATAREQUEST_CREATION_AUTO == $creationmethod) {
+            // If the request was automatically created, then do not notify unless explicitly set.
+            $notify = false;
+        }
+
         $datarequest = new data_request();
         // The user the request is being made for.
         $datarequest->set('userid', $foruser);
@@ -256,6 +264,16 @@ class api {
         // Store subject access request.
         $datarequest->create();
 
+        if ($notify) {
+            // Get the list of the site Data Protection Officers.
+            $dpos = api::get_site_dpos();
+
+            // Email the data request to the Data Protection Officer(s)/Admin(s).
+            foreach ($dpos as $dpo) {
+                api::notify_dpo($dpo, $datarequest);
+            }
+        }
+
         return $datarequest;
     }
 
index 22cf823..3901563 100644 (file)
@@ -277,7 +277,14 @@ class data_request extends persistent {
         $currentdata = $this->to_record();
         unset($currentdata->id);
 
-        $clone = api::create_data_request($this->get('userid'), $this->get('type'));
+        // Clone the original request, but do not notify.
+        $clone = api::create_data_request(
+                $this->get('userid'),
+                $this->get('type'),
+                $this->get('comments'),
+                $this->get('creationmethod'),
+                false
+            );
         $clone->set('comments', $this->get('comments'));
         $clone->set('dpo', $this->get('dpo'));
         $clone->set('requestedby', $this->get('requestedby'));