update: limit user edit interval for torrents/requests

This commit is contained in:
Roardom
2024-01-28 11:53:45 +00:00
parent 71426b7e72
commit 8f0bc33058
5 changed files with 72 additions and 25 deletions
+22 -2
View File
@@ -58,7 +58,13 @@ class RequestController extends Controller
return view('requests.show', [
'torrentRequest' => $torrentRequest->load(['category', 'claim' => ['user'], 'bounties', 'torrent']),
'user' => $request->user(),
'meta' => match (true) {
'canEdit' => $request->user()->group->is_modo || TorrentRequest::query()
->whereDoesntHave('bounties', fn ($query) => $query->where('user_id', '!=', $request->user()->id))
->whereNull('claimed')
->whereNull('filled_by')
->whereKey($torrentRequest)
->exists(),
'meta' => match (true) {
($torrentRequest->category->tv_meta && $torrentRequest->tmdb) => Tv::with([
'genres',
'credits' => ['person', 'occupation'],
@@ -198,7 +204,21 @@ class RequestController extends Controller
{
$user = $request->user();
abort_unless($user->group->is_modo || $user->id === $torrentRequest->user_id, 403);
abort_unless(
(
$user->group->is_modo
|| (
$user->id === $torrentRequest->user_id
&& TorrentRequest::query()
->whereDoesntHave('bounties', fn ($query) => $query->where('user_id', '!=', $request->user()->id))
->whereNull('claimed')
->whereNull('filled_by')
->whereKey($torrentRequest)
->exists()
)
),
403
);
$torrentRequest->update($request->validated());
+23 -3
View File
@@ -125,8 +125,17 @@ class TorrentController extends Controller
}
return view('torrent.show', [
'torrent' => $torrent,
'user' => $user,
'torrent' => $torrent,
'user' => $user,
'canEdit' => $user->group->is_editor
|| $user->group->is_modo
|| (
$user->id === $torrent->user_id
&& (
$torrent->status !== Torrent::APPROVED
|| now()->isBefore($torrent->created_at->addDay())
)
),
'personal_freeleech' => cache()->get('personal_freeleech:'.$user->id),
'meta' => $meta,
'platforms' => $platforms,
@@ -185,7 +194,18 @@ class TorrentController extends Controller
$user = $request->user();
$torrent = Torrent::withoutGlobalScope(ApprovedScope::class)->findOrFail($id);
abort_unless($user->group->is_editor || $user->group->is_modo || $user->id === $torrent->user_id, 403);
abort_unless(
$user->group->is_editor
|| $user->group->is_modo
|| (
$user->id === $torrent->user_id
&& (
$torrent->status !== Torrent::APPROVED
|| now()->isBefore($torrent->created_at->addDay())
)
),
403
);
$torrent->update($request->validated());
@@ -1,8 +1,10 @@
<li class="form__group form__group--short-horizontal">
<a
class="form__button form__button--outlined form__button--centered"
href="{{ route('requests.edit', ['torrentRequest' => $torrentRequest]) }}"
>
{{ __('common.edit') }}
</a>
</li>
@if ($canEdit)
<li class="form__group form__group--short-horizontal">
<a
class="form__button form__button--outlined form__button--centered"
href="{{ route('requests.edit', ['torrentRequest' => $torrentRequest]) }}"
>
{{ __('common.edit') }}
</a>
</li>
@endif
@@ -14,7 +14,7 @@
flex-wrap: wrap;
"
>
@if (auth()->user()->group->is_editor || auth()->user()->group->is_modo || auth()->id() === $torrent->user_id)
@if (auth()->user()->group->is_editor || auth()->user()->group->is_modo || (auth()->id() === $torrent->user_id && $canEdit))
<li>
<menu
style="
@@ -25,16 +25,21 @@
flex-wrap: wrap;
"
>
<li>
<a
class="form__button form__button--outlined"
href="{{ route('torrents.edit', ['id' => $torrent->id]) }}"
role="button"
>
<i class="{{ config('other.font-awesome') }} fa-pencil-alt"></i>
{{ __('common.edit') }}
</a>
</li>
@if ($canEdit)
<li>
<a
class="form__button form__button--outlined"
href="{{ route('torrents.edit', ['id' => $torrent->id]) }}"
role="button"
>
<i
class="{{ config('other.font-awesome') }} fa-pencil-alt"
></i>
{{ __('common.edit') }}
</a>
</li>
@endif
@if (auth()->user()->group->is_modo || (auth()->id() === $torrent->user_id && Illuminate\Support\Carbon::now()->lt($torrent->created_at->addDay())))
<li x-data="dialog">
<button
+1 -1
View File
@@ -50,7 +50,7 @@
@include('torrent.partials.buttons')
{{-- Tools Block --}}
@if (auth()->user()->group->is_internal || auth()->user()->group->is_editor || auth()->user()->group->is_modo || auth()->id() === $torrent->user_id)
@if (auth()->user()->group->is_internal || auth()->user()->group->is_editor || auth()->user()->group->is_modo || (auth()->id() === $torrent->user_id && $canEdit))
@include('torrent.partials.tools')
@endif