Skip to content

Commit

Permalink
Merge branch 'feature/FOUR-11531' of https://github.com/ProcessMaker/…
Browse files Browse the repository at this point in the history
…processmaker into feature/FOUR-12253
  • Loading branch information
CarliPinell committed Dec 22, 2023
2 parents 494a715 + 21d5918 commit fa72fe1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
13 changes: 13 additions & 0 deletions ProcessMaker/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ProcessMaker\Exception\ReferentialIntegrityException;
use ProcessMaker\Models\Comment;
use ProcessMaker\Models\Permission;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\User;

Expand All @@ -28,4 +29,16 @@ public function deleting(User $user)
->where('user_id', $user->id)
->delete();
}

/**
* Handle the user "created" event.
*/
public function created(User $user): void
{
$perList = [
'view-process-catalog'
];
$permissionIds = Permission::whereIn('name', $perList)->pluck('id')->toArray();
$user->permissions()->attach($permissionIds);
}
}
3 changes: 0 additions & 3 deletions database/seeders/PermissionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ class PermissionSeeder extends Seeder
'edit-signals',
'delete-signals',
],
'Process Catalog' => [
'view-process-catalog',
],
];

public function run($seedUser = null)
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Api/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ public function testSetPermissionsForUser()
$this->assertEquals($testUser->permissions->first()->id, $testPermission->id);
}

public function testSetPermissionsViewProcessCatalogForUser()
{
Permission::updateOrCreate([
'name' => 'view-process-catalog',
], [
'title' => 'View Process Catalog',
'name' => 'view-process-catalog',
'group' => 'Process Catalog',
]);
$testUser = User::updateOrCreate([
'username' => 'will',
'is_administrator' => true,
], [
'username' => 'will',
'password' => 'Sample123+',
'email' => 'will@gmail.com',
'firstname' => 'will',
'lastname' => 'will',
]);
// Assert that the permissions has been set
$this->assertTrue($testUser->hasPermission('view-process-catalog'));
// Clean
session(['permissions' => null]);
}

public function testCategoryPermission()
{
$context = function ($type, $class) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Api/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testDefaultValuesOfUser()
'lastname' => $faker->lastName(),
'email' => $faker->email(),
'status' => $faker->randomElement(['ACTIVE', 'INACTIVE']),
'password' => $faker->password(8) . 'A' . '1',
'password' => $faker->password(8) . 'A' . '1' . '+',
'datetime_format' => $dateFormat,
]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use ProcessMaker\Models\Permission;
use ProcessMaker\Upgrades\UpgradeMigration as Upgrade;

class CreatePermissionViewProcessCatalog extends Upgrade
{
/**
* Run the migrations.
*/
public function up(): void
{
Permission::updateOrCreate([
'name' => 'view-process-catalog',
], [
'title' => 'View Process Catalog',
'name' => 'view-process-catalog',
'group' => 'Process Catalog',
]);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Permission::where('name', 'view-process-catalog')->delete();
}
}

0 comments on commit fa72fe1

Please sign in to comment.