Commit eb9c4dae authored by Francois Marier's avatar Francois Marier
Browse files

Make logged-in user access on profile configurable



Part of bug #807278

Add new site setting to force logged-in access to profile pages

Change-Id: I7e1634cba16759923e3aa4c64d129d1f5280665f
Signed-off-by: default avatarEugene Venter <eugene@catalyst.net.nz>
parent e283a68a
......@@ -167,6 +167,13 @@ $siteoptionform = array(
'defaultvalue' => get_config('anonymouscomments'),
'disabled' => in_array('anonymouscomments', $OVERRIDDEN),
),
'loggedinprofileviewaccess' => array(
'type' => 'checkbox',
'title' => get_string('loggedinprofileviewaccess', 'admin'),
'description' => get_string('loggedinprofileviewaccessdescription', 'admin'),
'defaultvalue' => get_config('loggedinprofileviewaccess'),
'disabled' => in_array('loggedinprofileviewaccess', $OVERRIDDEN),
),
),
),
'searchsettings' => array(
......@@ -579,7 +586,7 @@ function siteoptions_submit(Pieform $form, $values) {
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend',
'showselfsearchsideblock', 'searchusernames', 'searchplugin', 'showtagssideblock',
'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'disableexternalresources',
'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'loggedinprofileviewaccess', 'disableexternalresources',
'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure',
'noreplyaddress', 'homepageinfo', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers', 'registerterms',
'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
......
......@@ -540,13 +540,15 @@ class User {
// Set view access
$access = array();
$access[] = array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
);
if (get_config('loggedinprofileviewaccess')) {
$access[] = array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
);
}
if ($institutions = $this->get('institutions')) {
foreach ($institutions as $i) {
$access[] = array(
......
......@@ -228,6 +228,8 @@ $string['allowpublicprofiles'] = 'Allow public profiles';
$string['allowpublicprofilesdescription'] = 'If set to yes, users will be able to set their profile pages to be accessible to the public rather than only to logged in users';
$string['anonymouscomments'] = 'Anonymous Comments';
$string['anonymouscommentsdescription'] = 'If checked, logged-out users can leave comments on public pages or pages they can access by secret URL.';
$string['loggedinprofileviewaccess'] = 'Logged-in profile view access';
$string['loggedinprofileviewaccessdescription'] = 'If checked, a user\'s profile page will be viewable by all logged-in users.';
$string['antispam'] = 'Anti-spam';
$string['antispamdescription'] = 'The type of anti-spam measures used on publicly visible forms';
$string['dropdownmenu'] = 'Dropdown navigation';
......
......@@ -2627,5 +2627,10 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('cron', $cron);
}
if ($oldversion < 2011082401) {
// Set config value for logged-in profile view access
set_config('loggedinprofileviewaccess', 1);
}
return $status;
}
......@@ -158,6 +158,9 @@ function pieform_element_viewacl(Pieform $form, $element) {
function pieform_render_viewacl_getvaluebytype($type, $id) {
switch ($type) {
case 'loggedin':
return get_string('loggedin', 'view');
break;
case 'user':
$user = get_record('usr', 'id', $id);
return display_name($user);
......
......@@ -741,6 +741,7 @@ function core_install_firstcoredata_defaults() {
set_config('footerlinks', serialize(array('privacystatement', 'about', 'contactus')));
set_config('searchusernames', 1);
set_config('onlineuserssideblockmaxusers', 10);
set_config('loggedinprofileviewaccess', 1);
set_config('dropdownmenu', 0);
// install the applications
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011082400;
$config->version = 2011082401;
$config->release = '1.5.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -671,6 +671,10 @@ class View {
$item['id'] = null;
}
if ($this->type == 'profile' && $item['type'] == 'loggedin' && get_config('loggedinprofileviewaccess')) {
$item['locked'] = true;
}
if ($item['role']) {
$item['roledisplay'] = get_string($item['role'], 'grouptype.'.$grouptypes[$item['group']]->grouptype);
}
......@@ -962,6 +966,17 @@ class View {
db_commit();
}
public function add_access($access) {
if (!$this->id) {
return false;
}
// Ensure view is correct
$access->view = $this->id;
ensure_record_exists('view_access', $access, $access);
}
public function add_owner_institution_access($instnames=array()) {
if (!$this->id) {
return false;
......
......@@ -128,6 +128,17 @@ if (!empty($views)) {
if ($view->get('type') == 'profile') {
// Make sure all the user's institutions have access to profile view
$view->add_owner_institution_access();
if (get_config('loggedinprofileviewaccess')) {
// Force logged-in user access
$viewaccess = new stdClass;
$viewaccess->accesstype = 'loggedin';
$viewaccess->startdate = null;
$viewaccess->stopdate = null;
$viewaccess->allowcomments = 0;
$viewaccess->approvecomments = 1;
$view->add_access($viewaccess);
}
}
$allowcomments = $view->get('allowcomments');
......@@ -543,6 +554,13 @@ function editaccess_submit(Pieform $form, $values) {
if ($view->get('type') == 'profile') {
// Ensure the user's institutions are still added to the access list
$view->add_owner_institution_access();
if (get_config('loggedinprofileviewaccess')) {
// Force logged-in user access
$viewaccess = new stdClass;
$viewaccess->accesstype = 'loggedin';
$view->add_access($viewaccess);
}
}
}
......
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