Browse Source

updated Libraries/Aauth & UserTest

- added $this->configApp
- enhanced `listUsers()` & `listUsersPaginated()` with $groupPar
v3-dev
REJack 6 years ago
parent
commit
aca63f8e2a
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 56
      app/Libraries/Aauth.php
  2. 8
      tests/Aauth/Libraries/Aauth/UserTest.php

56
app/Libraries/Aauth.php

@ -42,6 +42,13 @@ class Aauth
*/ */
protected $config; protected $config;
/**
* Variable for loading the app config array into
*
* @var \Config\App
*/
protected $configApp;
/** /**
* Variable for loading the session service into * Variable for loading the session service into
* *
@ -112,8 +119,9 @@ class Aauth
$session = \Config\Services::session(); $session = \Config\Services::session();
} }
$this->config = $config; $this->configApp = new \Config\App();
$this->session = $session; $this->config = $config;
$this->session = $session;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -718,32 +726,38 @@ class Aauth
* *
* Return users as an object array * Return users as an object array
* *
* @param integer $limit Limit of users to be returned * @param string|integer $groupPar Specify group id to list group or null for all users
* @param integer $offset Offset for limited number of users * @param integer $limit Limit of users to be returned
* @param boolean $includeBanneds Include banned users * @param integer $offset Offset for limited number of users
* @param string $orderBy Order by MYSQL string (e.g. 'name ASC', 'email DESC') * @param boolean $includeBanneds Include banned users
* @param string $orderBy Order by MYSQL string (e.g. 'name ASC', 'email DESC')
* *
* @return array Array of users * @return array Array of users
*/ */
public function listUsers(int $limit = 0, int $offset = 0, bool $includeBanneds = null, string $orderBy = null) public function listUsers($groupPar = null, int $limit = 0, int $offset = 0, bool $includeBanneds = null, string $orderBy = null)
{ {
$userModel = new UserModel(); $userModel = new UserModel();
$user = $userModel->limit($limit, $offset); $userModel->limit($limit, $offset);
$userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login'); $userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login');
// eanbool $groupPar = null,
if ($groupPar && $groupId = $this->getGroupId($groupPar))
{
$userModel->join($this->config->dbTableGroupToUser, $this->config->dbTableGroupToUser . '.user_id = ' . $this->config->dbTableUsers . '.id');
$userModel->where($this->config->dbTableGroupToUser . '.group_id', $groupId);
}
if (is_null($includeBanneds)) if (is_null($includeBanneds))
{ {
$user->where('banned', 0); $userModel->where('banned', 0);
} }
if (! is_null($orderBy)) if (! is_null($orderBy))
{ {
$user->orderBy($orderBy); $userModel->orderBy($orderBy);
} }
return $user->findAll(); return $userModel->findAll();
} }
/** /**
@ -751,19 +765,25 @@ class Aauth
* *
* Return users as an object array * Return users as an object array
* *
* @param integer $limit Limit of users to be returned * @param string|integer $groupPar Specify group id to list group or null for all users
* @param integer $offset Offset for limited number of users * @param integer $limit Limit of users to be returned
* @param boolean $includeBanneds Include banned users * @param integer $offset Offset for limited number of users
* @param string $orderBy Order by MYSQL string (e.g. 'name ASC', 'email DESC') * @param boolean $includeBanneds Include banned users
* @param string $orderBy Order by MYSQL string (e.g. 'name ASC', 'email DESC')
* *
* @return array Array of users * @return array Array of users
*/ */
public function listUsersPaginated(int $limit = 10, bool $includeBanneds = null, string $orderBy = null) public function listUsersPaginated($groupPar = null, int $limit = 10, bool $includeBanneds = null, string $orderBy = null)
{ {
$userModel = new UserModel(); $userModel = new UserModel();
$userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login'); $userModel->select('id, email, username, banned, created_at, updated_at, last_activity, last_ip_address, last_login');
// eanbool $groupPar = null,
if ($groupPar && $groupId = $this->getGroupId($groupPar))
{
$userModel->join($this->config->dbTableGroupToUser, $this->config->dbTableGroupToUser . '.user_id = ' . $this->config->dbTableUsers . '.id');
$userModel->where($this->config->dbTableGroupToUser . '.group_id', $groupId);
}
if (is_null($includeBanneds)) if (is_null($includeBanneds))
{ {

8
tests/Aauth/Libraries/Aauth/UserTest.php

@ -158,9 +158,11 @@ class UserTest extends CIDatabaseTestCase
$this->assertEquals('admin', $users[0]['username']); $this->assertEquals('admin', $users[0]['username']);
$this->assertEquals('user', $users[1]['username']); $this->assertEquals('user', $users[1]['username']);
$usersOrderBy = $this->library->listUsers(0, 0, null, 'id DESC'); $usersOrderBy = $this->library->listUsers(null, 0, 0, null, 'id DESC');
$this->assertEquals('user', $usersOrderBy[0]['username']); $this->assertEquals('user', $usersOrderBy[0]['username']);
$this->assertEquals('admin', $usersOrderBy[1]['username']); $this->assertEquals('admin', $usersOrderBy[1]['username']);
$this->assertCount(1, $this->library->listUsers($this->config->groupAdmin));
} }
public function testListUsersPaginated() public function testListUsersPaginated()
@ -171,9 +173,11 @@ class UserTest extends CIDatabaseTestCase
$this->assertEquals('admin', $users['users'][0]['username']); $this->assertEquals('admin', $users['users'][0]['username']);
$this->assertEquals('user', $users['users'][1]['username']); $this->assertEquals('user', $users['users'][1]['username']);
$usersOrderBy = $this->library->listUsersPaginated(10, null, 'id DESC'); $usersOrderBy = $this->library->listUsersPaginated(null, 10, null, 'id DESC');
$this->assertEquals('user', $usersOrderBy['users'][0]['username']); $this->assertEquals('user', $usersOrderBy['users'][0]['username']);
$this->assertEquals('admin', $usersOrderBy['users'][1]['username']); $this->assertEquals('admin', $usersOrderBy['users'][1]['username']);
$this->assertCount(1, $this->library->listUsersPaginated($this->config->groupAdmin)['users']);
} }
public function testVerifyUser() public function testVerifyUser()

Loading…
Cancel
Save