Skip to content
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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • @param int $PermissionId

Copy link
Copy Markdown
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
Copy Markdown

@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
Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown
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

Copy link
Copy Markdown

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

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

Choose a reason for hiding this comment

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

if (is_array ( $Res ))
Copy link
Copy Markdown

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 ();
Copy link
Copy Markdown

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 )
Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown
Author

Choose a reason for hiding this comment

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

agree

return $out;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove

}
else
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove

return null;
Copy link
Copy Markdown

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