Commit 798250b4 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Require logged-in access for views automatically copied for new users/groups

parent 4e42183e
......@@ -281,6 +281,9 @@ $string['noownersfound'] = 'No owners found';
$string['viewsby'] = 'Views by %s';
$string['Preview'] = 'Preview';
$string['close'] = 'Close';
$string['viewscopiedfornewusersmustbecopyable'] = 'You must allow copying before you can set a view to be copied for new users.';
$string['viewscopiedfornewgroupsmustbecopyable'] = 'You must allow copying before you can set a view to be copied for new groups.';
$string['copynewusergroupneedsloggedinaccess'] = 'Views copied for new users or groups must give access to logged-in users.';
$string['blockcopypermission'] = 'Block copy permission';
$string['blockcopypermissiondesc'] = 'If you allow other users to copy this View, you may choose how this block will be copied';
......
......@@ -209,7 +209,13 @@ function ensure_loggedin_access() {
var newaccess = getFirstElementByTagAndClassName(null, 'loggedin-container', 'accesslistitems');
addElementClass(getFirstElementByTagAndClassName(null, 'removebutton', newaccess), 'hidden');
forEach(getElementsByTagAndClassName(null, 'pieform-calendar-toggle', newaccess), function (elem) { addElementClass(elem, 'hidden'); });
forEach(getElementsByTagAndClassName('input', null, newaccess), function (elem) { elem.value = null; elem.disabled = true; });
forEach(getElementsByTagAndClassName('input', null, newaccess), function (elem) {
if (elem.name.match(/\[st(art|op)date\]$/)) {
elem.value = '';
elem.disabled = true;
}
});
}
function relax_loggedin_access() {
forEach(getElementsByTagAndClassName(null, 'loggedin-container', $('accesslistitems')), function (elem) {
......
......@@ -220,15 +220,47 @@ $form['elements']['submit'] = array(
);
function editaccess_validate(Pieform $form, $values) {
global $institution, $group;
if ($values['copynewuser'] && !$values['template']) {
$form->set_error('copynewuser', get_string('viewscopiedfornewusersmustbecopyable', 'view'));
}
$createforgroup = false;
if ($institution == 'mahara') {
foreach (group_get_grouptypes() as $grouptype) {
if ($values['copyfornewgroups_'.$grouptype]) {
$createforgroup = true;
break;
}
}
if ($createforgroup && !$values['template']) {
$form->set_error('copyfornewgroups', get_string('viewscopiedfornewgroupsmustbecopyable', 'view'));
}
}
if ($values['startdate'] && $values['stopdate'] && $values['startdate'] > $values['stopdate']) {
$form->set_error('startdate', get_string('startdatemustbebeforestopdate', 'view'));
}
$loggedinaccess = false;
if ($values['accesslist']) {
foreach ($values['accesslist'] as $item) {
if (!isset($item['startdate'])) {
$item['startdate'] = null;
}
if (!isset($item['stopdate'])) {
$item['stopdate'] = null;
}
if ($item['type'] == 'loggedin' && !$item['startdate'] && !$item['stopdate']) {
$loggedinaccess = true;
}
if ($item['startdate'] && $item['stopdate'] && $item['startdate'] > $item['stopdate']) {
$form->set_error('accesslist', get_string('startdatemustbebeforestopdate', 'view'));
break;
}
}
}
// Must have logged in user access for copy new user/group settings.
if (($createforgroup || $values['copynewuser']) && !$loggedinaccess) {
$form->set_error('accesslist', get_string('copynewusergroupneedsloggedinaccess', 'view'));
}
}
function editaccess_cancel_submit() {
......
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