Browse Source

Updated seminar type requests

develop^2
Benjamin Bädorf 4 years ago
parent
commit
6d5c282022
  1. 5
      api/app/Http/Controllers/SeminarTypeController.php
  2. 2
      api/app/Http/Requests/DeleteSeminarTypeRequest.php
  3. 2
      api/app/Http/Requests/SeminarTypeRequest.php
  4. 30
      api/app/Http/Requests/ShowSeminarTypesRequest.php
  5. 25
      api/app/Models/Role.php

5
api/app/Http/Controllers/SeminarTypeController.php

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\SeminarType;
use Illuminate\Http\Request;
use App\Http\Requests\SeminarTypeRequest;
use App\Http\Requests\ShowSeminarTypesRequest;
use App\Http\Requests\DeleteSeminarTypeRequest;
use App\Http\Resources\SeminarType as SeminarTypeResource;
use App\Http\Resources\SeminarTypes as SeminarTypeCollection;
@ -16,7 +17,7 @@ class SeminarTypeController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function index()
public function index(ShowSeminarTypesRequest $request)
{
$seminarTypes = SeminarType::all();
return new SeminarTypeCollection($seminarTypes);
@ -45,7 +46,7 @@ class SeminarTypeController extends Controller
* @param \App\SeminarType $seminarType
* @return \Illuminate\Http\Response
*/
public function show(SeminarType $seminarType)
public function show(ShowSeminarTypesRequest $request, SeminarType $seminarType)
{
return new SeminarTypeResource($seminarType);
}

2
api/app/Http/Requests/DeleteSeminarTypeRequest.php

@ -13,7 +13,7 @@ class DeleteSeminarTypeRequest extends FormRequest
*/
public function authorize()
{
return \Auth::user()->role->hasRight('SEMINAR_TYPE_DELETE');
return \Auth::user()->role->hasRight('SEMINAR_TYPE_ADMIN');
}
/**

2
api/app/Http/Requests/SeminarTypeRequest.php

@ -13,7 +13,7 @@ class SeminarTypeRequest extends FormRequest
*/
public function authorize()
{
return \Auth::user()->role->hasRight('SEMINAR_TYPE_WRITE');
return \Auth::user()->role->hasRight('SEMINAR_TYPE_ADMIN');
}
/**

30
api/app/Http/Requests/ShowSeminarTypesRequest.php

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ShowSeminarTypesRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return \Auth::user()->role->hasOneRight(['SEMINAR_WRITE', 'SEMINAR_TYPE_ADMIN']);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

25
api/app/Models/Role.php

@ -20,16 +20,9 @@ class Role extends UuidModel
'SEMINAR_WRITE',
'SEMINAR_DELETE',
'SEMINAR_TYPE_LIST',
'SEMINAR_TYPE_WRITE',
'SEMINAR_TYPE_DELETE',
// 'FACULTY_LIST',
'FACULTY_WRITE',
'FACULTY_DELETE',
'STUDENT_COUNCIL_WRITE',
'STUDENT_COUNCIL_DELETE',
'SEMINAR_TYPE_ADMIN',
'FACULTY_ADMIN',
'STUDENT_COUNCIL_ADMIN',
'APPLICATION_HAVE',
@ -69,7 +62,7 @@ class Role extends UuidModel
return in_array($right, $this->rights);
}
public function hasRights(Array $rights)
public function hasAllRights(Array $rights)
{
foreach ($rights as $right) {
if (!$this->hasRight($right)) {
@ -79,6 +72,16 @@ class Role extends UuidModel
return true;
}
public function hasOneRight(Array $rights)
{
foreach ($rights as $right) {
if ($this->hasRight($right)) {
return true;
}
}
return true;
}
public function users()
{
return $this->hasMany(App\User::class);

Loading…
Cancel
Save