diff --git a/app/Http/Controllers/VoteController.php b/app/Http/Controllers/VoteController.php index 64ba3bdef..21fb81625 100644 --- a/app/Http/Controllers/VoteController.php +++ b/app/Http/Controllers/VoteController.php @@ -124,6 +124,8 @@ public function update(Request $request, $id) { $vote = Vote::findOrFail($id); + $this->authorize('vote', [Vote::class, $vote]); + if (! $this->isVoteValid($vote)) { return back()->withInput()->withErrors('You vote could not be registered. The vote deadline has passed.'); } diff --git a/app/Policies/VotePolicy.php b/app/Policies/VotePolicy.php index ed8735eb7..0a96da97f 100644 --- a/app/Policies/VotePolicy.php +++ b/app/Policies/VotePolicy.php @@ -49,10 +49,15 @@ public function store(User $user) */ public function vote(User $user, Vote $vote) { + if ($vote->closed) { return Response::deny('The vote closed and concluded at ' . Carbon::create($vote->end_at)->toEuropeanDateTime()); } + if ($vote->user->contains('id', $user->id)) { + return Response::deny('You have already voted.'); + } + if ($vote->require_member) { if ($user->subdivision != config('app.owner_code')) { return Response::deny('Sorry, you do not qualify to participate in this vote. You must belong to ' . config('app.owner_name') . ' to vote.'); diff --git a/resources/views/vote/show.blade.php b/resources/views/vote/show.blade.php index a4d28aab1..c05423139 100644 --- a/resources/views/vote/show.blade.php +++ b/resources/views/vote/show.blade.php @@ -15,34 +15,27 @@ @can('vote', $vote) - @if($vote->user()->where('user_id', \Auth::user()->id)->exists()) - -

You've already voted.

- - @else -
- @method('PATCH') - @csrf - - @foreach( $vote->option as $votefor ) -
- - -
- @endforeach - @error('vote') - {{ $errors->first('vote') }} - @enderror - -
-

Your vote is secret and can not be traced. The vote is final and cannot be changed.

- - -
- - @endif +
+ @method('PATCH') + @csrf + + @foreach( $vote->option as $votefor ) +
+ + +
+ @endforeach + @error('vote') + {{ $errors->first('vote') }} + @enderror + +
+

Your vote is secret and can not be traced. The vote is final and cannot be changed.

+ + +
@else

{{ Gate::inspect('vote', $vote)->message() }}