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

Styles codes in the PSR-2 way. #127

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
67 changes: 24 additions & 43 deletions app/Acl/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use App\Acl\Eloquent\Group;
use App\Acl\Permissions;

class Acl {
class Acl
{

/**
* get role list in the project.
Expand All @@ -32,22 +33,19 @@ public static function getRolesByUid($project_key, $user_id)
$role_ids = [];

$groups = self::getBoundGroups($user_id);
foreach ($groups as $group)
{
foreach ($groups as $group) {
$role_actors = Roleactor::whereRaw([ 'group_ids' => $group['id'], 'project_key' => $project_key ])
->get([ 'role_id' ])
->toArray();
foreach($role_actors as $actor)
{
foreach ($role_actors as $actor) {
$role_ids[] = $actor['role_id'];
}
}

$role_actors = Roleactor::whereRaw([ 'user_ids' => $user_id, 'project_key' => $project_key ])
->get(['role_id'])
->toArray();
foreach($role_actors as $actor)
{
foreach ($role_actors as $actor) {
$role_ids[] = $actor['role_id'];
}

Expand All @@ -65,44 +63,36 @@ public static function getUserIdsByPermission($permission, $project_key)
{
$role_ids = [];
$rps = RolePermissions::whereRaw([ 'permissions' => $permission, 'project_key' => $project_key ])->get();
foreach ($rps as $rp)
{
foreach ($rps as $rp) {
$role_ids[] = $rp->role_id;
}

$local_role_ids = [];
$local_rps = RolePermissions::whereRaw([ 'project_key' => $project_key ])->get();
foreach ($local_rps as $rp)
{
foreach ($local_rps as $rp) {
$local_role_ids[] = $rp->role_id;
}

$rps = RolePermissions::whereRaw([ 'permissions' => $permission, 'project_key' => '$_sys_$', 'role_id' => [ '$nin' => $local_role_ids ] ])->get();
foreach ($rps as $rp)
{
foreach ($rps as $rp) {
$role_ids[] = $rp->role_id;
}

$user_ids = [];
$group_ids = [];
$role_actors = Roleactor::whereRaw([ 'project_key' => $project_key, 'role_id' => [ '$in' => $role_ids ] ])->get();
foreach ($role_actors as $actor)
{
if (isset($actor->user_ids) && $actor->user_ids)
{
foreach ($role_actors as $actor) {
if (isset($actor->user_ids) && $actor->user_ids) {
$user_ids = array_merge($user_ids, $actor->user_ids);
}
if (isset($actor->group_ids) && $actor->group_ids)
{
if (isset($actor->group_ids) && $actor->group_ids) {
$group_ids = array_merge($group_ids, $actor->group_ids);
}
}

foreach ($group_ids as $group_id)
{
foreach ($group_ids as $group_id) {
$group = Group::find($group_id);
if ($group && isset($group->users) && $group->users)
{
if ($group && isset($group->users) && $group->users) {
$user_ids = array_merge($user_ids, $group->users);
}
}
Expand All @@ -121,26 +111,23 @@ public static function getUserIdsByPermission($permission, $project_key)
public static function isAllowed($user_id, $permission, $project_key)
{
$permissions = self::getPermissions($user_id, $project_key);
if ($permission == 'view_project')
{
if ($permission == 'view_project') {
return !!$permissions;
}
else
{
} else {
return in_array($permission, $permissions);
}
}

/**
* get groups user is bound
* get groups user is bound
*
* @var string $user_id
* @return array
* @return array
*/
public static function getBoundGroups($user_id)
{
$groups = [];
$group_list = Group::where([ 'users' => $user_id ])->get();
$group_list = Group::where([ 'users' => $user_id ])->get();
foreach ($group_list as $group) {
$groups[] = [ 'id' => $group->id, 'name' => $group->name ];
}
Expand All @@ -160,40 +147,34 @@ public static function getPermissions($user_id, $project_key)
$role_actors = Roleactor::whereRaw([ 'user_ids' => $user_id, 'project_key' => $project_key ])
->get([ 'role_id' ])
->toArray();
foreach($role_actors as $actor)
{
foreach ($role_actors as $actor) {
$role_ids[] = $actor['role_id'];
}

$groups = self::getBoundGroups($user_id);
foreach ($groups as $group)
{
foreach ($groups as $group) {
$role_actors = Roleactor::whereRaw([ 'group_ids' => $group['id'], 'project_key' => $project_key ])
->get([ 'role_id' ])
->toArray();
foreach($role_actors as $actor)
{
foreach ($role_actors as $actor) {
$role_ids[] = $actor['role_id'];
}
}

$all_permissions = [];

foreach ($role_ids as $role_id)
{
foreach ($role_ids as $role_id) {
$rp = RolePermissions::where('project_key', $project_key)
->where('role_id', $role_id)
->first();

if (!$rp)
{
if (!$rp) {
$rp = RolePermissions::where('project_key', '$_sys_$')
->where('role_id', $role_id)
->first();
}

if ($rp)
{
if ($rp) {
$all_permissions = array_merge($all_permissions, $rp->permissions ?: []);
}
}
Expand Down
5 changes: 2 additions & 3 deletions app/Acl/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Acl;

class Permissions {

class Permissions
{
const VIEW_PROJECT = 'view_project';
const MANAGE_PROJECT = 'manage_project';

Expand Down Expand Up @@ -85,5 +85,4 @@ public static function all()
static::DELETE_SELF_WORKLOG,
];
}

}
Loading