Commit dfbdc067 authored by Robert Lyon's avatar Robert Lyon

Bug 1523298: Make get_owner_object() return LiveUser object

This way we can avoid re-making it multiple times further down the
chain.

Most places where the get_owner_object() object was passed can handle
dealing with a User object vs a StdObject anyway.

behatnotneeded - existing tests should suffice

Change-Id: I2b92d9e408066a9c3b4c2f0bb87fbe8370bf9911
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit 2bcebcd4)
parent 3645d7d8
......@@ -33,7 +33,7 @@ $smarty->assign('displayname', display_name($owner));
$smarty->assign('instanceid', $instanceid);
$smarty->assign('owner', $owner);
$smarty->assign('wholewall', true);
$smarty->assign('ownwall', (!empty($USER) && $USER->get('id') == $owner->id));
$smarty->assign('ownwall', (!empty($USER) && $USER->get('id') == $owner->get('id')));
if ($posts = PluginBlocktypeWall::fetch_posts($block, true)) {
$smarty->assign('wallposts', $posts);
}
......
......@@ -62,10 +62,10 @@ if (!function_exists('checkdnsrr')) {
/**
* Check whether a user is on probation.
* @param int $userid
* @param int/object $user
* @return boolean TRUE if the user is on probation, FALSE if the user is not on probation
*/
function is_probationary_user($userid = null) {
function is_probationary_user($user = null) {
global $USER;
// Check whether a new user threshold is in place or not.
......@@ -74,12 +74,15 @@ function is_probationary_user($userid = null) {
}
// Get the user's information
if ($userid == null) {
$user = $USER;
}
else {
$user = new User();
$user->find_by_id($userid);
if (!($user instanceof User)) {
if ($user == null) {
$user = $USER;
}
else {
$userobj = new User();
$userobj->find_by_id($user);
$user = $userobj;
}
}
// Admins and staff get a free pass
......
......@@ -2356,8 +2356,8 @@ function can_view_view($view, $user_id=null) {
$ownerobj = $view->get_owner_object();
// Suspended user
if ($ownerobj->suspendedctime) {
// If the view's owner is suspended, deny access to the view
if (empty($ownerobj) || $ownerobj->get('suspendedctime')) {
return false;
}
......@@ -2365,16 +2365,14 @@ function can_view_view($view, $user_id=null) {
// (setting these here instead of doing a return-false, so that we can do checks for
// logged-in users later)
require_once(get_config('libroot') . 'antispam.php');
$onprobation = is_probationary_user($ownerobj->id);
$onprobation = is_probationary_user($ownerobj);
$publicviews = $publicviews && !$onprobation;
$publicprofiles = $publicprofiles && !$onprobation;
// Member of an institution that prohibits public pages
// (group views and logged in users are not affected by
// the institution level config for public views)
$owner = new User();
$owner->find_by_id($ownerobj->id);
$publicviews = $publicviews && $owner->institution_allows_public_views();
$publicviews = $publicviews && $ownerobj->institution_allows_public_views();
}
// Now that we've examined the page owner, check again for whether it can be viewed by a logged-out user
......@@ -2386,13 +2384,6 @@ function can_view_view($view, $user_id=null) {
return true;
}
// If the view's owner is suspended, deny access to the view
if ($view->get('owner')) {
if ((!$owner = $view->get_owner_object()) || $owner->suspendedctime) {
return false;
}
}
if ($SESSION->get('mnetuser')) {
$mnettoken = get_cookie('mviewaccess:' . $view_id);
}
......
......@@ -816,7 +816,10 @@ class View {
return false;
}
if (!isset($this->ownerobj)) {
$this->ownerobj = get_user_for_display($this->get('owner'));
// $this->ownerobj = get_user_for_display($this->get('owner'));
$user = new User();
$user->find_by_id($this->get('owner'));
$this->ownerobj = $user;
}
return $this->ownerobj;
}
......@@ -2797,6 +2800,7 @@ class View {
if ($this->get('owner')) {
$user = $this->get_owner_object();
$user = get_user_for_display($user);
switch ($this->ownerformat) {
case FORMAT_NAME_FIRSTNAME:
......@@ -5806,7 +5810,7 @@ class View {
$url = 'group/view.php?id=' . $this->group;
}
else if (!$useid && !is_null($this->urlid) && get_config('cleanurls')) {
if ($this->owner && !is_null($this->get_owner_object()->urlid)) {
if ($this->owner && !is_null($this->get_owner_object()->get('urlid'))) {
return profile_url($this->ownerobj, $full) . '/' . $this->urlid;
}
else if ($this->group && !is_null($this->get_group_object()->urlid)) {
......@@ -5884,10 +5888,7 @@ class View {
// a group view won't have an 'owner'
if ($publicviews && $ownerobj = $this->get_owner_object()) {
$owner = new User();
$owner->find_by_id($ownerobj->id);
$publicviews = $owner->institution_allows_public_views();
$publicviews = $ownerobj->institution_allows_public_views();
}
$allowcomments = false;
......
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