finish event with log user participation
This commit is contained in:
@@ -130,4 +130,24 @@ class EventController extends Controller
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
public function userConfirmParticipation(Event $event)
|
||||
{
|
||||
$this->authorize('participation', $event);
|
||||
|
||||
$event->guests()->updateExistingPivot(auth()->user(), ['validated_at' => now()->toDateTimeString()], false);
|
||||
|
||||
return (new EventResource($event))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
public function userDeleteInvitation(Event $event)
|
||||
{
|
||||
$this->authorize('participation', $event);
|
||||
|
||||
$event->guests()->detach(auth()->user());
|
||||
|
||||
return response([], 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ class User extends JsonResource
|
||||
'is_staff' => $this->whenPivotLoaded('event_guest', function () {
|
||||
return (int) $this->pivot->is_staff;
|
||||
}),
|
||||
'validated_at' => $this->whenPivotLoaded('event_guest', function () {
|
||||
return (int) $this->pivot->validated_at;
|
||||
}),
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
|
||||
@@ -58,7 +58,11 @@ class EventPolicy
|
||||
} else {
|
||||
$testedUser = $event->guests()->where('users.id', $user->id)->first();
|
||||
if ($testedUser !== null) {
|
||||
return $testedUser->pivot->is_staff;
|
||||
if($testedUser->pivot->is_staff) {
|
||||
return $testedUser->pivot->is_staff;
|
||||
} else if (!$event->private) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -99,4 +103,20 @@ class EventPolicy
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user