diff --git a/src/components/com_cluster/administrator/models/clusters.php b/src/components/com_cluster/administrator/models/clusters.php index 25ac53d..803e2af 100644 --- a/src/components/com_cluster/administrator/models/clusters.php +++ b/src/components/com_cluster/administrator/models/clusters.php @@ -58,7 +58,7 @@ protected function getListQuery() $query = $db->getQuery(true); // Create the base select statement. - $query->select(array('cl.*','users.name as uname')); + $query->select(array('cl.*','users.name as uname','cl.id as cluster_id')); $query->from($db->quoteName('#__tj_clusters', 'cl')); $query->join('LEFT', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cl.created_by') . ' = ' . $db->quoteName('users.id') . ')'); diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 3357797..15b46de 100644 --- a/src/components/com_cluster/administrator/models/clusteruser.php +++ b/src/components/com_cluster/administrator/models/clusteruser.php @@ -131,11 +131,13 @@ public function getUsersClusters($userId = null) JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); // If user is not allowed to view all the clusters then return the clusters in which user is a part else return al cluster - if (!$user->authorise('core.manageall.cluster', 'com_cluster')) + if (!$user->authorise('core.manageall', 'com_cluster')) { $clusterUsersModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); $clusterUsersModel->setState('list.group_by_client_id', 1); $clusterUsersModel->setState('filter.published', 1); + $clusterUsersModel->setState('list.ordering', 'cl.name'); + $clusterUsersModel->setState('list.direction', 'ASC'); $clusterUsersModel->setState('filter.user_id', $user->id); // Get all assigned cluster entries @@ -147,6 +149,8 @@ public function getUsersClusters($userId = null) // Get all cluster entries $clusterModel->setState('filter.state', 1); + $clusterModel->setState('list.ordering', 'cl.name'); + $clusterModel->setState('list.direction', 'ASC'); $clusters = $clusterModel->getItems(); } @@ -162,12 +166,12 @@ public function getUsersClusters($userId = null) if (!empty($clusters)) { - if ($subUserExist && (!$user->authorise('core.manageall.cluster', 'com_cluster'))) + if ($subUserExist && (!$user->authorise('core.manageall', 'com_cluster'))) { foreach ($clusters as $cluster) { // Check user has permission for mentioned cluster - if (RBACL::authorise($user->id, 'com_cluster', 'core.manage.cluster', $cluster->id)) + if (RBACL::authorise($user->id, 'com_cluster', 'core.manage', $cluster->cluster_id)) { $usersClusters[] = $cluster; } diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 1e5ebfa..c4de463 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -62,24 +62,6 @@ protected function getListQuery() . $db->quoteName('users.id') . ')'); $query->join('INNER', $db->quoteName('#__tj_clusters', 'cl') . ' ON (' . $db->quoteName('cl.id') . ' = ' . $db->quoteName('cu.cluster_id') . ')'); - // Get com_subusers component status - $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; - - if ($subUserExist) - { - $roleId = $this->getState('filter.role_id'); - - if (is_numeric($roleId)) - { - $query->join('INNER', $db->qn('#__tjsu_users', 'su') . - ' ON (' . $db->qn('users.id') . ' = ' . $db->qn('su.user_id') . ' AND ' . $db->qn('su.client') . ' = "com_multiagency" )'); - $query->join('INNER', $db->qn('#__tjsu_roles', 'r') . - ' ON (' . $db->qn('r.id') . ' = ' . $db->qn('su.role_id') . ' AND ' . $db->qn('r.state') . ' = 1 )'); - - $query->where($db->quoteName('su.role_id') . ' != ' . (int) $roleId); - } - } - // Filter by search in title. $search = $this->getState('filter.search'); diff --git a/src/components/com_cluster/site/controllers/clusterusers.json.php b/src/components/com_cluster/site/controllers/clusterusers.json.php new file mode 100644 index 0000000..2753758 --- /dev/null +++ b/src/components/com_cluster/site/controllers/clusterusers.json.php @@ -0,0 +1,73 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Response\JsonResponse; +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Session\Session; + +JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + +/** + * Get Cluster Users controller class. + * + * @since 1.0.0 + */ +class ClusterControllerClusterUsers extends BaseController +{ + /** + * Method to get user list depending on the client chosen. + * + * @return null + * + * @since 1.0.0 + */ + public function getUsersByClientId() + { + $app = Factory::getApplication(); + + // Check for request forgeries. + if (!Session::checkToken()) + { + echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true); + $app->close(); + } + + $clusterIds = $app->input->getInt('cluster_id', 0); + $userOptions = $allUsers = array(); + + // Initialize array to store dropdown options + $userOptions[] = HTMLHelper::_('select.option', "", Text::_('COM_CLUSTER_OWNERSHIP_USER')); + + // Check cluster selected or not + if ($clusterIds) + { + $clusterObj = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); + $clusterObj->setState('filter.block', 0); + $clusterObj->setState('filter.cluster_id', $clusterIds); + $clusterObj->setState('list.group_by_user_id', 1); + $allUsers = $clusterObj->getItems(); + } + + if (!empty($allUsers)) + { + foreach ($allUsers as $user) + { + $userOptions[] = HTMLHelper::_('select.option', $user->user_id, trim($user->uname . ' (' . $user->uemail . ')')); + } + } + + echo new JsonResponse($userOptions); + $app->close(); + } +}