Added the rest of the policy files
This commit is contained in:
parent
1233f02d40
commit
6511f3a248
8 changed files with 326 additions and 55 deletions
app/Policies
58
app/Policies/QuestionPolicy.php
Normal file
58
app/Policies/QuestionPolicy.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\User;
|
||||
use App\Question;
|
||||
use App\Test;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class QuestionPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can create questions.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
if ($user->isAdministrator() || $user->isModerator()) {
|
||||
dd("hit");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the question.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Question $question
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, Question $question)
|
||||
{
|
||||
if ($user->isAdministrator() || ($user->isModerator() AND $user->group_id === $question->test->group_id)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the question.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Question $question
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(User $user, Question $question)
|
||||
{
|
||||
if ($user->isAdministrator() || ($user->isModerator() AND $user->group_id === $question->test->group_id)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in a new issue