add staff remove & staff invite test
This commit is contained in:
@@ -110,7 +110,17 @@ class EventController extends Controller
|
||||
|
||||
$this->authorize('delete', $event);
|
||||
|
||||
$event->guests()->updateExistingPivot($user, array('is_staff' => 1), false);
|
||||
$event->guests()->updateExistingPivot($user, ['is_staff' => true], false);
|
||||
|
||||
return (new EventResource($event))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
public function deleteGuestToStaffEvent(Event $event, User $user) {
|
||||
$this->authorize('delete', $event);
|
||||
|
||||
$event->guests()->updateExistingPivot($user, ['is_staff' => false], false);
|
||||
|
||||
return (new EventResource($event))
|
||||
->response()
|
||||
|
||||
@@ -28,7 +28,7 @@ class User extends JsonResource
|
||||
'last_login' => optional($this->login_at)->diffForHumans(),
|
||||
'is_admin' => $this->isAdmin(),
|
||||
'is_staff' => $this->whenPivotLoaded('event_guest', function() {
|
||||
return $this->pivot->is_staff;
|
||||
return (int) $this->pivot->is_staff;
|
||||
}),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -115,7 +115,7 @@ class User extends Authenticatable
|
||||
|
||||
public function invitedEvent(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Event::class, 'event_guest')
|
||||
return $this->belongsToMany(Event::class, 'event_guest', 'user_id', 'event_id')
|
||||
->withPivot('is_staff', 'validated_at')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
@@ -53,7 +53,15 @@ class EventPolicy
|
||||
*/
|
||||
public function update(User $user, Event $event)
|
||||
{
|
||||
return $user->id == $event->user_id;
|
||||
if($user->id == $event->user_id) {
|
||||
return true;
|
||||
} else {
|
||||
$testedUser = $event->guests()->where('users.id', $user->id)->first();
|
||||
if($testedUser !== null) {
|
||||
return $testedUser->pivot->is_staff;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user