-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
159 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
app/Actions/HumanResources/Employee/UI/GetJobPositionsGroupData.php
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
app/Actions/HumanResources/Employee/UI/GetPermissionGroupData.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* Author: Raul Perusquia <[email protected]> | ||
* Created: Tue, 14 Mar 2023 19:13:28 Malaysia Time, Kuala Lumpur, Malaysia | ||
* Copyright (c) 2023, Raul A Perusquia Flores | ||
*/ | ||
|
||
namespace App\Actions\HumanResources\Employee\UI; | ||
|
||
use App\Models\HumanResources\Employee; | ||
use App\Models\SysAdmin\Group; | ||
use App\Models\SysAdmin\Guest; | ||
use App\Models\SysAdmin\User; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class GetPermissionGroupData | ||
{ | ||
use AsAction; | ||
|
||
public function handle(Employee|User|Guest $user, Group $group): array | ||
{ | ||
return (array) $user->permissions->map(function ($permission) use ($group) { | ||
return [$permission->name]; | ||
})->reduce(function ($carry, $item) { | ||
return array_merge_recursive($carry, $item); | ||
}, []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
app/Actions/SysAdmin/User/UpdateUsersModelHasPermission.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* Author: Raul Perusquia <[email protected]> | ||
* Created: Mon, 30 Sept 2024 18:51:48 Malaysia Time, Kuala Lumpur, Malaysia | ||
* Copyright (c) 2024, Raul A Perusquia Flores | ||
*/ | ||
|
||
namespace App\Actions\SysAdmin\User; | ||
|
||
use App\Actions\GrpAction; | ||
use App\Actions\Traits\WithPreparePositionsForValidation; | ||
use App\Actions\Traits\WithActionUpdate; | ||
use App\Actions\Traits\WithReorganisePositions; | ||
use App\Http\Resources\HumanResources\EmployeeResource; | ||
use App\Models\HumanResources\Employee; | ||
use App\Models\SysAdmin\Organisation; | ||
use App\Models\SysAdmin\User; | ||
use Illuminate\Support\Arr; | ||
use Lorisleiva\Actions\ActionRequest; | ||
|
||
class UpdateUsersModelHasPermission extends GrpAction | ||
{ | ||
use WithActionUpdate; | ||
use WithPreparePositionsForValidation; | ||
use WithReorganisePositions; | ||
|
||
protected bool $asAction = false; | ||
|
||
private Employee $employee; | ||
|
||
private User $user; | ||
|
||
|
||
private Organisation $organisation; | ||
|
||
public function handle(User $user, array $modelData): User | ||
{ | ||
$permissions = Arr::get($modelData, 'permissions', []); | ||
$positions = $this->reorganisePositionsSlugsToIds($permissions); | ||
|
||
$user->syncPermissions($positions); | ||
|
||
$user->refresh(); | ||
|
||
return $user; | ||
} | ||
|
||
|
||
public function authorize(ActionRequest $request): bool | ||
{ | ||
if ($this->asAction) { | ||
return true; | ||
} | ||
|
||
return $request->user()->hasPermissionTo("sysadmin.edit"); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'permissions' => ['sometimes', 'array'], | ||
'permissions.group' => ['sometimes', 'array'] | ||
]; | ||
} | ||
|
||
public function action(User $user, Organisation $organisation, $modelData): User | ||
{ | ||
$this->asAction = true; | ||
$this->user = $user; | ||
$this->organisation = $organisation; | ||
|
||
$this->initialisation($user->group, $modelData); | ||
|
||
return $this->handle($user, $this->validatedData); | ||
} | ||
|
||
public function prepareForValidation(ActionRequest $request): void | ||
{ | ||
$this->preparePositionsForValidation(); | ||
//todo check if is a valid current model (gust|employee) in user_has_models if is an active one reject | ||
|
||
|
||
} | ||
|
||
public function asController(User $user, ActionRequest $request): User | ||
{ | ||
$this->user = $user; | ||
|
||
$this->initialisation(app('group'), $request); | ||
|
||
return $this->handle($user, $this->validatedData); | ||
} | ||
|
||
public function jsonResponse(User $user): EmployeeResource | ||
{ | ||
return new EmployeeResource($user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters