123 lines
2.7 KiB
PHP
123 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
class EventPolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*
|
|
* @param \App\User $user
|
|
* @return mixed
|
|
*/
|
|
public function viewAny(User $user)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*
|
|
* @param \App\User $user
|
|
* @param \App\Models\Event $event
|
|
* @return mixed
|
|
*/
|
|
public function view(User $user, Event $event)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*
|
|
* @param \App\User $user
|
|
* @return mixed
|
|
*/
|
|
public function create(User $user)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @param \App\User $user
|
|
* @param \App\Models\Event $event
|
|
* @return mixed
|
|
*/
|
|
public function update(User $user, Event $event)
|
|
{
|
|
if ($user->id == $event->user_id) {
|
|
return true;
|
|
} else {
|
|
$testedUser = $event->guests()->where('users.id', $user->id)->first();
|
|
if ($testedUser !== null) {
|
|
if($testedUser->pivot->is_staff) {
|
|
return $testedUser->pivot->is_staff;
|
|
} else if (!$event->private) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @param \App\User $user
|
|
* @param \App\Models\Event $event
|
|
* @return mixed
|
|
*/
|
|
public function delete(User $user, Event $event)
|
|
{
|
|
return $user->id == $event->user_id;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can restore the model.
|
|
*
|
|
* @param \App\User $user
|
|
* @param \App\Models\Event $event
|
|
* @return mixed
|
|
*/
|
|
public function restore(User $user, Event $event)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can permanently delete the model.
|
|
*
|
|
* @param \App\User $user
|
|
* @param \App\Models\Event $event
|
|
* @return mixed
|
|
*/
|
|
public function forceDelete(User $user, Event $event)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the guest can permanently delete invitation.
|
|
*
|
|
* @param \App\User $user
|
|
* @param \App\Models\Event $event
|
|
* @return mixed
|
|
*/
|
|
public function participation(User $user, Event $event)
|
|
{
|
|
$testedUser = $event->guests()->where('users.id', $user->id)->first();
|
|
if ($testedUser !== null) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|