From 3db05619c84a8b9067861f7200a61235f60df31f Mon Sep 17 00:00:00 2001 From: Sanjivani Patil Date: Fri, 19 Oct 2018 11:32:17 +0530 Subject: [PATCH 1/4] Some fixes for multiple content assign to single user --- src/administrator/includes/rbacl.php | 4 +++- src/administrator/models/user.php | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/administrator/includes/rbacl.php b/src/administrator/includes/rbacl.php index 7039cae..a95ad4c 100644 --- a/src/administrator/includes/rbacl.php +++ b/src/administrator/includes/rbacl.php @@ -129,7 +129,9 @@ public static function check($userId, $client, $action, $contentId = null) $userModel = self::model("user"); $contentRoleId = $userModel->getAssociatedContentRole($userId, $client, $contentId); - if (in_array($contentRoleId, $allowedRoles)) + $rolesAllowed = array_intersect($contentRoleId, $allowedRoles); + + if (!empty($rolesAllowed)) { return true; } diff --git a/src/administrator/models/user.php b/src/administrator/models/user.php index 70f4e17..8572b8e 100755 --- a/src/administrator/models/user.php +++ b/src/administrator/models/user.php @@ -106,7 +106,7 @@ protected function loadFormData() * * @since __DEPLOY_VERSION__ */ - public function getAssociatedContentRole($userId, $client, $contentId) + public function getAssociatedContentRole($userId, $client, $contentId = null) { $db = Factory::getDbo(); $query = $db->getQuery(true); @@ -115,9 +115,14 @@ public function getAssociatedContentRole($userId, $client, $contentId) $query->from($db->quoteName('#__tjsu_users')); $query->where($db->quoteName('user_id') . " = " . (int) $userId); $query->where($db->quoteName('client') . " = " . $db->q($client)); - $query->where($db->quoteName('client_id') . " = " . (int) $contentId); + + if (!is_null($contentId)) + { + $query->where($db->quoteName('client_id') . " = " . $db->quote($contentId)); + } + $db->setQuery($query); - return $db->loadResult(); + return $db->loadColumn(); } } From e513db813e6ec1ed4cd2a8440dbe9560d63050bf Mon Sep 17 00:00:00 2001 From: Sanjivani Patil Date: Fri, 19 Oct 2018 12:34:38 +0530 Subject: [PATCH 2/4] Method to Get roles of users again to selected agency. --- src/administrator/includes/rbacl.php | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/administrator/includes/rbacl.php b/src/administrator/includes/rbacl.php index a95ad4c..742a302 100644 --- a/src/administrator/includes/rbacl.php +++ b/src/administrator/includes/rbacl.php @@ -201,4 +201,65 @@ public static function getRoleByUser($userId, $client = '', $clientContentIid = return $roles; } + + /** + * Method to Get roles of users again to selected agency. + * + * @param integer $agencyId agency id + * @param integer $userId user id + * @param integer $roleId selected role id + * + * @return mixed + * + * @since 1.6 + */ + public function getAuthorizedActions($agencyId = null, $userId = null, $roleId = null) + { + if ($agencyId == null) + { + $input = JFactory::getApplication()->input; + $agencyId = $input->get('aid', '0', 'INT'); + } + + if ($userId == null) + { + $userId = JFactory::getUser()->id; + } + + // Get subusers actions mapp + $userRoleId = self::getRoleByUser($userId, 'com_multiagency', 0); + + if (empty($userRoleId)) + { + $userRoleId = self::getRoleByUser($userId, 'com_multiagency', $agencyId); + } + + if (!empty($userRoleId)) + { + $db = JFactory::getDBO(); + $subInQuery = $db->getQuery(true); + $subInQuery->select('action_id') + ->from($db->quoteName('#__tjsu_role_action_map')) + ->where($db->quoteName('role_id') . 'IN(' . implode(',', $userRoleId) . ')'); + $db->setQuery($subInQuery); + + $roleActions = $db->loadColumn(); + + if ($roleActions && !empty($agencyId) && !empty($userRoleId)) + { + $query = $db->getQuery(true); + $query->select('m.role_id,r.name, count( m.action_id) as actionCount, (select count(aa.action_id) + FROM #__tjsu_role_action_map aa WHERE aa.role_id = m.role_id) as roleCount'); + $query->from($db->quoteName('#__tjsu_role_action_map', 'm')); + $query->join('INNER', $db->quoteName('#__tjsu_actions', 'a') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('m.action_id') . ')'); + $query->join('INNER', $db->quoteName('#__tjsu_roles', 'r') . ' ON (' . $db->quoteName('r.id') . ' = ' . $db->quoteName('m.role_id') . ')'); + $query->where($db->quoteName('m.action_id') . ' IN (' . implode(',', $roleActions) . ')'); + $query->group($db->quoteName('m.role_id')); + $query->having('roleCount <= actionCount'); + $db->setQuery($query); + + return $roles = $db->loadAssocList(); + } + } + } } From 92b69f6d75c72c627b0f098c5ec87986f6875298 Mon Sep 17 00:00:00 2001 From: Sanjivani Patil Date: Fri, 19 Oct 2018 17:33:00 +0530 Subject: [PATCH 3/4] Method to Get roles of users again to selected agency. --- src/administrator/includes/rbacl.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/administrator/includes/rbacl.php b/src/administrator/includes/rbacl.php index 742a302..17c42c7 100644 --- a/src/administrator/includes/rbacl.php +++ b/src/administrator/includes/rbacl.php @@ -205,7 +205,7 @@ public static function getRoleByUser($userId, $client = '', $clientContentIid = /** * Method to Get roles of users again to selected agency. * - * @param integer $agencyId agency id + * @param integer $contentId agency id * @param integer $userId user id * @param integer $roleId selected role id * @@ -213,12 +213,12 @@ public static function getRoleByUser($userId, $client = '', $clientContentIid = * * @since 1.6 */ - public function getAuthorizedActions($agencyId = null, $userId = null, $roleId = null) + public function getAuthorizedActions($contentId = null, $userId = null, $roleId = null) { - if ($agencyId == null) + if ($contentId == null) { $input = JFactory::getApplication()->input; - $agencyId = $input->get('aid', '0', 'INT'); + $contentId = $input->get('aid', '0', 'INT'); } if ($userId == null) @@ -231,7 +231,7 @@ public function getAuthorizedActions($agencyId = null, $userId = null, $roleId = if (empty($userRoleId)) { - $userRoleId = self::getRoleByUser($userId, 'com_multiagency', $agencyId); + $userRoleId = self::getRoleByUser($userId, 'com_multiagency', $contentId); } if (!empty($userRoleId)) @@ -245,7 +245,7 @@ public function getAuthorizedActions($agencyId = null, $userId = null, $roleId = $roleActions = $db->loadColumn(); - if ($roleActions && !empty($agencyId) && !empty($userRoleId)) + if ($roleActions && !empty($contentId) && !empty($userRoleId)) { $query = $db->getQuery(true); $query->select('m.role_id,r.name, count( m.action_id) as actionCount, (select count(aa.action_id) From 633269da7840fc0b1819c1772c5ba8995f87dad7 Mon Sep 17 00:00:00 2001 From: Sanjivani Patil Date: Mon, 22 Oct 2018 10:37:48 +0530 Subject: [PATCH 4/4] Some fixes for multiple content assign to single user --- src/administrator/includes/rbacl.php | 27 ++++++++++++++++----------- src/administrator/models/user.php | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/administrator/includes/rbacl.php b/src/administrator/includes/rbacl.php index 17c42c7..948537a 100644 --- a/src/administrator/includes/rbacl.php +++ b/src/administrator/includes/rbacl.php @@ -203,25 +203,24 @@ public static function getRoleByUser($userId, $client = '', $clientContentIid = } /** - * Method to Get roles of users again to selected agency. + * Method to Get roles of users against to selected client. * - * @param integer $contentId agency id - * @param integer $userId user id - * @param integer $roleId selected role id + * @param integer $contentId content id + * @param integer $userId user id * - * @return mixed + * @return array * - * @since 1.6 + * @since __DEPLOY_VERSION__ */ - public function getAuthorizedActions($contentId = null, $userId = null, $roleId = null) + public function getAuthorizedActions($contentId = null, $userId = null) { - if ($contentId == null) + if (is_null($contentId)) { $input = JFactory::getApplication()->input; $contentId = $input->get('aid', '0', 'INT'); } - if ($userId == null) + if (is_null($userId)) { $userId = JFactory::getUser()->id; } @@ -237,6 +236,8 @@ public function getAuthorizedActions($contentId = null, $userId = null, $roleId if (!empty($userRoleId)) { $db = JFactory::getDBO(); + + // Get actions mapped to roles. $subInQuery = $db->getQuery(true); $subInQuery->select('action_id') ->from($db->quoteName('#__tjsu_role_action_map')) @@ -245,8 +246,12 @@ public function getAuthorizedActions($contentId = null, $userId = null, $roleId $roleActions = $db->loadColumn(); - if ($roleActions && !empty($contentId) && !empty($userRoleId)) + if ($roleActions && !empty($contentId)) { + /* Get the roles again to cotent id. + * e.g. One content is Agency and agency having multiple roles manager, staff, employee + * One user having two different roles for two different agency. then If I pass then agency id then query give us mapped actions agains to agency. + */ $query = $db->getQuery(true); $query->select('m.role_id,r.name, count( m.action_id) as actionCount, (select count(aa.action_id) FROM #__tjsu_role_action_map aa WHERE aa.role_id = m.role_id) as roleCount'); @@ -258,7 +263,7 @@ public function getAuthorizedActions($contentId = null, $userId = null, $roleId $query->having('roleCount <= actionCount'); $db->setQuery($query); - return $roles = $db->loadAssocList(); + return $db->loadAssocList(); } } } diff --git a/src/administrator/models/user.php b/src/administrator/models/user.php index 8572b8e..5d514d5 100755 --- a/src/administrator/models/user.php +++ b/src/administrator/models/user.php @@ -102,7 +102,7 @@ protected function loadFormData() * @param string $client The name of the client to authorise. com_content * @param integer $contentId The content key. null check with role and allowed actions. * - * @return integer The role id + * @return array The role id * * @since __DEPLOY_VERSION__ */