Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes for multiple content assign to single user #10

Open
wants to merge 4 commits into
base: release-1.1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion src/administrator/includes/rbacl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved

if (!empty($rolesAllowed))
{
return true;
}
Expand Down Expand Up @@ -199,4 +201,65 @@ public static function getRoleByUser($userId, $client = '', $clientContentIid =

return $roles;
}

/**
* Method to Get roles of users again to selected agency.
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param integer $agencyId agency id
* @param integer $userId user id
* @param integer $roleId selected role id
*
* @return mixed
*
* @since 1.6
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved
*/
public function getAuthorizedActions($agencyId = null, $userId = null, $roleId = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there hardcoded references to com_multiagency ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the variable name.

{
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanjivani1812 Move the DB operations in the model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thite-amol - getRoleByUser function having DB operation so I put there. Can please suggest a model name.

$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') . ')');
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved
$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();
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
11 changes: 8 additions & 3 deletions src/administrator/models/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved
{
$query->where($db->quoteName('client_id') . " = " . $db->quote($contentId));
}

$db->setQuery($query);

return $db->loadResult();
return $db->loadColumn();
sanjivani1812 marked this conversation as resolved.
Show resolved Hide resolved
}
}