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

Force institution access on profile page



Part of bug #807278

Change-Id: I3c01e88577262dd610f5df74f79f5150e3978dd9
Signed-off-by: default avatarEugene Venter <eugene@catalyst.net.nz>
parent 61454f50
......@@ -538,13 +538,27 @@ class User {
$aboutme->set('configdata', $configdata);
$view->addblockinstance($aboutme);
$view->set_access(array(
// Set view access
$access = array();
$access[] = array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
));
);
if ($institutions = $this->get('institutions')) {
foreach ($institutions as $i) {
$access[] = array(
'type' => 'institution',
'id' => $i->institution,
'startdate' => null,
'stopdate' => null,
);
}
}
$view->set_access($access);
db_commit();
return $view;
......
......@@ -142,6 +142,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
}
}
$smarty->assign('viewtype', $element['viewtype']);
$smarty->assign('potentialpresets', json_encode($potentialpresets));
$smarty->assign('loggedinindex', $loggedinindex);
$smarty->assign('accesslist', json_encode($value));
......
......@@ -228,6 +228,12 @@ class Institution {
require_once('activity.php');
activity_occurred('maharamessage', $message);
handle_event('updateuser', $userinst->usr);
// Give institution members access to user's profile page
require_once('view.php');
$profileview = $userobj->get_profile_view();
$profileview->add_owner_institution_access(array($this->name));
db_commit();
}
......
......@@ -606,7 +606,7 @@ class View {
*/
public function get_access($timeformat=null) {
if ($data = $this->get_access_records()) {
return self::process_access_records($data, $timeformat);
return $this->process_access_records($data, $timeformat);
}
return array();
}
......@@ -627,7 +627,7 @@ class View {
return $data ? $data : array();
}
public static function process_access_records($data=array(), $timeformat=null) {
public function process_access_records($data=array(), $timeformat=null) {
$rolegroups = array();
foreach ($data as &$item) {
if ($item->role && !isset($roledata[$item->group])) {
......@@ -658,6 +658,13 @@ class View {
else if ($item['institution']) {
$item['type'] = 'institution';
$item['id'] = $item['institution'];
if ($this->type == 'profile') {
$myinstitutions = array_keys(load_user_institutions($this->owner));
if (in_array($item['id'], $myinstitutions) && empty($item['startdate']) && empty($item['stopdate'])) {
$item['locked'] = true;
}
}
}
else {
$item['type'] = $item['accesstype'];
......@@ -955,6 +962,30 @@ class View {
db_commit();
}
public function add_owner_institution_access($instnames=array()) {
if (!$this->id) {
return false;
}
$institutions = empty($instnames) ? array_keys(load_user_institutions($this->owner)) : $instnames;
if (!empty($institutions)) {
db_begin();
foreach ($institutions as $i) {
$vaccess = new stdClass;
$vaccess->view = $this->id;
$vaccess->institution = $i;
$vaccess->startdate = null;
$vaccess->stopdate = null;
$vaccess->allowcomments = 0;
$vaccess->approvecomments = 1;
ensure_record_exists('view_access', $vaccess, $vaccess);
}
db_commit();
}
return true;
}
public function get_autocreate_grouptypes() {
if (!isset($this->copynewgroups)) {
......
......@@ -125,12 +125,18 @@ 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();
}
$allowcomments = $view->get('allowcomments');
$form['elements']['accesslist'] = array(
'type' => 'viewacl',
'allowcomments' => $allowcomments,
'defaultvalue' => $view->get_access(get_string('strftimedatetimeshort')),
'viewtype' => $view->get('type'),
);
......@@ -533,6 +539,11 @@ function editaccess_submit(Pieform $form, $values) {
if (!empty($toupdate)) {
View::update_view_access($viewconfig, $toupdate);
if ($view->get('type') == 'profile') {
// Ensure the user's institutions are still added to the access list
$view->add_owner_institution_access();
}
}
$SESSION->add_ok_msg(get_string('updatedaccessfornumviews', 'view', count($toupdate)));
......
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