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

Added function to get all users with specific permission #104

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all 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
21 changes: 21 additions & 0 deletions PhpRbac/src/PhpRbac/core/lib/rbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,27 @@ function roles($Permission, $OnlyIDs = true)
WHERE PermissionID=? ORDER BY TP.ID", $Permission );
}
}
/**
* Returns all users with a permission

Choose a reason for hiding this comment

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

  • Return user ids with a permission

*
* @param integer $Permission

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

It gets string or id as parameter.

Copy link

@VyacheslavDolya VyacheslavDolya Dec 22, 2017

Choose a reason for hiding this comment

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

and that's sad

* ID
* @return Array 1D or null

Choose a reason for hiding this comment

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

*/
function users($Permission)
Copy link

@VyacheslavDolya VyacheslavDolya Dec 21, 2017

Choose a reason for hiding this comment

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

function getUserIdsByPermissionId($PermissionId)

Copy link
Author

Choose a reason for hiding this comment

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

this is not the way other functions in a library named

Choose a reason for hiding this comment

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

that's clear function name, belongs to standard naming

{
if (!is_numeric($Permission)) $Permission = $this->returnId($Permission);

Choose a reason for hiding this comment

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

if (!is_int($PermissionId)) {
    throw new InvalidArgumentException("`$PermissionId` should be type of integer")
}

Copy link
Author

Choose a reason for hiding this comment

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

agree. this check can be performed after permission string is resolved into id

$Res = Jf::sql ("SELECT DISTINCT(UserID) FROM {$this->tablePrefix()}permissions INNER JOIN {$this->tablePrefix()}rolepermissions ON {$this->tablePrefix()}permissions.ID = {$this->tablePrefix()}rolepermissions.PermissionID INNER JOIN {$this->tablePrefix()}roles ON {$this->tablePrefix()}rolepermissions.RoleID = {$this->tablePrefix()}roles.`ID` INNER JOIN {$this->tablePrefix()}userroles ON {$this->tablePrefix()}roles.`ID` = {$this->tablePrefix()}userroles.RoleID WHERE {$this->tablePrefix()}permissions.`ID` = ?", $Permission);

Choose a reason for hiding this comment

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

if (is_array ( $Res ))

Choose a reason for hiding this comment

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

$answer = array();
if (is_array( $rows)) {

{
$out = array ();

Choose a reason for hiding this comment

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

remove

foreach ( $Res as $R )

Choose a reason for hiding this comment

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

foreach ( $rows as $user ) {

$out [] = $R ['UserID'];
Copy link

@VyacheslavDolya VyacheslavDolya Dec 21, 2017

Choose a reason for hiding this comment

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

$answer[] = (int) $user['UserID'];

Copy link
Author

Choose a reason for hiding this comment

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

agree

return $out;

Choose a reason for hiding this comment

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

remove

}
else

Choose a reason for hiding this comment

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

remove

return null;

Choose a reason for hiding this comment

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

return answer;

}
}

/** @} */ // End group phprbac_permission_manager */
Expand Down