Commit 785ec774 authored by Robert Lyon's avatar Robert Lyon

Bug 1836981: Don't show 'registered users' rule on view index page

And don't show the rule when editing the profile access when isolated
institutions are on

behatnotneeded

Change-Id: I4c3957a6c1efd2d515418ac31ff0c235356f1ce4
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 61062b0d
......@@ -4292,6 +4292,14 @@ class View {
// Use the special sorting so that we get all the 'public' access rules at the top of the list
// then access rules where some groups of people can see it and lastly specified users/friends
foreach ($accesslist as $ak => $av) {
// remove 'Registered users' from the list if isolated institutions are enabled
if ($av->accesstype == 'loggedin' && is_isolated()) {
continue;
}
// remove 'Friends' from the list if friendsnotallowed is enabled
if ($av->accesstype == 'friends' && get_config('friendsnotallowed')) {
continue;
}
if ($av->usr) {
$av->displayname = display_name($av->usr);
if (!empty($av->role)) {
......
......@@ -92,6 +92,17 @@ $restrictedview = !can_view_view($viewid);
if ($restrictedview && !$USER->is_logged_in()) {
throw new AccessDeniedException();
}
else if ($restrictedview) {
// Check if isolated institutions are on and user being viewed is a site admin
// or both users are in no institution
$userinsts = $userobj->get('institutions');
$loggedininsts = $USER->get('institutions');
if ($userobj->get('admin') ||
(empty($userinsts) && empty($loggedininsts))) {
$restrictedview = false;
}
}
if (!$restrictedview) {
$viewcontent = $view->build_rows(); // Build content before initialising smarty in case pieform elements define headers.
}
......
......@@ -209,11 +209,19 @@ if ($group && in_array( $USER->get('id'), $admintutorids, true )) {
'defaultvalue' => 0,
)));
}
$viewaccess = $view->get_access('%s');
if (is_isolated() && !empty($viewaccess)) {
foreach ($viewaccess as $k => $access) {
if ($access['accesstype'] == 'loggedin') {
unset($viewaccess[$k]);
}
}
$viewaccess = array_values($viewaccess);
}
$form['elements']['accesslist'] = array(
'type' => 'viewacl',
'allowcomments' => $allowcomments,
'defaultvalue' => $view->get_access('%s'),
'defaultvalue' => $viewaccess,
'viewtype' => $view->get('type'),
'isformgroup' => false
);
......
......@@ -140,11 +140,20 @@ if ($group && in_array($USER->get('id'), $admintutorids, true)) {
'defaultvalue' => 0,
)));
}
$viewaccess = $view->get_access('%s');
if (is_isolated() && !empty($viewaccess)) {
foreach ($viewaccess as $k => $access) {
if ($access['accesstype'] == 'loggedin') {
unset($viewaccess[$k]);
}
}
$viewaccess = array_values($viewaccess);
}
$form['elements']['accesslist'] = array(
'type' => 'viewacl',
'allowcomments' => $allowcomments,
'defaultvalue' => $view->get_access('%s'),
'defaultvalue' => $viewaccess,
'viewtype' => $view->get('type'),
'isformgroup' => false
);
......@@ -370,12 +379,12 @@ function accessurl_validate(Pieform $form, $values) {
}
$now = time();
if ($item['stopdate'] && $now > $item['stopdate']) {
if (!empty($item['stopdate']) && $item['stopdate'] && $now > $item['stopdate']) {
$SESSION->add_error_msg(get_string('newstopdatecannotbeinpast', 'view', $accesstypestrings[$item['type']]));
$form->set_error('accesslist', '');
break;
}
if ($item['startdate'] && $item['stopdate'] && $item['startdate'] > $item['stopdate']) {
if (!empty($item['startdate']) && !empty($item['stopdate']) && $item['startdate'] && $item['stopdate'] && $item['startdate'] > $item['stopdate']) {
$SESSION->add_error_msg(get_string('newstartdatemustbebeforestopdate', 'view', $accesstypestrings[$item['type']]));
$form->set_error('accesslist', '');
break;
......
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