Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/administrator/models/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ public function getAssignedRoles($actionId)

$query->select('DISTINCT role_id');
$query->from($db->quoteName('#__tjsu_role_action_map'));
$query->where($db->quoteName('action_id') . " = " . (int) $actionId);

if (is_array($actionId))
{
$query->where($db->quoteName('action_id') . 'IN (' . implode(',', $db->quote($actionId)) . ')');
}
else
{
$query->where($db->quoteName('action_id') . " = " . (int) $actionId);
}

$db->setQuery($query);

return $db->loadColumn();
Expand Down
42 changes: 42 additions & 0 deletions src/administrator/models/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Factory;

/**
* Subusers model.
Expand Down Expand Up @@ -154,4 +155,45 @@ public function save($data)

return true;
}

/**
* Method to get a roles by actions.
*
* @param array $actions array of action code.
* @param string $client name of action client.
* @param int $clientId client id.
*
* @return array indexed array of associated arrays.
*
* @since __DEPLOY__VERSION__
*/
public function getAuthorizeRoles($actions = array(), $client = null, $clientId = null)
{
if (!empty($actions))
{
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(('id')));
$query->from($db->quoteName('#__tjsu_actions'));

if ($client)
{
$query->where($db->quoteName('client') . ' = ' . $db->quote($client));
}

foreach ($actions as $action)
{
$query->where($db->quoteName('code') . ' = ' . $db->quote($action));
}

$db->setQuery($query);

$actionIds = $db->loadColumn();

// Get role ids by providing action ids
$actionModel = RBACL::model("action");

return $actionModel->getAssignedRoles($actionIds);
}
}
}
35 changes: 32 additions & 3 deletions src/administrator/models/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ protected function getListQuery()
$db = $this->getDbo();
$query = $db->getQuery(true);

$query->select(array('a.*', 'uc.name', 'rl.name as rolename'));
$query->select(array('a.*', 'uc.name','uc.email', 'rl.name as rolename'));
$query->from('`#__tjsu_users` AS a');
$query->join('INNER', $db->quoteName('#__users', 'uc') . ' ON (' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('uc.id') . ')');
$query->join('INNER', $db->quoteName('#__tjsu_roles', 'rl') . ' ON (' . $db->quoteName('rl.id') . ' = ' . $db->quoteName('a.role_id') . ')');
$search = $this->getState('filter.search');

// If the model is set to check item state, add to the query.
$state = $this->getState('filter.state');

if (is_numeric($state))
{
$query->where('uc.block = ' . (int) $state);
}

if (!empty($search))
{
if (stripos($search, 'id:') === 0)
Expand All @@ -125,7 +133,14 @@ protected function getListQuery()

if (!empty($roleId))
{
$query->where($db->quoteName('a.role_id') . " = " . (int) $roleId);
if (is_array($roleId))
{
$query->where($db->quoteName('a.role_id') . 'IN (' . implode(',', $db->quote($roleId)) . ')');
}
else
{
$query->where($db->quoteName('a.role_id') . " = " . (int) $roleId);
}
}

$client = $this->getState('filter.client');
Expand All @@ -139,7 +154,21 @@ protected function getListQuery()

if (!empty($clientId))
{
$query->where($db->quoteName('a.client_id') . " = " . (int) $clientId);
if (is_array($clientId))
{
$query->where($db->quoteName('a.client_id') . 'IN (' . implode(',', $db->quote($clientId)) . ')');
}
else
{
$query->where($db->quoteName('a.client_id') . " = " . (int) $clientId);
}
}

$groupBy = $this->getState('group_by');

if (!empty($groupBy))
{
$query->group($db->quoteName('a.' . $groupBy));
}

$orderCol = $this->state->get('list.ordering');
Expand Down