From a19167d2484b8bdf1b3f91b56d187b08393c257d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Wed, 14 Aug 2019 19:29:41 +0530 Subject: [PATCH 01/13] Task #10 feat: Add function to get list of cluster to which a given have access --- .../administrator/models/clusteruser.php | 71 +++++++++++++++++++ .../administrator/models/clusterusers.php | 56 +++++++++++++++ .../languages/en-GB/en-GB.com_cluster.ini | 1 + 3 files changed, 128 insertions(+) diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 9aeda3f..40e2309 100644 --- a/src/components/com_cluster/administrator/models/clusteruser.php +++ b/src/components/com_cluster/administrator/models/clusteruser.php @@ -12,6 +12,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Table\Table; +use Joomla\CMS\Component\ComponentHelper; /** * Item Model for an Cluster. @@ -110,4 +111,74 @@ public function save($data) return parent::save($data); } + + /** + * Method to get the list of clusters to which user have access + * + * @param INT $userId Users Id. + * + * @return ARRAY List of clusters. + * + * @since 1.0.0 + */ + public function getUsersClusters($userId) + { + $user = Factory::getUser($userId); + $superUser = $user->authorise('core.admin'); + + $clusters = array(); + + // Load cluster library file + JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + + if (!$superUser && !$user->authorise('core.manageall.cluster', '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('filter.user_id', $user->id); + + // Get all assigned cluster entries + $clusters = $clusterUsersModel->getItems(); + } + + if ($superUser) + { + $clusterModel = ClusterFactory::model('Clusters', array('ignore_request' => true)); + + // Get all cluster entries + $clusters = $clusterModel->getItems(); + } + + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + if ($subUserExist) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + } + + $usersClusters = array(); + + if (!empty($clusters)) + { + if ($subUserExist && (!$superUser && !$user->authorise('core.manageall.cluster', '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)) + { + $usersClusters[] = $cluster; + } + } + } + else + { + $usersClusters = $clusters; + } + } + + return $usersClusters; + } } diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 7939c70..86fb1e1 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -102,6 +102,62 @@ protected function getListQuery() $query->where('cu.cluster_id = ' . (int) $cluster); } + // Filter by user + $cluster_user = $this->getState('filter.user_id'); + + if (is_numeric($cluster_user)) + { + $query->where('cu.user_id = ' . (int) $cluster_user); + } + + // Filter by client_id + $clusterClientId = $this->getState('filter.client_id'); + + if (is_numeric($clusterClientId)) + { + $query->where('cl.client_id = ' . (int) $clusterClientId); + } + elseif (is_array($clusterClientId)) + { + $query->where("cl.client_id IN ('" . implode("','", $clusterClientId) . "')"); + } + + // Filter by state + $published = $this->getState('filter.published'); + + if (is_numeric($published)) + { + $query->where('cl.state = ' . (int) $published); + } + elseif ($published === '') + { + $query->where('(cl.state = 0 OR cl.state = 1)'); + } + + // Filter by blocked users + $blockUser = $this->getState('filter.block'); + + if (is_numeric($blockUser)) + { + $query->where($db->quoteName('users.block') . ' = ' . (int) $blockUser); + } + + // Group by cluster + $clientID = $this->getState('list.group_by_client_id'); + + if (is_numeric($clientID)) + { + $query->group('cl.client_id'); + } + + // Group by user + $userID = $this->getState('list.group_by_user_id'); + + if (is_numeric($userID)) + { + $query->group('users.id'); + } + // Add the list ordering clause. $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); diff --git a/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini b/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini index 1ec5484..85bbe25 100644 --- a/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini +++ b/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini @@ -6,3 +6,4 @@ COM_CLUSTER_LIST_VIEW_DESCRIPTION="Description" COM_CLUSTER_LIST_VIEW_CLIENT="Client" COM_CLUSTER_LIST_VIEW_ID = "ID" COM_CLUSTER_LIST_VIEW_CREATEDBY = "Created By" +COM_CLUSTER_OWNERSHIP_USER ="Select User" From a89059fe83a1df6b29c5c707fd74e3a0f24f1027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Mon, 19 Aug 2019 11:13:57 +0530 Subject: [PATCH 02/13] Task #114 feat: Cluster awareness in related field --- .../administrator/models/clusteruser.php | 14 +++++++------- .../administrator/models/clusterusers.php | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 40e2309..52e88a5 100644 --- a/src/components/com_cluster/administrator/models/clusteruser.php +++ b/src/components/com_cluster/administrator/models/clusteruser.php @@ -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); @@ -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 @@ -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) { diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 86fb1e1..005c8ea 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -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 @@ -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 From 4ba67fd6b6b4223b774da7c6afbf1af1648399bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cankush=5Fm=E2=80=9D?= Date: Mon, 19 Aug 2019 11:16:06 +0530 Subject: [PATCH 03/13] Task #114 feat: Cluster awareness in related field --- src/components/com_cluster/administrator/models/clusteruser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 52e88a5..3357797 100644 --- a/src/components/com_cluster/administrator/models/clusteruser.php +++ b/src/components/com_cluster/administrator/models/clusteruser.php @@ -143,10 +143,10 @@ public function getUsersClusters($userId = null) } else { - $clusterModel = $this->setState('filter.state', 1); $clusterModel = ClusterFactory::model('Clusters', array('ignore_request' => true)); // Get all cluster entries + $clusterModel->setState('filter.state', 1); $clusters = $clusterModel->getItems(); } From d4eff8bf8125e9e6ef76a21d10a93346b9bddc8d Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Tue, 20 Aug 2019 18:48:28 +0530 Subject: [PATCH 04/13] #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 05/13] #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 06/13] #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 07/13] 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" From e489367a2043a638a11887ed75d98014fd3c860a Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Wed, 4 Sep 2019 17:02:00 +0530 Subject: [PATCH 08/13] Task #14 chore: Improvement made in cluster package - updating queries, removed unwanted code and also added JSON controller to get all associated users --- .../administrator/models/clusters.php | 2 +- .../administrator/models/clusteruser.php | 10 ++- .../administrator/models/clusterusers.php | 18 ----- .../site/controllers/clusterusers.json.php | 67 +++++++++++++++++++ 4 files changed, 75 insertions(+), 22 deletions(-) create mode 100644 src/components/com_cluster/site/controllers/clusterusers.json.php 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..7eda3fa --- /dev/null +++ b/src/components/com_cluster/site/controllers/clusterusers.json.php @@ -0,0 +1,67 @@ + + * @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\Component\ComponentHelper; +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() + { + // Check for request forgeries. + Session::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + $clusterIds = Factory::getApplication()->input->getInt('cluster_id', 0); + $userOptions = $allUsers = array(); + + // Initialize array to store dropdown options + $userOptions[] = HTMLHelper::_('select.option', "", Text::_('COM_TJFIELDS_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 JResponseJson($userOptions); + jexit(); + } +} From ef93b1b85778447fc90f59fa247ced9d64578612 Mon Sep 17 00:00:00 2001 From: Pravin_s Date: Mon, 14 Oct 2019 16:37:09 +0530 Subject: [PATCH 09/13] Task #14 chore: resolve MR comments --- .../site/controllers/clusterusers.json.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/com_cluster/site/controllers/clusterusers.json.php b/src/components/com_cluster/site/controllers/clusterusers.json.php index 7eda3fa..2753758 100644 --- a/src/components/com_cluster/site/controllers/clusterusers.json.php +++ b/src/components/com_cluster/site/controllers/clusterusers.json.php @@ -12,7 +12,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\CMS\Session\Session; @@ -34,14 +34,20 @@ class ClusterControllerClusterUsers extends BaseController */ public function getUsersByClientId() { + $app = Factory::getApplication(); + // Check for request forgeries. - Session::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + if (!Session::checkToken()) + { + echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true); + $app->close(); + } - $clusterIds = Factory::getApplication()->input->getInt('cluster_id', 0); + $clusterIds = $app->input->getInt('cluster_id', 0); $userOptions = $allUsers = array(); // Initialize array to store dropdown options - $userOptions[] = HTMLHelper::_('select.option', "", Text::_('COM_TJFIELDS_OWNERSHIP_USER')); + $userOptions[] = HTMLHelper::_('select.option', "", Text::_('COM_CLUSTER_OWNERSHIP_USER')); // Check cluster selected or not if ($clusterIds) @@ -61,7 +67,7 @@ public function getUsersByClientId() } } - echo new JResponseJson($userOptions); - jexit(); + echo new JsonResponse($userOptions); + $app->close(); } } From 0bc94de5294899adcd581d560c2e3a0b61ef380d Mon Sep 17 00:00:00 2001 From: Prav Date: Thu, 9 Jan 2020 11:39:28 +0530 Subject: [PATCH 10/13] Task#16 chore: Modified the query and table engines --- .../com_cluster/administrator/includes/cluster.php | 2 +- .../com_cluster/administrator/libraries/cluster.php | 6 +++++- .../com_cluster/administrator/models/clusterusers.php | 8 +++++--- .../com_cluster/administrator/sql/install.mysql.utf8.sql | 6 +++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/com_cluster/administrator/includes/cluster.php b/src/components/com_cluster/administrator/includes/cluster.php index 6ad7222..12f9bf6 100644 --- a/src/components/com_cluster/administrator/includes/cluster.php +++ b/src/components/com_cluster/administrator/includes/cluster.php @@ -54,7 +54,7 @@ public static function table($name) **/ public static function model($name, $config = array()) { - BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_cluster/models'); + BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_cluster/models', 'ClusterModel'); // @TODO Add support for cache return BaseDatabaseModel::getInstance($name, 'ClusterModel', $config); diff --git a/src/components/com_cluster/administrator/libraries/cluster.php b/src/components/com_cluster/administrator/libraries/cluster.php index 3052c92..e2877c3 100644 --- a/src/components/com_cluster/administrator/libraries/cluster.php +++ b/src/components/com_cluster/administrator/libraries/cluster.php @@ -245,8 +245,12 @@ public function isMember($userId = null) { $userId = Factory::getuser($userId)->id; - $ClusterModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); + if (empty($userId)) + { + return false; + } + $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); diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index c4de463..b024aa5 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -56,7 +56,9 @@ protected function getListQuery() $db = $this->getDbo(); $query = $db->getQuery(true); - $query->select(array('cu.*','cl.name', 'users.name as uname', 'users.username','cl.name as title', 'cl.client_id as client_id')); + $query->select( + array('cu.*','cl.name', 'users.name as uname', 'users.email as uemail', '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') . ')'); @@ -162,8 +164,8 @@ protected function getListQuery() } // Add the list ordering clause. - $orderCol = $this->state->get('list.ordering'); - $orderDirn = $this->state->get('list.direction'); + $orderCol = $this->state->get('list.ordering', 'users.name'); + $orderDirn = $this->state->get('list.direction', 'asc'); if ($orderCol && $orderDirn) { diff --git a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql index 3983260..4f64310 100644 --- a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql +++ b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_clusters` ( `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `description` text NOT NULL DEFAULT '', `params` text NOT NULL DEFAULT '', - `client` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '', + `client` varchar(400) NOT NULL DEFAULT '', `client_id` int(11) NOT NULL DEFAULT '0', `ordering` int(11) NOT NULL DEFAULT '0', `state` tinyint(3) NOT NULL DEFAULT '0', @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_clusters` ( `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE = MyISAM CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `#__tj_cluster_nodes` ( @@ -31,7 +31,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_cluster_nodes` ( `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`), FOREIGN KEY (`cluster_id`) REFERENCES `#__tj_clusters` (`id`) -) ENGINE = MyISAM CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; -- -- Indexes for table `__tj_cluster_nodes` From 47895d988b241c06d766e8133c9a79a6c6e7ed95 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Mon, 10 Oct 2022 21:05:11 +0530 Subject: [PATCH 11/13] Task #189184 feat: com_cluster improvements --- .../administrator/helpers/cluster.php | 5 +- .../administrator/libraries/cluster.php | 5 +- .../administrator/views/cluster/view.html.php | 23 +++++---- .../views/clusters/view.html.php | 39 +++++++------- .../views/clusteruser/view.html.php | 23 +++++---- .../views/clusterusers/view.html.php | 39 +++++++------- src/components/com_cluster/site/cluster.php | 6 ++- .../com_cluster/site/controller.php | 6 ++- src/components/com_cluster/site/router.php | 3 +- .../site/views/cluster/view.html.php | 3 +- .../site/views/clusters/tmpl/default.php | 51 ++++++++++--------- .../site/views/clusters/view.html.php | 17 ++++--- 12 files changed, 123 insertions(+), 97 deletions(-) diff --git a/src/components/com_cluster/administrator/helpers/cluster.php b/src/components/com_cluster/administrator/helpers/cluster.php index ef1f44a..dcf2c7c 100644 --- a/src/components/com_cluster/administrator/helpers/cluster.php +++ b/src/components/com_cluster/administrator/helpers/cluster.php @@ -10,6 +10,7 @@ defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; /** * Cluster helper. @@ -33,13 +34,13 @@ public static function addSubmenu($vName = '') if ($layout != "default") { JHtmlSidebar::addEntry( - JText::_('COM_CLUSTERS_VIEW_CLUSTERS'), + Text::_('COM_CLUSTERS_VIEW_CLUSTERS'), 'index.php?option=com_cluster&view=clusters', $vName == 'clusters' ); JHtmlSidebar::addEntry( - JText::_('COM_CLUSTERS_VIEW_CLUSTER_USERS'), + Text::_('COM_CLUSTERS_VIEW_CLUSTER_USERS'), 'index.php?option=com_cluster&view=clusterusers', $vName == 'clusterusers' ); diff --git a/src/components/com_cluster/administrator/libraries/cluster.php b/src/components/com_cluster/administrator/libraries/cluster.php index e2877c3..8d5f0a3 100644 --- a/src/components/com_cluster/administrator/libraries/cluster.php +++ b/src/components/com_cluster/administrator/libraries/cluster.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Language\Text; /** * Cluster class. Handles all application interaction with a Cluster @@ -192,7 +193,7 @@ public function bind(&$array) { if (empty($array)) { - $this->setError(JText::_('COM_CLUSTER_EMPTY_DATA')); + $this->setError(Text::_('COM_CLUSTER_EMPTY_DATA')); return false; } @@ -200,7 +201,7 @@ public function bind(&$array) // Bind the array if (!$this->setProperties($array)) { - $this->setError(\JText::_('COM_CLUSTER_BINDING_ERROR')); + $this->setError(Text::_('COM_CLUSTER_BINDING_ERROR')); return false; } diff --git a/src/components/com_cluster/administrator/views/cluster/view.html.php b/src/components/com_cluster/administrator/views/cluster/view.html.php index fe0e642..dff9105 100644 --- a/src/components/com_cluster/administrator/views/cluster/view.html.php +++ b/src/components/com_cluster/administrator/views/cluster/view.html.php @@ -11,6 +11,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * View to edit @@ -70,7 +73,7 @@ public function display($tpl = null) $this->form = $this->get('Form'); $this->input = Factory::getApplication()->input; - $this->canDo = JHelperContent::getActions('com_cluster', 'cluster', $this->item->id); + $this->canDo = ContentHelper::getActions('com_cluster', 'cluster', $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) @@ -110,15 +113,15 @@ protected function addToolbar() { Factory::getApplication()->input->set('hidemainmenu', true); - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_CLUSTER' : ($isNew ? 'ADD_CLUSTER' : 'EDIT_CLUSTER'))), + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_CLUSTER' : ($isNew ? 'ADD_CLUSTER' : 'EDIT_CLUSTER'))), 'pencil-2 cluster-add' ); if ($isNew) { - JToolbarHelper::save('cluster.save'); - JToolbarHelper::cancel('cluster.cancel'); + ToolbarHelper::save('cluster.save'); + ToolbarHelper::cancel('cluster.cancel'); } else { @@ -126,13 +129,13 @@ protected function addToolbar() // Can't save the record if it's checked out and editable $this->canSave($checkedOut, $itemEditable); - JToolbarHelper::cancel('cluster.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('cluster.cancel', 'JTOOLBAR_CLOSE'); } } else { - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_VIEW_CLUSTER') + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_VIEW_CLUSTER') ); $app = Factory::getApplication(); @@ -143,7 +146,7 @@ protected function addToolbar() $this->sidebar = JHtmlSidebar::render(); } - JToolbarHelper::divider(); + ToolbarHelper::divider(); } /** @@ -159,7 +162,7 @@ protected function canSave($checkedOut, $itemEditable) { if (!$checkedOut && $itemEditable) { - JToolbarHelper::save('cluster.save'); + ToolbarHelper::save('cluster.save'); } } diff --git a/src/components/com_cluster/administrator/views/clusters/view.html.php b/src/components/com_cluster/administrator/views/clusters/view.html.php index d31496f..71f5062 100644 --- a/src/components/com_cluster/administrator/views/clusters/view.html.php +++ b/src/components/com_cluster/administrator/views/clusters/view.html.php @@ -13,6 +13,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * Clusters view @@ -93,7 +96,7 @@ public function display($tpl = null) $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); $this->user = Factory::getUser(); - $this->canDo = JHelperContent::getActions('com_cluster'); + $this->canDo = ContentHelper::getActions('com_cluster'); ClusterHelper::addSubmenu('clusters'); $this->addToolbar(); @@ -111,38 +114,38 @@ public function display($tpl = null) */ protected function addToolbar() { - JToolBarHelper::title(JText::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); + ToolbarHelper::title(Text::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); $canDo = $this->canDo; if ($canDo->get('core.create')) { - JToolbarHelper::addNew('cluster.add'); + ToolbarHelper::addNew('cluster.add'); } if ($canDo->get('core.edit')) { - JToolbarHelper::editList('cluster.edit'); + ToolbarHelper::editList('cluster.edit'); } if ($canDo->get('core.edit.state')) { - JToolbarHelper::divider(); - JToolbarHelper::publish('clusters.publish', 'JTOOLBAR_PUBLISH', true); - JToolbarHelper::unpublish('clusters.unpublish', 'JTOOLBAR_UNPUBLISH', true); - JToolBarHelper::archiveList('clusters.archive', 'JTOOLBAR_ARCHIVE'); - JToolbarHelper::divider(); + ToolbarHelper::divider(); + ToolbarHelper::publish('clusters.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('clusters.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolbarHelper::archiveList('clusters.archive', 'JTOOLBAR_ARCHIVE'); + ToolbarHelper::divider(); } if ($canDo->get('core.delete')) { - JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusters.delete', 'JTOOLBAR_DELETE'); - JToolbarHelper::divider(); + ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusters.delete', 'JTOOLBAR_DELETE'); + ToolbarHelper::divider(); } if ($canDo->get('core.admin') || $canDo->get('core.options')) { - JToolbarHelper::preferences('com_cluster'); - JToolbarHelper::divider(); + ToolbarHelper::preferences('com_cluster'); + ToolbarHelper::divider(); } } @@ -154,11 +157,11 @@ protected function addToolbar() protected function getSortFields() { return array( - 'cl.id' => JText::_('JGRID_HEADING_ID'), - 'cl.title' => JText::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), - 'cl.client' => JText::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), - 'cl.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'cl.state' => JText::_('JSTATUS'), + 'cl.id' => Text::_('JGRID_HEADING_ID'), + 'cl.title' => Text::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), + 'cl.client' => Text::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), + 'cl.ordering' => Text::_('JGRID_HEADING_ORDERING'), + 'cl.state' => Text::_('JSTATUS'), ); } } diff --git a/src/components/com_cluster/administrator/views/clusteruser/view.html.php b/src/components/com_cluster/administrator/views/clusteruser/view.html.php index 374f84a..05c8c60 100644 --- a/src/components/com_cluster/administrator/views/clusteruser/view.html.php +++ b/src/components/com_cluster/administrator/views/clusteruser/view.html.php @@ -11,6 +11,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * View to edit @@ -70,7 +73,7 @@ public function display($tpl = null) $this->form = $this->get('Form'); $this->input = Factory::getApplication()->input; - $this->canDo = JHelperContent::getActions('com_cluster', 'clusteruser', $this->item->id); + $this->canDo = ContentHelper::getActions('com_cluster', 'clusteruser', $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) @@ -108,27 +111,27 @@ protected function addToolbar() { Factory::getApplication()->input->set('hidemainmenu', true); - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_USER' : ($isNew ? 'ADD_USER' : 'EDIT_USER'))), + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_USER' : ($isNew ? 'ADD_USER' : 'EDIT_USER'))), 'pencil-2 cluster-add' ); if ($isNew) { - JToolbarHelper::save('clusteruser.save'); - JToolbarHelper::cancel('clusteruser.cancel'); + ToolbarHelper::save('clusteruser.save'); + ToolbarHelper::cancel('clusteruser.cancel'); } else { $itemEditable = $this->isEditable($this->canDo, $user->id); $this->canSave($checkedOut, $itemEditable); - JToolbarHelper::cancel('clusteruser.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('clusteruser.cancel', 'JTOOLBAR_CLOSE'); } } else { - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_VIEW_CLUSTER_USER') + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_VIEW_CLUSTER_USER') ); ClusterHelper::addSubmenu('clusteruser'); @@ -136,7 +139,7 @@ protected function addToolbar() $this->sidebar = JHtmlSidebar::render(); } - JToolbarHelper::divider(); + ToolbarHelper::divider(); } /** @@ -152,7 +155,7 @@ protected function canSave($checkedOut, $itemEditable) { if (!$checkedOut && $itemEditable) { - JToolbarHelper::save('clusteruser.save'); + ToolbarHelper::save('clusteruser.save'); } } diff --git a/src/components/com_cluster/administrator/views/clusterusers/view.html.php b/src/components/com_cluster/administrator/views/clusterusers/view.html.php index 7816666..d33efbc 100644 --- a/src/components/com_cluster/administrator/views/clusterusers/view.html.php +++ b/src/components/com_cluster/administrator/views/clusterusers/view.html.php @@ -12,6 +12,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * Clusters view @@ -92,7 +95,7 @@ public function display($tpl = null) $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); $this->user = Factory::getUser(); - $this->canDo = JHelperContent::getActions('com_cluster'); + $this->canDo = ContentHelper::getActions('com_cluster'); ClusterHelper::addSubmenu('clusterusers'); $this->addToolbar(); @@ -110,37 +113,37 @@ public function display($tpl = null) */ protected function addToolbar() { - JToolBarHelper::title(JText::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); + ToolBarHelper::title(Text::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); if ($this->canDo->get('core.create')) { - JToolbarHelper::addNew('clusteruser.add'); + ToolBarHelper::addNew('clusteruser.add'); } if ($this->canDo->get('core.edit')) { - JToolbarHelper::editList('clusteruser.edit'); + ToolBarHelper::editList('clusteruser.edit'); } if ($this->canDo->get('core.edit.state')) { - JToolbarHelper::divider(); - JToolbarHelper::publish('clusteruser.publish', 'JTOOLBAR_PUBLISH', true); - JToolbarHelper::unpublish('clusteruser.unpublish', 'JTOOLBAR_UNPUBLISH', true); - JToolBarHelper::archiveList('clusteruser.archive', 'JTOOLBAR_ARCHIVE'); - JToolbarHelper::divider(); + ToolBarHelper::divider(); + ToolBarHelper::publish('clusteruser.publish', 'JTOOLBAR_PUBLISH', true); + ToolBarHelper::unpublish('clusteruser.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolBarHelper::archiveList('clusteruser.archive', 'JTOOLBAR_ARCHIVE'); + ToolBarHelper::divider(); } if ($this->canDo->get('core.delete')) { - JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusterusers.delete', 'JTOOLBAR_DELETE'); - JToolbarHelper::divider(); + ToolBarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusterusers.delete', 'JTOOLBAR_DELETE'); + ToolBarHelper::divider(); } if ($this->canDo->get('core.admin') || $this->canDo->get('core.options')) { - JToolbarHelper::preferences('com_cluster'); - JToolbarHelper::divider(); + ToolBarHelper::preferences('com_cluster'); + ToolBarHelper::divider(); } } @@ -152,11 +155,11 @@ protected function addToolbar() protected function getSortFields() { return array( - 'cl.id' => JText::_('JGRID_HEADING_ID'), - 'cl.title' => JText::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), - 'cl.client' => JText::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), - 'cl.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'cl.state' => JText::_('JSTATUS'), + 'cl.id' => Text::_('JGRID_HEADING_ID'), + 'cl.title' => Text::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), + 'cl.client' => Text::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), + 'cl.ordering' => Text::_('JGRID_HEADING_ORDERING'), + 'cl.state' => Text::_('JSTATUS'), ); } } diff --git a/src/components/com_cluster/site/cluster.php b/src/components/com_cluster/site/cluster.php index 2700e1e..30aaa86 100644 --- a/src/components/com_cluster/site/cluster.php +++ b/src/components/com_cluster/site/cluster.php @@ -7,6 +7,8 @@ */ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\BaseController; // Include dependancies jimport('joomla.application.component.controller'); @@ -16,6 +18,6 @@ // Execute the task. -$controller = JControllerLegacy::getInstance('Cluster'); -$controller->execute(JFactory::getApplication()->input->get('task')); +$controller = BaseController::getInstance('Cluster'); +$controller->execute(Factory::getApplication()->input->get('task')); $controller->redirect(); diff --git a/src/components/com_cluster/site/controller.php b/src/components/com_cluster/site/controller.php index d4735e3..47cf546 100644 --- a/src/components/com_cluster/site/controller.php +++ b/src/components/com_cluster/site/controller.php @@ -8,6 +8,8 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Factory; jimport('joomla.application.component.controller'); @@ -17,7 +19,7 @@ * * @since 1.0.0 */ -class ClusterController extends JControllerLegacy +class ClusterController extends BaseController { /** * Method to display a view. @@ -31,7 +33,7 @@ class ClusterController extends JControllerLegacy */ public function display($cachable = false, $urlparams = false) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $view = $app->input->getCmd('view', 'clusters'); $app->input->set('view', $view); diff --git a/src/components/com_cluster/site/router.php b/src/components/com_cluster/site/router.php index 73f26b8..827c3ee 100644 --- a/src/components/com_cluster/site/router.php +++ b/src/components/com_cluster/site/router.php @@ -8,6 +8,7 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\Component\Router\RouterBase; JLoader::registerPrefix('Cluster', JPATH_SITE . '/components/com_cluster/'); @@ -16,7 +17,7 @@ * * @since 1.0.0 */ -class ClusterRouter extends JComponentRouterBase +class ClusterRouter extends RouterBase { /** * Build method for URLs diff --git a/src/components/com_cluster/site/views/cluster/view.html.php b/src/components/com_cluster/site/views/cluster/view.html.php index c170105..49f0b77 100644 --- a/src/components/com_cluster/site/views/cluster/view.html.php +++ b/src/components/com_cluster/site/views/cluster/view.html.php @@ -8,6 +8,7 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\MVC\View\HtmlView; jimport('joomla.application.component.view'); @@ -16,7 +17,7 @@ * * @since 1.0.0 */ -class ClusterViewCluster extends JViewLegacy +class ClusterViewCluster extends HtmlView { protected $item; diff --git a/src/components/com_cluster/site/views/clusters/tmpl/default.php b/src/components/com_cluster/site/views/clusters/tmpl/default.php index 7e7c442..83799a5 100644 --- a/src/components/com_cluster/site/views/clusters/tmpl/default.php +++ b/src/components/com_cluster/site/views/clusters/tmpl/default.php @@ -8,13 +8,16 @@ // No direct access defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Layout\LayoutHelper; +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - -JHtml::_('bootstrap.tooltip'); -JHtml::_('behavior.multiselect'); -JHtml::_('formbehavior.chosen', 'select'); +HTMLHelper::_('bootstrap.tooltip'); +HTMLHelper::_('behavior.multiselect'); +HTMLHelper::_('formbehavior.chosen', 'select'); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); @@ -23,13 +26,13 @@ if ($saveOrder) { $saveOrderingUrl = 'index.php?option=com_cluster&task=clusters.saveOrderAjax&tmpl=component'; - JHtml::_('sortablelist.sortable', 'clustersList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); + HTMLHelper::_('sortablelist.sortable', 'clustersList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); } ?>
-
+ sidebar)) { @@ -50,13 +53,13 @@ $this)); + echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?> items)) { ?>
- +
- + - + items[0]->state)) { ?> - + - + - + - + - + @@ -132,7 +135,7 @@ } elseif (!$saveOrder) { - $iconClass = ' inactive tip-top hasTooltip" title="' . JHtml::_('tooltipText', 'JORDERINGDISABLED'); + $iconClass = ' inactive tip-top hasTooltip" title="' . HTMLHelper::_('tooltipText', 'JORDERINGDISABLED'); } ?> @@ -147,14 +150,14 @@ ?> - id); ?> + id); ?> items[0]->state)) { ?> - state, $i, 'clusters.', $canChange, 'cb'); ?> + state, $i, 'clusters.', $canChange, 'cb'); ?> checked_out) { ?> - checked_out, $item->checked_out_time, 'clusters.', $canCheckin); ?> + checked_out, $item->checked_out_time, 'clusters.', $canCheckin); ?> - + escape($item->name); ?> - +
diff --git a/src/components/com_cluster/site/views/clusters/view.html.php b/src/components/com_cluster/site/views/clusters/view.html.php index 89e3983..b685660 100644 --- a/src/components/com_cluster/site/views/clusters/view.html.php +++ b/src/components/com_cluster/site/views/clusters/view.html.php @@ -8,13 +8,16 @@ // No direct access to this file defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Factory; /** * Clusters view * * @since 1.0.0 */ -class ClusterViewClusters extends JViewLegacy +class ClusterViewClusters extends HtmlView { /** * An array of items @@ -122,7 +125,7 @@ public function display($tpl = null) $this->activeFilters = $this->get('ActiveFilters'); // Get ACL actions - $this->user = JFactory::getUser(); + $this->user = Factory::getUser(); $this->canCreate = $this->user->authorise('core.content.create', 'com_cluster'); $this->canEdit = $this->user->authorise('core.content.edit', 'com_cluster'); @@ -142,11 +145,11 @@ public function display($tpl = null) protected function getSortFields() { return array( - 'cl.id' => JText::_('JGRID_HEADING_ID'), - 'cl.title' => JText::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), - 'cl.client' => JText::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), - 'cl.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'cl.state' => JText::_('JSTATUS'), + 'cl.id' => Text::_('JGRID_HEADING_ID'), + 'cl.title' => Text::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), + 'cl.client' => Text::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), + 'cl.ordering' => Text::_('JGRID_HEADING_ORDERING'), + 'cl.state' => Text::_('JSTATUS'), ); } } From 9b17e4179d8aa32bb7b8404deab317cf457f3d7a Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Sat, 5 Nov 2022 11:10:17 +0530 Subject: [PATCH 12/13] Task #189184 chore: Updated Indexing for tables --- .../com_cluster/administrator/sql/install.mysql.utf8.sql | 3 +++ .../com_cluster/administrator/sql/updates/mysql/1.0.0.sql | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql diff --git a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql index 4f64310..40e4d23 100644 --- a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql +++ b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_clusters` ( `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`) + KEY `client_id_idx` (`client_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; @@ -31,6 +32,8 @@ CREATE TABLE IF NOT EXISTS `#__tj_cluster_nodes` ( `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`), FOREIGN KEY (`cluster_id`) REFERENCES `#__tj_clusters` (`id`) + KEY `cluster_id_idx` (`cluster_id`) + KEY `user_id_idx` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; -- diff --git a/src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql b/src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql new file mode 100644 index 0000000..7583b37 --- /dev/null +++ b/src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql @@ -0,0 +1,4 @@ +ALTER TABLE #__tj_clusters ADD INDEX client_id_idx (client_id); +ALTER TABLE #__tj_cluster_nodes ADD INDEX cluster_id_idx (cluster_id); +ALTER TABLE #__tj_cluster_nodes ADD INDEX user_id_idx (user_id); + From 52306bd3d7dfb9100e7067bfa6839e4f2549fb85 Mon Sep 17 00:00:00 2001 From: Kishori Karale Date: Sat, 5 Nov 2022 11:12:30 +0530 Subject: [PATCH 13/13] Task #189184 chore: Updated Indexing for tables --- .../com_cluster/administrator/sql/install.mysql.utf8.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql index 40e4d23..989b083 100644 --- a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql +++ b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_clusters` ( `created_by` int(11) UNSIGNED NOT NULL DEFAULT '0', `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), KEY `client_id_idx` (`client_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; @@ -31,8 +31,8 @@ CREATE TABLE IF NOT EXISTS `#__tj_cluster_nodes` ( `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`), - FOREIGN KEY (`cluster_id`) REFERENCES `#__tj_clusters` (`id`) - KEY `cluster_id_idx` (`cluster_id`) + FOREIGN KEY (`cluster_id`) REFERENCES `#__tj_clusters` (`id`), + KEY `cluster_id_idx` (`cluster_id`), KEY `user_id_idx` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;