Skip to content

Commit 3fc516a

Browse files
author
Jiaquan He
committed
Styles codes in the PSR-2 way.
This commit runs `php-cs-fixer fix` to apply the PSR-2 code style to the whole project, as Laravel does. (see: https://laravel.com/docs/master/contributions#coding-style)
1 parent 8871f9a commit 3fc516a

File tree

97 files changed

+3394
-6180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+3394
-6180
lines changed

app/Acl/Acl.php

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use App\Acl\Eloquent\Group;
88
use App\Acl\Permissions;
99

10-
class Acl {
10+
class Acl
11+
{
1112

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

3435
$groups = self::getBoundGroups($user_id);
35-
foreach ($groups as $group)
36-
{
36+
foreach ($groups as $group) {
3737
$role_actors = Roleactor::whereRaw([ 'group_ids' => $group['id'], 'project_key' => $project_key ])
3838
->get([ 'role_id' ])
3939
->toArray();
40-
foreach($role_actors as $actor)
41-
{
40+
foreach ($role_actors as $actor) {
4241
$role_ids[] = $actor['role_id'];
4342
}
4443
}
4544

4645
$role_actors = Roleactor::whereRaw([ 'user_ids' => $user_id, 'project_key' => $project_key ])
4746
->get(['role_id'])
4847
->toArray();
49-
foreach($role_actors as $actor)
50-
{
48+
foreach ($role_actors as $actor) {
5149
$role_ids[] = $actor['role_id'];
5250
}
5351

@@ -65,44 +63,36 @@ public static function getUserIdsByPermission($permission, $project_key)
6563
{
6664
$role_ids = [];
6765
$rps = RolePermissions::whereRaw([ 'permissions' => $permission, 'project_key' => $project_key ])->get();
68-
foreach ($rps as $rp)
69-
{
66+
foreach ($rps as $rp) {
7067
$role_ids[] = $rp->role_id;
7168
}
7269

7370
$local_role_ids = [];
7471
$local_rps = RolePermissions::whereRaw([ 'project_key' => $project_key ])->get();
75-
foreach ($local_rps as $rp)
76-
{
72+
foreach ($local_rps as $rp) {
7773
$local_role_ids[] = $rp->role_id;
7874
}
7975

8076
$rps = RolePermissions::whereRaw([ 'permissions' => $permission, 'project_key' => '$_sys_$', 'role_id' => [ '$nin' => $local_role_ids ] ])->get();
81-
foreach ($rps as $rp)
82-
{
77+
foreach ($rps as $rp) {
8378
$role_ids[] = $rp->role_id;
8479
}
8580

8681
$user_ids = [];
8782
$group_ids = [];
8883
$role_actors = Roleactor::whereRaw([ 'project_key' => $project_key, 'role_id' => [ '$in' => $role_ids ] ])->get();
89-
foreach ($role_actors as $actor)
90-
{
91-
if (isset($actor->user_ids) && $actor->user_ids)
92-
{
84+
foreach ($role_actors as $actor) {
85+
if (isset($actor->user_ids) && $actor->user_ids) {
9386
$user_ids = array_merge($user_ids, $actor->user_ids);
9487
}
95-
if (isset($actor->group_ids) && $actor->group_ids)
96-
{
88+
if (isset($actor->group_ids) && $actor->group_ids) {
9789
$group_ids = array_merge($group_ids, $actor->group_ids);
9890
}
9991
}
10092

101-
foreach ($group_ids as $group_id)
102-
{
93+
foreach ($group_ids as $group_id) {
10394
$group = Group::find($group_id);
104-
if ($group && isset($group->users) && $group->users)
105-
{
95+
if ($group && isset($group->users) && $group->users) {
10696
$user_ids = array_merge($user_ids, $group->users);
10797
}
10898
}
@@ -121,26 +111,23 @@ public static function getUserIdsByPermission($permission, $project_key)
121111
public static function isAllowed($user_id, $permission, $project_key)
122112
{
123113
$permissions = self::getPermissions($user_id, $project_key);
124-
if ($permission == 'view_project')
125-
{
114+
if ($permission == 'view_project') {
126115
return !!$permissions;
127-
}
128-
else
129-
{
116+
} else {
130117
return in_array($permission, $permissions);
131118
}
132119
}
133120

134121
/**
135-
* get groups user is bound
122+
* get groups user is bound
136123
*
137124
* @var string $user_id
138-
* @return array
125+
* @return array
139126
*/
140127
public static function getBoundGroups($user_id)
141128
{
142129
$groups = [];
143-
$group_list = Group::where([ 'users' => $user_id ])->get();
130+
$group_list = Group::where([ 'users' => $user_id ])->get();
144131
foreach ($group_list as $group) {
145132
$groups[] = [ 'id' => $group->id, 'name' => $group->name ];
146133
}
@@ -160,40 +147,34 @@ public static function getPermissions($user_id, $project_key)
160147
$role_actors = Roleactor::whereRaw([ 'user_ids' => $user_id, 'project_key' => $project_key ])
161148
->get([ 'role_id' ])
162149
->toArray();
163-
foreach($role_actors as $actor)
164-
{
150+
foreach ($role_actors as $actor) {
165151
$role_ids[] = $actor['role_id'];
166152
}
167153

168154
$groups = self::getBoundGroups($user_id);
169-
foreach ($groups as $group)
170-
{
155+
foreach ($groups as $group) {
171156
$role_actors = Roleactor::whereRaw([ 'group_ids' => $group['id'], 'project_key' => $project_key ])
172157
->get([ 'role_id' ])
173158
->toArray();
174-
foreach($role_actors as $actor)
175-
{
159+
foreach ($role_actors as $actor) {
176160
$role_ids[] = $actor['role_id'];
177161
}
178162
}
179163

180164
$all_permissions = [];
181165

182-
foreach ($role_ids as $role_id)
183-
{
166+
foreach ($role_ids as $role_id) {
184167
$rp = RolePermissions::where('project_key', $project_key)
185168
->where('role_id', $role_id)
186169
->first();
187170

188-
if (!$rp)
189-
{
171+
if (!$rp) {
190172
$rp = RolePermissions::where('project_key', '$_sys_$')
191173
->where('role_id', $role_id)
192174
->first();
193175
}
194176

195-
if ($rp)
196-
{
177+
if ($rp) {
197178
$all_permissions = array_merge($all_permissions, $rp->permissions ?: []);
198179
}
199180
}

app/Acl/Permissions.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Acl;
44

5-
class Permissions {
6-
5+
class Permissions
6+
{
77
const VIEW_PROJECT = 'view_project';
88
const MANAGE_PROJECT = 'manage_project';
99

@@ -85,5 +85,4 @@ public static function all()
8585
static::DELETE_SELF_WORKLOG,
8686
];
8787
}
88-
8988
}

0 commit comments

Comments
 (0)