-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #55 - change routes for admin * #43 - permission policy #94 - add permissions * CR Co-authored-by: KD <do>
- Loading branch information
1 parent
3bb1bb6
commit be83c53
Showing
26 changed files
with
549 additions
and
97 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
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,42 @@ | ||
<?php | ||
|
||
namespace EscolaLms\HeadlessH5P\Database\Seeders; | ||
|
||
use EscolaLms\HeadlessH5P\Enums\H5PPermissionsEnum; | ||
use Illuminate\Database\Seeder; | ||
use Spatie\Permission\Models\Permission; | ||
use Spatie\Permission\Models\Role; | ||
|
||
/** | ||
* @todo remove neccesity of using 'web' guard | ||
*/ | ||
class PermissionTableSeeder extends Seeder | ||
{ | ||
public function run() | ||
{ | ||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions(); | ||
|
||
$apiAdmin = Role::findOrCreate('admin', 'api'); | ||
$webAdmin = Role::findOrCreate('admin', 'web'); | ||
$permissions = [ | ||
H5PPermissionsEnum::H5P_LIST, | ||
H5PPermissionsEnum::H5P_READ, | ||
H5PPermissionsEnum::H5P_DELETE, | ||
H5PPermissionsEnum::H5P_UPDATE, | ||
H5PPermissionsEnum::H5P_CREATE, | ||
H5PPermissionsEnum::H5P_LIBRARY_LIST, | ||
H5PPermissionsEnum::H5P_LIBRARY_READ, | ||
H5PPermissionsEnum::H5P_LIBRARY_DELETE, | ||
H5PPermissionsEnum::H5P_LIBRARY_UPDATE, | ||
H5PPermissionsEnum::H5P_LIBRARY_CREATE, | ||
]; | ||
|
||
foreach ($permissions as $permission) { | ||
Permission::findOrCreate($permission, 'api'); | ||
Permission::findOrCreate($permission, 'web'); | ||
} | ||
|
||
$apiAdmin->givePermissionTo($permissions); | ||
$webAdmin->givePermissionTo($permissions); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace EscolaLms\HeadlessH5P; | ||
|
||
use EscolaLms\HeadlessH5P\Models\H5PContent; | ||
use EscolaLms\HeadlessH5P\Models\H5PLibrary; | ||
use EscolaLms\HeadlessH5P\Policies\H5PContentPolicy; | ||
use EscolaLms\HeadlessH5P\Policies\H5PLibraryPolicy; | ||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | ||
|
||
class AuthServiceProvider extends ServiceProvider | ||
{ | ||
protected $policies = [ | ||
H5PContent::class => H5PContentPolicy::class, | ||
H5PLibrary::class => H5PLibraryPolicy::class, | ||
]; | ||
|
||
public function boot() | ||
{ | ||
$this->registerPolicies(); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace EscolaLms\HeadlessH5P\Enums; | ||
|
||
use EscolaLms\Core\Enums\BasicEnum; | ||
|
||
class H5PPermissionsEnum extends BasicEnum | ||
{ | ||
const H5P_LIST = 'h5p_list'; | ||
const H5P_READ = 'h5p_read'; | ||
const H5P_CREATE = 'h5p_create'; | ||
const H5P_DELETE = 'h5p_delete'; | ||
const H5P_UPDATE = 'h5p_update'; | ||
|
||
const H5P_LIBRARY_LIST = 'h5p_library_list'; | ||
const H5P_LIBRARY_READ = 'h5p_library_read'; | ||
const H5P_LIBRARY_CREATE = 'h5p_library_create'; | ||
const H5P_LIBRARY_DELETE = 'h5p_library_delete'; | ||
const H5P_LIBRARY_UPDATE = 'h5p_library_update'; | ||
} |
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
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,23 @@ | ||
<?php | ||
|
||
namespace EscolaLms\HeadlessH5P\Http\Requests; | ||
|
||
use EscolaLms\HeadlessH5P\Repositories\Contracts\H5PContentRepositoryContract; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class ContentDeleteRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
$h5PContentRepository = app(H5PContentRepositoryContract::class); | ||
$h5pContent = $h5PContentRepository->show($this->route('id')); | ||
|
||
return Gate::allows('delete', $h5pContent); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return []; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace EscolaLms\HeadlessH5P\Http\Requests; | ||
|
||
use EscolaLms\HeadlessH5P\Models\H5PContent; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class ContentListRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return Gate::allows('list', H5PContent::class); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return []; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace EscolaLms\HeadlessH5P\Http\Requests; | ||
|
||
use EscolaLms\HeadlessH5P\Repositories\Contracts\H5PContentRepositoryContract; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class ContentReadRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
$h5PContentRepository = app(H5PContentRepositoryContract::class); | ||
$h5pContent = $h5PContentRepository->show($this->route('id')); | ||
|
||
return Gate::allows('read', $h5pContent); | ||
} | ||
|
||
public function rules(): array | ||
{ | ||
return []; | ||
} | ||
} |
Oops, something went wrong.