Skip to content

Commit

Permalink
Task #114 feat: Cluster awareness in related field
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush-maherwal committed Aug 19, 2019
1 parent a19167d commit a89059f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/components/com_cluster/administrator/models/clusteruser.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ public function save($data)
*
* @since 1.0.0
*/
public function getUsersClusters($userId)
public function getUsersClusters($userId = null)
{
$user = Factory::getUser($userId);
$superUser = $user->authorise('core.admin');
$user = empty($userId) ? Factory::getUser() : Factory::getUser($userId);

$clusters = array();

// Load cluster library file
JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR);

if (!$superUser && !$user->authorise('core.manageall.cluster', 'com_cluster'))
// 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'))
{
$clusterUsersModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true));
$clusterUsersModel->setState('list.group_by_client_id', 1);
Expand All @@ -141,9 +141,9 @@ public function getUsersClusters($userId)
// Get all assigned cluster entries
$clusters = $clusterUsersModel->getItems();
}

if ($superUser)
else
{
$clusterModel = $this->setState('filter.state', 1);
$clusterModel = ClusterFactory::model('Clusters', array('ignore_request' => true));

// Get all cluster entries
Expand All @@ -162,7 +162,7 @@ public function getUsersClusters($userId)

if (!empty($clusters))
{
if ($subUserExist && (!$superUser && !$user->authorise('core.manageall.cluster', 'com_cluster')))
if ($subUserExist && (!$user->authorise('core.manageall.cluster', 'com_cluster')))
{
foreach ($clusters as $cluster)
{
Expand Down
12 changes: 6 additions & 6 deletions src/components/com_cluster/administrator/models/clusterusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ protected function getListQuery()
}
}

$created_by = $this->getState('filter.created_by');
$createdBy = $this->getState('filter.created_by');

if (!empty($created_by))
if (!empty($createdBy))
{
$query->where($db->quoteName('cu.created_by') . ' = ' . (int) $created_by);
$query->where($db->quoteName('cu.created_by') . ' = ' . (int) $createdBy);
}

// Filter by state
Expand All @@ -103,11 +103,11 @@ protected function getListQuery()
}

// Filter by user
$cluster_user = $this->getState('filter.user_id');
$clusterUser = $this->getState('filter.user_id');

if (is_numeric($cluster_user))
if (is_numeric($clusterUser))
{
$query->where('cu.user_id = ' . (int) $cluster_user);
$query->where('cu.user_id = ' . (int) $clusterUser);
}

// Filter by client_id
Expand Down

0 comments on commit a89059f

Please sign in to comment.