Skip to content

Commit

Permalink
Task #14 chore: Improvement made in cluster package (#15)
Browse files Browse the repository at this point in the history
Task #14 chore: Improvement made in cluster package
  • Loading branch information
thite-amol authored Oct 14, 2019
2 parents 5cc9683 + ef93b1b commit 1a26a5b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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') . ')');

Expand Down
10 changes: 7 additions & 3 deletions src/components/com_cluster/administrator/models/clusteruser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand All @@ -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;
}
Expand Down
18 changes: 0 additions & 18 deletions src/components/com_cluster/administrator/models/clusterusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
73 changes: 73 additions & 0 deletions src/components/com_cluster/site/controllers/clusterusers.json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* @package Com_Cluster
* @author Techjoomla <[email protected]>
* @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();
}
}

0 comments on commit 1a26a5b

Please sign in to comment.