From d4eff8bf8125e9e6ef76a21d10a93346b9bddc8d Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Tue, 20 Aug 2019 18:48:28 +0530 Subject: [PATCH 1/4] #12 chore: Update query, added joins based on filters & introduce new ACL --- .../com_cluster/administrator/access.xml | 2 + .../languages/en-GB/en-GB.com_cluster.ini | 5 + .../languages/en-GB/en-GB.com_cluster.sys.ini | 3 +- .../administrator/libraries/cluster.php | 30 +++++ .../administrator/models/clusterusers.php | 44 +++++--- .../administrator/models/forms/cluster.xml | 103 +++++++++++++++--- .../models/forms/clusteruser.xml | 90 ++++++++++++--- .../models/forms/filter_clusters.xml | 31 +++++- .../models/forms/filter_clusterusers.xml | 43 +++++++- 9 files changed, 288 insertions(+), 63 deletions(-) diff --git a/src/components/com_cluster/administrator/access.xml b/src/components/com_cluster/administrator/access.xml index aa5a2bb..e558b09 100644 --- a/src/components/com_cluster/administrator/access.xml +++ b/src/components/com_cluster/administrator/access.xml @@ -8,5 +8,7 @@ + + diff --git a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini index 1a0d1d8..2a11773 100644 --- a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini +++ b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini @@ -92,3 +92,8 @@ COM_CLUSTER_PAGE_VIEW_USER = "Cluster user: View" COM_CLUSTER_USER_LIST_VIEW_NAME="User" COM_CLUSTER_USER_LIST_VIEW_CLUSTER="Cluster Name" COM_CLUSTER_USERLIST_VIEW_ID="ID" + +JACTION_MANAGE_ALL_CLUSTER="Manage All Clusters" +JACTION_MANAGE_ALL_CLUSTER_DESC="Manage All Clusters" +JACTION_MANAGE_OWN_CLUSTER="Manage Own Cluster" +JACTION_MANAGE_OWN_CLUSTER_DESC="Manage Own Cluster" diff --git a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini index e2bca07..11d9fcd 100644 --- a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini +++ b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini @@ -7,4 +7,5 @@ COM_CLUSTER_CLUSTER_VIEW_EDIT_DESC="Shows a form to create a New Cluster." COM_CLUSTER_CLUSTERS_VIEW_DEFAULT_TITLE="List all Clusters" COM_CLUSTER_CLUSTERS_VIEW_DEFAULT_DESC="Shows a list of all the Clusters." COM_CLUSTER_TITLE_ITEM_VIEW_CLUSTER="Single Cluster" -COM_CLUSTER_TITLE_CLUSTER="Cluster" \ No newline at end of file +COM_CLUSTER_TITLE_CLUSTER="Cluster" +COM_CLUSTERS_VIEW_CLUSTER_USERS="Cluster users" diff --git a/src/components/com_cluster/administrator/libraries/cluster.php b/src/components/com_cluster/administrator/libraries/cluster.php index 8ee5279..3052c92 100644 --- a/src/components/com_cluster/administrator/libraries/cluster.php +++ b/src/components/com_cluster/administrator/libraries/cluster.php @@ -231,4 +231,34 @@ public function isOwner($userId = null) return false; } + + /** + * Function isMember to check user associated with passed cluster_id + * + * @param INT $userId User Id + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function isMember($userId = null) + { + $userId = Factory::getuser($userId)->id; + + $ClusterModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); + + $ClusterModel->setState('filter.published', 1); + $ClusterModel->setState('filter.cluster_id', (int) $this->id); + $ClusterModel->setState('filter.user_id', $userId); + + // Check user associated with passed cluster_id + $clusters = $ClusterModel->getItems(); + + if (!empty($clusters)) + { + return true; + } + + return false; + } } diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 005c8ea..3af0513 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -10,7 +10,9 @@ // No direct access to this file defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Component\ComponentHelper; /** * Methods supporting a list of records. @@ -34,7 +36,7 @@ public function __construct($config = array()) $config['filter_fields'] = array( 'id', 'cu.id', 'cluster_id', 'cu.cluster_id', - 'state', 'cu.state', + 'state', 'cu.state','cl.name','cl.client_id' ); } @@ -54,32 +56,38 @@ protected function getListQuery() $db = $this->getDbo(); $query = $db->getQuery(true); - $query->select(array('cu.*','cl.name', 'users.name as uname')); + $query->select(array('cu.*','cl.name', 'users.name as uname', 'users.username','cl.name as title', 'cl.client_id as client_id')); $query->from($db->quoteName('#__tj_cluster_nodes', 'cu')); - $query->join('INNER', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cu.user_id') . ' = ' . $db->quoteName('users.id') . ')'); + $query->join('INNER', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cu.user_id') . ' = ' + . $db->quoteName('users.id') . ')'); $query->join('INNER', $db->quoteName('#__tj_clusters', 'cl') . ' ON (' . $db->quoteName('cl.id') . ' = ' . $db->quoteName('cu.cluster_id') . ')'); - // Filter by search in title. - $search = $this->getState('filter.search'); + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; - if (!empty($search)) + if ($subUserExist) { - if (stripos($search, 'id:') === 0) - { - $query->where('cu.id = ' . (int) substr($search, 3)); - } - else + $roleId = $this->getState('filter.role_id'); + + if (is_numeric($roleId)) { - $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); - $query->where('(users.name LIKE' . $search . ' OR cl.name LIKE ' . $search . ')'); + $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); } } - $createdBy = $this->getState('filter.created_by'); + // Filter by search in title. + $search = $this->getState('filter.search'); - if (!empty($createdBy)) + $created_by = $this->getState('filter.created_by'); + + if (!empty($created_by)) { - $query->where($db->quoteName('cu.created_by') . ' = ' . (int) $createdBy); + $query->where($db->quoteName('cu.created_by') . ' = ' . (int) $created_by); } // Filter by state @@ -122,7 +130,7 @@ protected function getListQuery() $query->where("cl.client_id IN ('" . implode("','", $clusterClientId) . "')"); } - // Filter by state + // Filter by cluster table state $published = $this->getState('filter.published'); if (is_numeric($published)) @@ -134,7 +142,7 @@ protected function getListQuery() $query->where('(cl.state = 0 OR cl.state = 1)'); } - // Filter by blocked users + // Filter users by block $blockUser = $this->getState('filter.block'); if (is_numeric($blockUser)) diff --git a/src/components/com_cluster/administrator/models/forms/cluster.xml b/src/components/com_cluster/administrator/models/forms/cluster.xml index 387d57c..fe0e06b 100644 --- a/src/components/com_cluster/administrator/models/forms/cluster.xml +++ b/src/components/com_cluster/administrator/models/forms/cluster.xml @@ -1,24 +1,91 @@
- - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + +
diff --git a/src/components/com_cluster/administrator/models/forms/clusteruser.xml b/src/components/com_cluster/administrator/models/forms/clusteruser.xml index a791e59..e1ac266 100644 --- a/src/components/com_cluster/administrator/models/forms/clusteruser.xml +++ b/src/components/com_cluster/administrator/models/forms/clusteruser.xml @@ -1,21 +1,81 @@
- - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + + + + + + +
diff --git a/src/components/com_cluster/administrator/models/forms/filter_clusters.xml b/src/components/com_cluster/administrator/models/forms/filter_clusters.xml index 96201ab..12a0ca3 100644 --- a/src/components/com_cluster/administrator/models/forms/filter_clusters.xml +++ b/src/components/com_cluster/administrator/models/forms/filter_clusters.xml @@ -1,13 +1,34 @@
- - + + - + + - + -
+ \ No newline at end of file diff --git a/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml b/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml index 78a0347..b66ce18 100644 --- a/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml +++ b/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml @@ -1,14 +1,45 @@
- - - + + + - + + - + -
+ \ No newline at end of file From 248822f8435f6ce620b0aa58a96f5b71eb5c0f85 Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Tue, 20 Aug 2019 18:54:16 +0530 Subject: [PATCH 2/4] #12 chore: Update query, added joins based on filters & introduce new ACL --- .../administrator/models/clusterusers.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 3af0513..2ca9abd 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -83,6 +83,19 @@ protected function getListQuery() // Filter by search in title. $search = $this->getState('filter.search'); + if (!empty($search)) + { + if (stripos($search, 'id:') === 0) + { + $query->where('cu.id = ' . (int) substr($search, 3)); + } + else + { + $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); + $query->where('(users.name LIKE' . $search . ' OR cl.name LIKE ' . $search . ')'); + } + } + $created_by = $this->getState('filter.created_by'); if (!empty($created_by)) From bd293d61d0f76081ddeaa370e02814aeeeef962c Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Tue, 20 Aug 2019 18:57:25 +0530 Subject: [PATCH 3/4] #12 chore: change variable name --- .../com_cluster/administrator/models/clusterusers.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 2ca9abd..1e5ebfa 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -96,11 +96,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 From b81b0dfb0507ebec04077548c86d9cc701438aed Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Thu, 22 Aug 2019 14:30:52 +0530 Subject: [PATCH 4/4] Task#12 chore: Resolve comments --- src/components/com_cluster/administrator/access.xml | 3 +-- .../administrator/languages/en-GB/en-GB.com_cluster.ini | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/com_cluster/administrator/access.xml b/src/components/com_cluster/administrator/access.xml index e558b09..27f5e20 100644 --- a/src/components/com_cluster/administrator/access.xml +++ b/src/components/com_cluster/administrator/access.xml @@ -8,7 +8,6 @@ - - + diff --git a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini index 2a11773..25dee5d 100644 --- a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini +++ b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini @@ -95,5 +95,3 @@ COM_CLUSTER_USERLIST_VIEW_ID="ID" JACTION_MANAGE_ALL_CLUSTER="Manage All Clusters" JACTION_MANAGE_ALL_CLUSTER_DESC="Manage All Clusters" -JACTION_MANAGE_OWN_CLUSTER="Manage Own Cluster" -JACTION_MANAGE_OWN_CLUSTER_DESC="Manage Own Cluster"