Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit c04240b

Browse files
committed
ENH: refs #445. Private user should be allowed to view their own userpage
Added a test to make sure this is true. Also made it so that a private user will now see himself in the user index list.
1 parent d525741 commit c04240b

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

core/controllers/UserController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function indexAction()
4444

4545
$order = $this->_getParam('order');
4646
$offset = $this->_getParam('offset');
47+
4748
if(!isset($order))
4849
{
4950
$order = 'view';
@@ -59,7 +60,7 @@ function indexAction()
5960
}
6061
else
6162
{
62-
$users = $this->User->getAll(true, 100, $order, $offset);
63+
$users = $this->User->getAll(true, 100, $order, $offset, $this->userSession->Dao);
6364
}
6465

6566
$this->view->order = $order;
@@ -668,7 +669,9 @@ public function userpageAction()
668669
else
669670
{
670671
$userDao = $this->User->load($user_id);
671-
if($userDao->getPrivacy() == MIDAS_USER_PRIVATE && (!isset($this->userSession->Dao) || !$this->userSession->Dao->isAdmin()))
672+
if($userDao->getPrivacy() == MIDAS_USER_PRIVATE &&
673+
(!$this->logged || $this->userSession->Dao->getKey() != $userDao->getKey()) &&
674+
(!isset($this->userSession->Dao) || !$this->userSession->Dao->isAdmin()))
672675
{
673676
throw new Zend_Exception("Permission error");
674677
}

core/models/base/UserModelBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ abstract function getByUuid($uuid);
6767
/** Returns a user given its folder (either public,private or base folder) */
6868
abstract function getByFolder($folder);
6969
/** Returns all the users */
70-
abstract function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset = null);
70+
abstract function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset = null, $currentUser = null);
7171

7272
/** save */
7373
public function save($dao)
@@ -226,4 +226,4 @@ public function getGravatarUrl($email, $s = 32, $d = '404', $r = 'g', $img = fal
226226
}
227227
return $url;
228228
}
229-
} // end class UserModelBase
229+
} // end class UserModelBase

core/models/pdo/UserModel.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,31 @@ public function getUserCommunities($userDao)
8383
} // end getUserCommunities
8484

8585
/** Get all */
86-
function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset = null)
86+
function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset = null, $currentUser = null)
8787
{
8888
$sql = $this->database->select();
8989
if($onlyPublic)
9090
{
91-
$sql ->where('privacy = ?', MIDAS_USER_PUBLIC);
91+
$orClause = '';
92+
if($currentUser !== null && $currentUser->getPrivacy() == MIDAS_USER_PRIVATE)
93+
{
94+
$orClause = ' OR '.$this->database->getDB()->quoteInto('user_id = ? ', $currentUser->getUserId());
95+
}
96+
$sql->where('privacy = ?'.$orClause, MIDAS_USER_PUBLIC);
9297
}
9398

9499
if($offset == null)
95100
{
96-
$sql ->limit($limit);
101+
$sql->limit($limit);
97102
}
98103
elseif(!is_numeric($offset))
99104
{
100-
$sql ->where('lastname LIKE ?', $offset.'%');
101-
$sql ->limit($limit);
105+
$sql->where('lastname LIKE ?', $offset.'%');
106+
$sql->limit($limit);
102107
}
103108
else
104109
{
105-
$sql ->limit($limit, $offset);
110+
$sql->limit($limit, $offset);
106111
}
107112
switch($order)
108113
{
@@ -127,6 +132,7 @@ function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset =
127132
}
128133
return $return;
129134
} // end getAll()
135+
130136
/** Get admins */
131137
function getAdmins()
132138
{

core/tests/controllers/UserControllerTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,29 @@ public function testUserpageAction()
237237
$this->resetAll();
238238
$usersFile = $this->loadData('User', 'default');
239239
$userDao = $this->User->load($usersFile[0]->getKey());
240-
$this->dispatchUrI("/user/userpage", $userDao);
240+
$this->dispatchUrI('/user/userpage', $userDao);
241241

242242
$this->assertQuery('div.genericInfo');
243243

244244
$folder = $userDao->getPublicFolder();
245245
$this->assertQuery("tr[element='".$folder->getKey()."']");
246246

247-
$this->params = array();
248-
$this->params['user_id'] = $userDao->getKey();
249-
$this->dispatchUrI("/user/userpage", null, false);
247+
// Should be able to see this user page since user is public
248+
$this->resetAll();
249+
$this->dispatchUrI('/user/'.$userDao->getKey(), null);
250250

251251
$userDao->setPrivacy(MIDAS_USER_PRIVATE);
252252
$this->User->save($userDao);
253253

254-
$this->dispatchUrI("/user/userpage", null, true);
254+
// Should throw an exception since the user is now private
255+
$this->resetAll();
256+
$this->dispatchUrI('/user/'.$userDao->getKey(), null, true);
257+
258+
// Private user should be able to view his own user page
259+
$this->resetAll();
260+
$this->dispatchUrI('/user/'.$userDao->getKey(), $userDao);
261+
$this->assertController('user');
262+
$this->assertAction('userpage');
255263
}
256264

257265
/** test validentry */

0 commit comments

Comments
 (0)