Browse Source

Merge branch 'feature/semtypes' of b12f/sas-php into develop

develop
Benjamin Bädorf 4 years ago
committed by Gogs
parent
commit
b0f7deddfb
  1. 13
      api/app/Http/Controllers/SeminarTypeController.php
  2. 4
      api/app/Http/Requests/CreateSeminarRequest.php
  3. 33
      api/app/Http/Requests/DeleteSeminarTypeRequest.php
  4. 33
      api/app/Http/Requests/SeminarTypeRequest.php
  5. 30
      api/app/Http/Requests/ShowSeminarTypesRequest.php
  6. 25
      api/app/Models/Role.php

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

@ -4,6 +4,9 @@ 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;
@ -14,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);
@ -26,7 +29,7 @@ class SeminarTypeController extends Controller
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(SeminarTypeRequest $request)
{
$seminarType = new SeminarType($request->all());
if(!$seminarType->save()) {
@ -43,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);
}
@ -55,7 +58,7 @@ class SeminarTypeController extends Controller
* @param \App\SeminarType $seminarType
* @return \Illuminate\Http\Response
*/
public function update(Request $request, SeminarType $seminarType)
public function update(SeminarTypeRequest $request, SeminarType $seminarType)
{
$seminarType->update($request->all());
if(!$seminarType->save()) {
@ -70,7 +73,7 @@ class SeminarTypeController extends Controller
* @param \App\SeminarType $seminarType
* @return \Illuminate\Http\Response
*/
public function destroy(SeminarType $seminarType)
public function destroy(DeleteSeminarRequest $request, SeminarType $seminarType)
{
// TODO: map all seminars to null type

4
api/app/Http/Requests/CreateSeminarRequest.php

@ -2,8 +2,6 @@
namespace App\Http\Requests;
use Auth;
use Config;
use Illuminate\Foundation\Http\FormRequest;
class CreateSeminarRequest extends FormRequest
@ -23,6 +21,6 @@ class CreateSeminarRequest extends FormRequest
public function authorize()
{
return Auth::user()->role->hasRight('SEMINAR_WRITE');
return \Auth::user()->role->hasRight('SEMINAR_WRITE');
}
}

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

@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class DeleteSeminarTypeRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return \Auth::user()->role->hasRight('SEMINAR_TYPE_ADMIN');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string',
'description' => 'nullable|string',
'deposit' => 'numeric|min:0',
'place' => 'nullable|string',
];
}
}

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

@ -0,0 +1,33 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SeminarTypeRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return \Auth::user()->role->hasRight('SEMINAR_TYPE_ADMIN');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string',
'description' => 'nullable|string',
'deposit' => 'numeric|min:0',
'place' => 'nullable|string',
];
}
}

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