Commit 8c507c8b authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1746259: Add the T&C to the register form

Had to change the definition of the following strings:
"siteprivacystatement"      to "siteprivacy"
"sitetermsstatement"        to "sitetermsandconditions"
"institutiontermsstatement" to "institutiontermsandconditions"

behatnotneeded

Change-Id: Ib2fd10b72ab4d6d80299a120e9cfbd11bd9fc8fe
parent 5f27da1e
......@@ -768,13 +768,13 @@ function privacy_form($ignoreagreevalue = false) {
if ($privacy->type == 'privacy') {
$title = get_string('institutionprivacystatement', 'admin');
if ($privacy->institution == 'mahara') {
$title = get_string('siteprivacystatement', 'admin');
$title = get_string('siteprivacy', 'admin');
}
}
else {
$title = get_string('institutiontermsstatement', 'admin');
$title = get_string('institutiontermsandconditions', 'admin');
if ($privacy->institution == 'mahara') {
$title = get_string('sitetermsstatement', 'admin');
$title = get_string('sitetermsandconditions', 'admin');
}
}
$smarty = smarty_core();
......@@ -2398,48 +2398,67 @@ function auth_generate_registration_form($formname, $authname='internal', $goto)
);
}
// Add site privacy statement and T&C to the register form.
$siteprivacy = get_latest_privacy_versions(array('mahara'));
$elements['privacy'] = array(
'type' => 'markup',
'value' => '<div id ="siteprivacy">' .
'<h2>' . get_string('siteprivacystatement', 'admin') . '</h2>' .
'<p class="text-midtone">' . get_string('registerprivacy1') . '</p>' .
'<div id ="siteprivacytext">' . $siteprivacy[0]->content . '</div>' .
'</div>',
);
$elements['privacyswitch'] = array(
'type' => 'switchbox',
'title' => get_string('privacyagreement', 'admin'),
'description' => get_string('registerprivacydetails', 'admin'),
'required' => true,
);
$elements['privacyid'] = array(
'type' => 'hidden',
'value' => $siteprivacy[0]->id,
);
$sitecontent = get_latest_privacy_versions(array('mahara'));
if ($sitecontent) {
$elements['privacytext'] = array(
'type' => 'markup',
'value' => '<p class="text-midtone">' . get_string('registerprivacy1') . '</p>',
);
foreach ($sitecontent as $content) {
$elements[$content->type] = array(
'type' => 'markup',
'value' => '<div id ="siteprivacy">' .
'<h2>' . get_string('site' . $content->type, 'admin') . '</h2>' .
'<div id ="siteprivacytext">' . $content->content . '</div>' .
'</div>',
);
$elements[$content->type . 'switch'] = array(
'type' => 'switchbox',
'title' => get_string('privacyagreement', 'admin', get_string($content->type . 'lowcase', 'admin')),
'description' => get_string('register' . $content->type, 'admin'),
'required' => true,
);
$elements[$content->type . 'id'] = array(
'type' => 'hidden',
'value' => $content->id,
);
}
}
// Add institution privacy if an institution has been selected.
$elements['instprivacy'] = array(
'type' => 'markup',
'value' => '<div id ="instprivacy" class ="js-hidden">' .
'value' => '<div id ="instprivacy" class ="inst js-hidden">' .
'<h2>' . get_string('institutionprivacystatement', 'admin') . '</h2>' .
'<p class="text-midtone">' . get_string('registerprivacy1') . '</p>' .
'<div id ="instprivacytext"></div>' .
'<div id ="instprivacytext" class="insttext"></div>' .
'</div>',
);
$elements['instprivacyswitch'] = array(
'type' => 'switchbox',
'title' => get_string('privacyagreement', 'admin'),
'description' => get_string('registerprivacydetails', 'admin'),
'class' => 'instprivacyswitch js-hidden',
'title' => get_string('privacyagreement', 'admin', get_string('privacylowcase', 'admin')),
'description' => get_string('registerprivacy1'),
'class' => 'instprivacyswitch js-hidden',
);
$elements['instprivacyid'] = array(
'type' => 'text',
'class' => 'js-hidden',
);
// Add the terms and conditions.
$elements['terms'] = array(
// Add institution terms if an institution has been selected.
$elements['insttermsandconditions'] = array(
'type' => 'markup',
'value' => "<h2>Terms and condititions</h2>" . get_site_page_content('termsandconditions'),
'value' => '<div id ="insttermsandconditions" class ="inst js-hidden">' .
'<h2>' . get_string('institutiontermsandconditions', 'admin') . '</h2>' .
'<div id ="insttermsandconditionstext" class="insttext"></div>' .
'</div>',
);
$elements['insttermsandconditionsswitch'] = array(
'type' => 'switchbox',
'title' => get_string('privacyagreement', 'admin', get_string('termsandconditionslowcase', 'admin')),
'description' => get_string('registertermsandconditions', 'admin'),
'class' => 'insttermsandconditionsswitch js-hidden',
);
$elements['insttermsandconditionsid'] = array(
'type' => 'text',
'class' => 'js-hidden',
);
$registerterms = get_config('registerterms');
......@@ -2531,8 +2550,10 @@ function auth_generate_registration_form_js($aform, $registerconfirm) {
jQuery(function($) {
function show_privacy(institutionid, value) {
$("#register_instprivacyid").attr("value", "");
$("#instprivacy").addClass("js-hidden");
$("#instprivacytext").html("");
$("#register_insttermsandconditionsid").attr("value", "");
$(".inst").addClass("js-hidden");
$(".insttext").html("");
$(".insttermsandconditionsswitch").addClass("js-hidden");
$(".instprivacyswitch").addClass("js-hidden");
if (value !== "0" && value !== "mahara") {
......@@ -2545,11 +2566,13 @@ function auth_generate_registration_form_js($aform, $registerconfirm) {
"institution": value,
}
}).done(function (data) {
if (data && data.content) {
$("#instprivacy").removeClass("js-hidden");
$("#instprivacytext").html(data.content);
$(".instprivacyswitch").removeClass("js-hidden");
$("#register_instprivacyid").attr("value", data.id);
if (data) {
$.each(data, function(index, value) {
$("#inst" + index).removeClass("js-hidden");
$("#inst" + index + "text").html(value.content);
$(".inst" + index + "switch").removeClass("js-hidden");
$("#register_inst" + index + "id").attr("value", value.id);
});
}
});
}
......@@ -2635,13 +2658,22 @@ function auth_register_validate(Pieform $form, $values) {
safe_require('auth', 'internal');
// Privacy statements must have been accepted by the user.
if (!$values['privacyswitch']) {
$SESSION->add_error_msg(get_string('registerrefusal', 'admin', get_string('privacylowcase', 'admin')));
$form->set_error('privacyswitch', get_string('registerrefusal', 'admin', get_string('privacylowcase', 'admin')));
}
if (!$values['instprivacyswitch'] && $values['instprivacyid'] != '') {
$SESSION->add_error_msg(get_string('registerprivacyrefusal', 'admin'));
$form->set_error('instprivacyswitch', get_string('registerprivacyrefusal', 'admin'));
$SESSION->add_error_msg(get_string('registerrefusal', 'admin', get_string('privacylowcase', 'admin')));
$form->set_error('instprivacyswitch', get_string('registerrefusal', 'admin', get_string('privacylowcase', 'admin')));
}
if (!$values['privacyswitch']) {
$SESSION->add_error_msg(get_string('registerprivacyrefusal', 'admin'));
$form->set_error('privacyswitch', get_string('registerprivacyrefusal', 'admin'));
// Terms and conditions must have been accepted by the user.
if (!$values['termsandconditionsswitch']) {
$SESSION->add_error_msg(get_string('registerrefusal', 'admin', get_string('termsandconditionslowcase', 'admin')));
$form->set_error('termsandconditionsswitch', get_string('registerrefusal', 'admin', get_string('termsandconditionslowcase', 'admin')));
}
if (!$values['insttermsandconditionsswitch'] && $values['insttermsandconditionsid'] != '') {
$SESSION->add_error_msg(get_string('registerrefusal', 'admin', get_string('termsandconditionslowcase', 'admin')));
$form->set_error('insttermsandconditionsswitch', get_string('registerrefusal', 'admin', get_string('termsandconditionslowcase', 'admin')));
}
// First name and last name must contain at least one non whitespace
......@@ -2730,7 +2762,13 @@ function auth_register_submit(Pieform $form, $values) {
local_register_submit($values);
}
$extra = new StdClass;
$extra->privacy = array($values['privacyid'], $values['instprivacyid']);
$extra->privacy = array($values['privacyid'], $values['termsandconditionsid']);
if (isset($values['instprivacyid']) && !empty($values['instprivacyid'])) {
array_push($extra->privacy, $values['instprivacyid']);
}
if (isset($values['insttermsandconditionsid']) && !empty($values['insttermsandconditionsid'])) {
array_push($extra->privacy, $values['insttermsandconditionsid']);
}
$values['extra'] = serialize($extra);
try {
if (!record_exists('usr_registration', 'email', $values['email'])) {
......
......@@ -21,4 +21,4 @@ $institution = param_alphanum('institution', null);
$privacy = get_latest_privacy_versions(array($institution));
json_headers();
print json_encode($privacy[0]);
print json_encode($privacy);
......@@ -1345,13 +1345,13 @@ $string['editversion'] = 'Edit version %s';
$string['privacylastversion'] = 'Privacy statements must have unique version names of up to 15 characters. The latest version for this privacy statement is "%s".';
$string['termsandconditionslastversion'] = 'Terms and conditions must have unique version names of up to 15 characters. The latest version for this privacy statement is "%s".';
$string['versionalreadyexist'] = 'A %s version with the name "%s" already exists.';
$string['siteprivacystatement'] = 'Site privacy statement';
$string['sitetermsstatement'] = 'Site terms and conditions';
$string['siteprivacy'] = 'Site privacy statement';
$string['sitetermsandconditions'] = 'Site terms and conditions';
$string['addoneversionlink'] = '<a href="%s">Add one</a> if you need it.';
$string['privacyversionfor'] = 'Privacy statement for version "%s" is as follows:';
$string['termsversionfor'] = 'Terms and conditions for version "%s" is as follows:';
$string['institutionprivacystatement'] = 'Institution privacy statement';
$string['institutiontermsstatement'] = 'Institution terms and conditions';
$string['institutiontermsandconditions'] = 'Institution terms and conditions';
$string['userprivacypagedescription'] = 'Displayed are the current privacy statements and terms and conditions to which you consented.';
$string['lastupdated'] = 'Last updated on';
$string['newprivacy'] = 'Before entering your account, please read the information displayed below.';
......@@ -1363,8 +1363,9 @@ $string['refuseprivacy'] = 'Refuse privacy statement or terms and condititons';
$string['confirmprivacyrefusal'] = 'Are you really sure you wish to continue?';
$string['privacyrefusaldetails'] = 'If you do not consent to the privacy statements or terms and conditions, your account will be suspended.';
$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['registerrefusal'] = 'Your account will not be created when you do not consent to the %s.';
$string['registerprivacy'] = 'Please read the privacy statement. If you don not consent to it, you cannot create an account on the site.';
$string['registertermsandconditions'] = 'Please read the terms and conditions. If you don not consent to them, you cannot create an account on the site.';
$string['enterreason'] = 'Please enter the reason of refusal here...';
$string['hasrefused'] = 'has refused the privacy statement';
$string['privacylowcase'] = 'privacy statement';
......
......@@ -24,7 +24,7 @@
<legend>
<h4>
<a href="#dropdown-privacyst-{$sitecontent['privacy']->id}" data-toggle="collapse" aria-expanded="false" aria-controls="dropdown" class="collapsed">
{str tag="siteprivacystatement" section="admin"}
{str tag="siteprivacy" section="admin"}
<span class="icon icon-chevron-down collapse-indicator right pull-right"> </span>
</a>
</h4>
......@@ -48,7 +48,7 @@
<legend>
<h4>
<a href="#dropdown-terms-{$sitecontent['termsandconditions']->id}" data-toggle="collapse" aria-expanded="false" aria-controls="dropdown" class="collapsed">
{str tag="sitetermsstatement" section="admin"}
{str tag="sitetermsandconditions" section="admin"}
<span class="icon icon-chevron-down collapse-indicator right pull-right"> </span>
</a>
</h4>
......
......@@ -18,6 +18,7 @@ Scenario: Registering as a new student and checking switch can flick back and fo
| Email address | fakeymcfakey@example.org |
| Registration reason | I will absolutely make this institution more amazing!! |
And I enable the switch "I consent to this privacy statement"
And I enable the switch "I consent to this terms and conditions"
# we wait a human amount of time so the spam trap is avoided
And I wait "4" seconds
And I press "Register"
......
@javascript @core @gdpr
Feature: Strict privacy switch
As a new user logging in for the first time
When strict privacy is enabled
I should be required to accept the privacy statement
Background:
# And the following site settings are set:
#| 'usersallowedmultipleinstitutions' | 0 |
# | 'institutionstrictprivacy' | 1 |
As a new user logging in for the first time
When strict privacy is enabled
I should be required to accept the privacy statement
Scenario: Create user who logs in with strict privacy enabled
Given I log in as "admin" with password "Kupuhipa1"
......@@ -35,14 +29,15 @@ Scenario: Create user who logs in with strict privacy enabled
And I press "Save changes"
And I log out
Given I log in as "bob" with password "Kupuhipa1"
Then I should see "Before entering your account, please read the privacy statement displayed below."
Then I should see "Before entering your account, please read the information displayed below."
# Try to ignore privacy statement
And I choose "Pages and collections" in "Portfolio" from main menu
Then I should see "Before entering your account, please read the privacy statement displayed below."
Then I should see "Before entering your account, please read the information displayed below."
And I press "Save changes"
Then I should see "If you do not consent to the privacy statement, your account will be suspended."
Then I should see "If you do not consent to the privacy statements or terms and conditions, your account will be suspended."
Then I press "No"
# consent to privacy statement
And I enable the switch "I consent to this privacy statement"
And I enable the switch "I consent to this terms and conditions"
And I press "Save changes"
Then I should see "Welcome"
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