Skip to content

Commit 84d51cb

Browse files
committed
add more strict requirements
1 parent 9a23d4d commit 84d51cb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

app/Http/Controllers/Gallery/PhotoController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ public function star(SetPhotosStarredRequest $request): void
181181
*/
182182
public function rate(SetPhotoRatingRequest $request, Rating $rating): PhotoResource
183183
{
184-
if (!$request->configs()->getValueAsBool('rating_enabled')) {
185-
throw new ConfigurationException('photo rating feature is disabled by configuration');
186-
}
187-
188184
/** @var \App\Models\User $user */
189185
$user = Auth::user();
190186

app/Http/Requests/Photo/SetPhotoRatingRequest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use App\Models\Photo;
1616
use App\Policies\PhotoPolicy;
1717
use App\Rules\RandomIDRule;
18+
use Illuminate\Support\Facades\Auth;
1819
use Illuminate\Support\Facades\Gate;
1920

2021
/**
@@ -31,6 +32,14 @@ class SetPhotoRatingRequest extends BaseApiRequest implements HasPhoto
3132
*/
3233
public function authorize(): bool
3334
{
35+
if (!$this->configs()->getValueAsBool('rating_enabled')) {
36+
return false;
37+
}
38+
39+
if (Auth::guest()) {
40+
return false;
41+
}
42+
3443
return Gate::check(PhotoPolicy::CAN_SEE, [Photo::class, $this->photo]);
3544
}
3645

@@ -53,7 +62,7 @@ protected function processValidatedValues(array $values, array $files): void
5362
/** @var ?string $photo_id */
5463
$photo_id = $values[RequestAttribute::PHOTO_ID_ATTRIBUTE];
5564
$this->photo = Photo::query()
56-
->with(['albums'])
65+
->with(['albums', 'rating'])
5766
->findOrFail($photo_id);
5867
$this->rating = intval($values[RequestAttribute::RATING_ATTRIBUTE]);
5968
}

0 commit comments

Comments
 (0)