Skip to content

Commit c18252f

Browse files
committed
Add a type field to routes and filter by it
1 parent 7dbf498 commit c18252f

8 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎ProcessMaker/Http/Controllers/Admin/UserController.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ public function edit(User $user)
3737
$user->memberships = $user->groupMembersFromMemberable()->get();
3838
$groups = $this->getAllGroups();
3939
$permission_ids = $user->permissionAssignments()->pluck('permission_id')->toArray();
40-
$all_permissions = Permission::all();
40+
$all_permissions = Permission::routes()->get();
4141
$users_permission_ids = $this->user_permission_ids($user);
4242

43-
4443
$currentUser = $user;
4544
$states = JsonData::states();
4645
$countries = JsonData::countries();

‎ProcessMaker/Http/Controllers/Api/ProcessController.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ public function update(Request $request, Process $process)
217217
$process->fill($request->except('cancel_request', 'start_request', 'cancel_request_id', 'start_request_id'));
218218
$process->saveOrFail();
219219

220-
221220
unset(
222221
$original_attributes['id'],
223222
$original_attributes['updated_at']

‎ProcessMaker/Http/Controllers/Api/ProcessRequestController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class ProcessRequestController extends Controller
1919
{
20-
public $skipPermissionCheckFor = ['index', 'show'];
20+
public $skipPermissionCheckFor = ['index', 'show', 'store', 'destroy'];
2121

2222
/**
2323
* Display a listing of the resource.

‎ProcessMaker/Http/Controllers/Api/ProcessRequestFileController.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
class ProcessRequestFileController extends Controller
2727
{
28+
public $skipPermissionCheckFor = ['index', 'store', 'update', 'destroy'];
29+
2830
use HasMediaTrait;
2931
/*
3032
* return list of Process Request files

‎ProcessMaker/Models/Permission.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,15 @@ static public function byGuardName($name)
2222
throw new ModelNotFoundException($name . " permission does not exist");
2323
}
2424
}
25+
26+
/**
27+
* Query filter for type = route
28+
*
29+
* @param \Illuminate\Database\Eloquent\Builder $query
30+
* @return \Illuminate\Database\Eloquent\Builder
31+
*/
32+
public function scopeRoutes($query)
33+
{
34+
return $query->where('type', 'ROUTE');
35+
}
2536
}

‎database/factories/PermissionFactory.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
$factory->define(ProcessMaker\Models\Permission::class, function (Faker $faker) {
66
return [
77
'name' => $faker->sentence(2),
8+
'type' => 'ROUTE',
89
'guard_name' => $faker->sentence(2),
910
'description' => $faker->sentence(5),
1011
];

‎database/migrations/2018_09_10_170636_create_permissions_table.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function up()
1616
Schema::create('permissions', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->string('name');
19+
$table->enum('type', ['ROUTE', 'RESOURCE']);
1920
$table->string('guard_name')->unique();
2021
$table->text('description');
2122
$table->timestamps();

‎database/seeds/PermissionSeeder.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class PermissionSeeder extends Seeder
4646
'processes.destroy',
4747
'processes.edit',
4848
'processes.show',
49+
'requests.index',
50+
'requests.create',
51+
'requests.destroy',
52+
'requests.cancel',
53+
'requests.edit',
54+
'requests.show',
4955
'scripts.index',
5056
'scripts.create',
5157
'scripts.destroy',
@@ -58,6 +64,10 @@ class PermissionSeeder extends Seeder
5864
'users.show'
5965
];
6066

67+
private $resourcePermissions = [
68+
'requests'
69+
];
70+
6171
public function run($user = null)
6272
{
6373
if (Permission::count() !== 0) {
@@ -78,9 +88,16 @@ public function run($user = null)
7888
]);
7989

8090
foreach ($this->permissions as $permissionString) {
91+
$type = 'ROUTE';
92+
$resource = explode('.', $permissionString)[0];
93+
if (in_array($resource, $this->resourcePermissions)) {
94+
$type = 'RESOURCE';
95+
}
96+
8197
$permission = factory(Permission::class)->create([
8298
'name' => ucwords(preg_replace('/(\.|_)/', ' ',
8399
$permissionString)),
100+
'type' => $type,
84101
'guard_name' => $permissionString,
85102
]);
86103
factory(PermissionAssignment::class)->create([

0 commit comments

Comments
 (0)