Commit 35a117ac authored by Maria Sorica's avatar Maria Sorica Committed by Cecilia Vela Gurovic
Browse files

Bug 1734169: Allow the user to say why he refuses the privacy

Add a textare in the 'are you sure' modal where the
user can write the reason why he refuses to consent to
a privacy statement.
This reason will be sent in a message to the institution
or site admin.

behatnotneeded

Change-Id: I6abe4c8c7c517b1319139497bedb40525d095fcb
parent ccb01ab6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1244,6 +1244,7 @@ function agreetoprivacy_submit(Pieform $form, $values) {
    array_push($userinstitutions, 'mahara');

    $hasrefused = param_integer('hasrefused', 0);
    $reason = param_variable('reason', '');

    foreach ($userinstitutions as $institution) {
        // check if the institution has a privacy statement
@@ -1259,7 +1260,7 @@ function agreetoprivacy_submit(Pieform $form, $values) {
            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'));
                $institution->send_admin_institution_refused_privacy_message($USER->get('id'), $reason);

                suspend_user($USER->get('id'), 'privacyrefusal');
                $SESSION->add_ok_msg(get_string('usersuspended', 'admin'));
+2 −0
Original line number Diff line number Diff line
@@ -1358,3 +1358,5 @@ $string['privacyrefusaldetails'] = 'If you do not consent to the privacy stateme
$string['privacyrefusal'] = 'Refused to consent to the privacy statement.';
$string['registerprivacyrefusal'] = 'Your account will not be created when you do not consent to the privacy statement.';
$string['registerprivacydetails'] = 'Please read the privacy statement. If you do not consent to it, you cannot create an account on the site.';
$string['enterreason'] = 'Please enter the reason of refusal here...';
$string['hasrefused'] = 'has refused the privacy statement';
+2 −1
Original line number Diff line number Diff line
@@ -760,12 +760,13 @@ The %s Team';
$string['institutionmemberrefusedprivacy'] = 'Hello %s,

The user %s, with the username %s, has refused the privacy statement. Their user account was suspended.
%s %s

Please contact the user via email at %s if you wish to discuss the refusal.

Regards,
The %s Team';

$string['thereasonis'] = 'The user\'s reason is:';
$string['config'] = 'Configuration';

$string['sendmessage'] = 'Send message';
+10 −3
Original line number Diff line number Diff line
@@ -471,8 +471,9 @@ class Institution {
     * Else send the messege to the site admin(s).
     *
     * @param integer $studentid The id of the user who has refused the privacy statement.
     * @param string $reason The reson why the user refused the privacy statement.
     */
    public function send_admin_institution_refused_privacy_message($studentid) {
    public function send_admin_institution_refused_privacy_message($studentid, $reason) {
        $student = new User();
        $student->find_by_id($studentid);
        $studentname = display_name($student, null, true);
@@ -483,6 +484,11 @@ class Institution {
        if (empty($admins)) {
            $admins = $this->institution_and_site_admins();
        }
        $thereasonis = '';
        if ($reason != '') {
            $thereasonis = get_string('thereasonis', 'mahara');
            $reason = '"' . urldecode($reason) . '"';
        }
        // check if there are admins - otherwise there are no site admins?!?!?
        if (count($admins) > 0) {
            require_once('activity.php');
@@ -493,9 +499,10 @@ class Institution {
                $user->find_by_id($id);
                $message = (object) array(
                    'users'   => array($id),
                    'subject' => $studentname . ' has refused the privacy statement',
                    'subject' => $studentname . ' ' . get_string('hasrefused', 'admin'),
                    'message' => get_string_from_language($lang, 'institutionmemberrefusedprivacy', 'mahara',
                            $user->firstname, $studentname, $student->username, $student->email,  get_config('sitename')),
                        $user->firstname, $studentname, $student->username,
                        $thereasonis, $reason, $student->email, get_config('sitename')),
                );
                activity_occurred('maharamessage', $message);
            }
+5 −1
Original line number Diff line number Diff line
@@ -10,6 +10,9 @@
                </div>
                <div class="modal-body">
                    <p><strong>{str tag=privacyrefusaldetails section=admin}</strong></p>
                    <p class="reason">
                        <textarea id="reason" rows="4" cols="65" placeholder="{str tag=enterreason section=admin}"></textarea>
                    </p>
                    <p>{str tag=confirmprivacyrefusal section=admin}</p>
                    <div class="btn-group">
                        <button id="confirm-no-button" type="button" class="btn btn-default">{str tag="yes"}</button>
@@ -39,7 +42,8 @@
        $j("#privacy-confirm-form").modal('hide');
        formAbortProcessing($j("#agreetoprivacy_submit"));
        $j('<input />').attr('type', 'hidden').attr('name', "hasrefused").attr('value', "1").appendTo('#agreetoprivacy');

        var reason = encodeURIComponent($j('#reason').val());
        $j('<input />').attr('class', 'js-hidden').attr('name', "reason").attr('value', reason).appendTo('#agreetoprivacy');
        // settimeout to 0 so it waits for everything else to finish before trigger the submit button
        setTimeout(function() {
            $j('#agreetoprivacy_submit').trigger( "click" );