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. 36
      app/Libraries/Aauth.php
  2. 8
      tests/Aauth/Libraries/Aauth/UserTest.php

36
app/Libraries/Aauth.php

@ -42,6 +42,13 @@ class Aauth
*/
protected $config;
/**
* Variable for loading the app config array into
*
* @var \Config\App
*/
protected $configApp;
/**
* Variable for loading the session service into
*
@ -112,6 +119,7 @@ class Aauth
$session = \Config\Services::session();
}
$this->configApp = new \Config\App();
$this->config = $config;
$this->session = $session;
}
@ -718,6 +726,7 @@ class Aauth
*
* Return users as an object array
*
* @param string|integer $groupPar Specify group id to list group or null for all users
* @param integer $limit Limit of users to be returned
* @param integer $offset Offset for limited number of users
* @param boolean $includeBanneds Include banned users
@ -725,25 +734,30 @@ class Aauth
*
* @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();
$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');
// 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))
{
$user->where('banned', 0);
$userModel->where('banned', 0);
}
if (! is_null($orderBy))
{
$user->orderBy($orderBy);
$userModel->orderBy($orderBy);
}
return $user->findAll();
return $userModel->findAll();
}
/**
@ -751,6 +765,7 @@ class Aauth
*
* Return users as an object array
*
* @param string|integer $groupPar Specify group id to list group or null for all users
* @param integer $limit Limit of users to be returned
* @param integer $offset Offset for limited number of users
* @param boolean $includeBanneds Include banned users
@ -758,12 +773,17 @@ class Aauth
*
* @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->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))
{

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

@ -158,9 +158,11 @@ class UserTest extends CIDatabaseTestCase
$this->assertEquals('admin', $users[0]['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('admin', $usersOrderBy[1]['username']);
$this->assertCount(1, $this->library->listUsers($this->config->groupAdmin));
}
public function testListUsersPaginated()
@ -171,9 +173,11 @@ class UserTest extends CIDatabaseTestCase
$this->assertEquals('admin', $users['users'][0]['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('admin', $usersOrderBy['users'][1]['username']);
$this->assertCount(1, $this->library->listUsersPaginated($this->config->groupAdmin)['users']);
}
public function testVerifyUser()

Loading…
Cancel
Save