Commit ccb01ab6 authored by Maria Sorica's avatar Maria Sorica Committed by Cecilia Vela Gurovic

Bug 1734169: Send message to admin when user rejects the privacy

When a user doesn't consent to a privacy statement,
a message will be sent to the institution/site admin.

If the user is part of an institution,the message
will be sent just to the inst admin. Else the
message will be sent to the site admin.

behatnotneeded

Change-Id: I7b3b87a59a537a805d851d29031df9cff941863e
parent 790b2c27
......@@ -1257,6 +1257,10 @@ function agreetoprivacy_submit(Pieform $form, $values) {
save_user_reply_to_agreement($USER->get('id'), $values[$institution . 'id'], $agreed);
$SESSION->add_ok_msg(get_string('agreementsaved', 'admin'));
if ($hasrefused) {
// Send a message to the institution/site admin informing that the user has refused the privacy statement.
$institution = new Institution($institution);
$institution->send_admin_institution_refused_privacy_message($USER->get('id'));
suspend_user($USER->get('id'), 'privacyrefusal');
$SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
$USER->logout();
......
......@@ -757,6 +757,15 @@ Please clean up existing user accounts or ask to have the maximum number of allo
Regards,
The %s Team';
$string['institutionmemberrefusedprivacy'] = 'Hello %s,
The user %s, with the username %s, has refused the privacy statement. Their user account was suspended.
Please contact the user via email at %s if you wish to discuss the refusal.
Regards,
The %s Team';
$string['config'] = 'Configuration';
$string['sendmessage'] = 'Send message';
......
......@@ -464,6 +464,43 @@ class Institution {
}
}
}
/**
* Send a message to the site admin or to the institution admin when a user refuses the privacy statement.
*
* If the user is part of an institution and the institution has admin(s), send the message just to the inst. admin(s).
* Else send the messege to the site admin(s).
*
* @param integer $studentid The id of the user who has refused the privacy statement.
*/
public function send_admin_institution_refused_privacy_message($studentid) {
$student = new User();
$student->find_by_id($studentid);
$studentname = display_name($student, null, true);
// Get the institution admin user records.
$admins = $this->admins();
// If the user is not part of an institution OR his institution has no admin, send the message to the site admin.
if (empty($admins)) {
$admins = $this->institution_and_site_admins();
}
// check if there are admins - otherwise there are no site admins?!?!?
if (count($admins) > 0) {
require_once('activity.php');
// send an email/message to each amdininistrator based on their specific language.
foreach ($admins as $index => $id) {
$lang = get_user_language($id);
$user = new User();
$user->find_by_id($id);
$message = (object) array(
'users' => array($id),
'subject' => $studentname . ' has refused the privacy statement',
'message' => get_string_from_language($lang, 'institutionmemberrefusedprivacy', 'mahara',
$user->firstname, $studentname, $student->username, $student->email, get_config('sitename')),
);
activity_occurred('maharamessage', $message);
}
}
}
public function declineRequestFromUser($userid) {
$lang = get_user_language($userid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment