Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from laravel-enso/feature/roles
adds roles for allocatedTo
- Loading branch information
Showing
8 changed files
with
130 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Roles | ||
|-------------------------------------------------------------------------- | ||
| which roles can choose for allocated users | ||
| Values: ['*'] -> all roles, [ roles ] -> selected roles | ||
*/ | ||
'roles' => ['*'], | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Users; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Count; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Create; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Destroy; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Edit; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\ExportExcel; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Index; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\InitTable; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Store; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\TableData; | ||
use LaravelEnso\Tasks\Http\Controllers\Tasks\Update; | ||
|
||
Route::middleware(['api', 'auth', 'core']) | ||
->namespace('LaravelEnso\Tasks\Http\Controllers\Tasks') | ||
->prefix('api/tasks') | ||
->as('tasks.') | ||
->group(function () { | ||
Route::get('create', 'Create')->name('create'); | ||
Route::post('', 'Store')->name('store'); | ||
Route::get('{task}/edit', 'Edit')->name('edit'); | ||
Route::get('create', Create::class)->name('create'); | ||
Route::post('', Store::class)->name('store'); | ||
Route::get('{task}/edit', Edit::class)->name('edit'); | ||
|
||
Route::patch('{task}', 'Update')->name('update'); | ||
Route::patch('{task}', Update::class)->name('update'); | ||
|
||
Route::delete('{task}', 'Destroy')->name('destroy'); | ||
Route::delete('{task}', Destroy::class)->name('destroy'); | ||
|
||
Route::get('initTable', 'InitTable')->name('initTable'); | ||
Route::get('tableData', 'TableData')->name('tableData'); | ||
Route::get('exportExcel', 'ExportExcel')->name('exportExcel'); | ||
Route::get('initTable', InitTable::class)->name('initTable'); | ||
Route::get('tableData', TableData::class)->name('tableData'); | ||
Route::get('exportExcel', ExportExcel::class)->name('exportExcel'); | ||
|
||
Route::get('count', 'Count')->name('count'); | ||
Route::get('', 'Index')->name('index'); | ||
Route::get('count', Count::class)->name('count'); | ||
Route::get('', Index::class)->name('index'); | ||
|
||
Route::get('users', Users::class)->name('users'); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Tasks\Http\Controllers\Tasks; | ||
|
||
use Illuminate\Support\Facades\Config; | ||
use LaravelEnso\Core\Http\Controllers\Administration\User\Options as UserOptions; | ||
|
||
class Users extends UserOptions | ||
{ | ||
public function query() | ||
{ | ||
$roles = Config::get('enso.tasks.roles'); | ||
|
||
return parent::query() | ||
->when($roles !== ['*'], fn ($query) => $query->whereIn('role_id', $roles)); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Tasks\Upgrades; | ||
|
||
use LaravelEnso\Permissions\Models\Permission; | ||
use LaravelEnso\Upgrade\Contracts\MigratesStructure; | ||
use LaravelEnso\Upgrade\Traits\StructureMigration; | ||
|
||
class Role implements MigratesStructure | ||
{ | ||
use StructureMigration; | ||
|
||
protected $permissions = [ | ||
['name' => 'tasks.users', 'description' => 'Get user options for task allocation', 'is_default' => false], | ||
]; | ||
|
||
protected $roles; | ||
|
||
public function __construct() | ||
{ | ||
$this->roles = Permission::with('roles') | ||
->whereName('administration.users.options') | ||
->first() | ||
->roles | ||
->map(fn($role) => $role->name) | ||
->toArray(); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Config; | ||
use LaravelEnso\Core\Models\User; | ||
use Tests\TestCase; | ||
|
||
class AllocateToRolesTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->seed(); | ||
|
||
$this->actingAs(User::first()); | ||
} | ||
|
||
/** @test */ | ||
public function can_limit_roles() | ||
{ | ||
Config::set('enso.tasks.roles', []); | ||
|
||
$this->get(route('tasks.users'))->assertJson([]); | ||
} | ||
|
||
/** @test */ | ||
public function can_select_all_roles() | ||
{ | ||
Config::set('enso.tasks.roles', ['*']); | ||
|
||
$this->get(route('tasks.users'))->assertJsonCount(User::count()); | ||
} | ||
} |