Skip to content

Commit cfe2b8f

Browse files
committed
Begin integration for Blade stack
1 parent cbf6787 commit cfe2b8f

File tree

7 files changed

+142
-2
lines changed

7 files changed

+142
-2
lines changed

routes/blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
Route::post('restore', [ThreadController::class, 'restore'])->name('thread.restore');
4949
Route::post('rename', [ThreadController::class, 'rename'])->name('thread.rename');
5050
Route::delete('/', [ThreadController::class, 'delete'])->name('thread.delete');
51+
Route::post('approve', [ThreadController::class, 'approve'])->name('thread.approve');
52+
Route::post('unapprove', [ThreadController::class, 'unapprove'])->name('thread.unapprove');
5153

5254
Route::get('reply', [PostController::class, 'create'])->name('post.create');
5355
Route::post('reply', [PostController::class, 'store'])->name('post.store');
@@ -57,6 +59,8 @@
5759
Route::get($prefix['post'] . '/{post_id}/restore', [PostController::class, 'confirmRestore'])->name('post.confirm-restore');
5860
Route::delete($prefix['post'] . '/{post_id}', [PostController::class, 'delete'])->name('post.delete');
5961
Route::post($prefix['post'] . '/{post_id}/restore', [PostController::class, 'restore'])->name('post.restore');
62+
Route::post($prefix['post'] . '/{post_id}/approve', [PostController::class, 'approve'])->name('post.approve');
63+
Route::post($prefix['post'] . '/{post_id}/unapprove', [PostController::class, 'unapprove'])->name('post.unapprove');
6064
});
6165
});
6266

@@ -74,11 +78,15 @@
7478
Route::post('unpin', [BulkThreadController::class, 'unpin'])->name('unpin');
7579
Route::delete('/', [BulkThreadController::class, 'delete'])->name('delete');
7680
Route::post('restore', [BulkThreadController::class, 'restore'])->name('restore');
81+
Route::post('approve', [BulkThreadController::class, 'approve'])->name('approve');
82+
Route::post('unapprove', [BulkThreadController::class, 'unapprove'])->name('unapprove');
7783
});
7884

7985
// Posts
8086
Route::prefix('post')->name('post.')->group(function () {
8187
Route::post('restore', [BulkPostController::class, 'restore'])->name('restore');
8288
Route::delete('/', [BulkPostController::class, 'delete'])->name('delete');
89+
Route::post('approve', [BulkPostController::class, 'approve'])->name('approve');
90+
Route::post('unapprove', [BulkPostController::class, 'unapprove'])->name('unapprove');
8391
});
8492
});

src/Http/Controllers/Blade/ThreadController.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TeamTeaTime\Forum\Events\UserViewingRecent;
1111
use TeamTeaTime\Forum\Events\UserViewingThread;
1212
use TeamTeaTime\Forum\Events\UserViewingUnread;
13+
use TeamTeaTime\Forum\Http\Requests\ApproveThread;
1314
use TeamTeaTime\Forum\Http\Requests\CreateThread;
1415
use TeamTeaTime\Forum\Http\Requests\DeleteThread;
1516
use TeamTeaTime\Forum\Http\Requests\LockThread;
@@ -18,6 +19,7 @@
1819
use TeamTeaTime\Forum\Http\Requests\PinThread;
1920
use TeamTeaTime\Forum\Http\Requests\RenameThread;
2021
use TeamTeaTime\Forum\Http\Requests\RestoreThread;
22+
use TeamTeaTime\Forum\Http\Requests\UnapproveThread;
2123
use TeamTeaTime\Forum\Http\Requests\UnlockThread;
2224
use TeamTeaTime\Forum\Http\Requests\UnpinThread;
2325
use TeamTeaTime\Forum\Models\Category;
@@ -246,4 +248,30 @@ public function restore(RestoreThread $request): RedirectResponse
246248

247249
return new RedirectResponse(Forum::route('thread.show', $thread));
248250
}
251+
252+
public function approve(ApproveThread $request): RedirectResponse
253+
{
254+
$thread = $request->fulfill();
255+
256+
if ($thread === null) {
257+
return $this->invalidSelectionResponse();
258+
}
259+
260+
Forum::alert('success', 'threads.approved');
261+
262+
return new RedirectResponse(Forum::route('thread.show', $thread));
263+
}
264+
265+
public function unapprove(UnapproveThread $request): RedirectResponse
266+
{
267+
$thread = $request->fulfill();
268+
269+
if ($thread === null) {
270+
return $this->invalidSelectionResponse();
271+
}
272+
273+
Forum::alert('success', 'threads.unapproved');
274+
275+
return new RedirectResponse(Forum::route('thread.show', $thread));
276+
}
249277
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace TeamTeaTime\Forum\Http\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use TeamTeaTime\Forum\{
7+
Actions\ApproveThread as Action,
8+
Events\UserApprovedThread,
9+
Support\Authorization\ThreadAuthorization,
10+
};
11+
12+
class ApproveThread extends FormRequest implements FulfillableRequestInterface
13+
{
14+
public function authorize(): bool
15+
{
16+
return ThreadAuthorization::approve($this->user(), $this->route('thread'));
17+
}
18+
19+
public function rules(): array
20+
{
21+
return [];
22+
}
23+
24+
public function fulfill()
25+
{
26+
$action = new Action($this->route('thread'));
27+
$thread = $action->execute();
28+
29+
if ($thread !== null) {
30+
UserApprovedThread::dispatch($this->user(), $thread);
31+
}
32+
33+
return $thread;
34+
}
35+
}

src/Http/Requests/DeleteThread.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function fulfill()
3030
$action = new Action($this->route('thread'), $this->shouldPermaDelete(isset($this->validated()['permadelete']) && $this->validated()['permadelete']));
3131
$thread = $action->execute();
3232

33-
if (!$thread === null) {
33+
if ($thread !== null) {
3434
UserDeletedThread::dispatch($this->user(), $thread);
3535
}
3636

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace TeamTeaTime\Forum\Http\Requests;
4+
5+
use TeamTeaTime\Forum\{
6+
Actions\UnapproveThread as Action,
7+
Events\UserUnapprovedThread,
8+
};
9+
10+
class UnapproveThread extends ApproveThread
11+
{
12+
public function fulfill()
13+
{
14+
$action = new Action($this->route('thread'));
15+
$thread = $action->execute();
16+
17+
UserUnapprovedThread::dispatch($this->user(), $thread);
18+
19+
return $thread;
20+
}
21+
}

ui-presets/blade-tailwind/views/thread/partials/list.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
@if ($thread->trashed())
2828
<x-forum::badge type="danger">{{ trans('forum::general.deleted') }}</x-forum::badge>
2929
@endif
30+
@if (!$thread->isApproved)
31+
<x-forum::badge type="warning">{{ trans('forum::general.pending_approval') }}</x-forum::badge>
32+
@endif
3033
<x-forum::badge :style="(isset($category) && $category->color_light_mode) ? 'background: '.$category->color_light_mode .';' : null">
3134
{{ trans('forum::general.replies') }}:
3235
{{ $thread->reply_count }}

ui-presets/blade-tailwind/views/thread/show.blade.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
@if (Gate::allows('lockThreads', $category)
2727
|| Gate::allows('pinThreads', $category)
2828
|| Gate::allows('rename', $thread)
29-
|| Gate::allows('moveThreadsFrom', $category))
29+
|| Gate::allows('moveThreadsFrom', $category)
30+
|| (Gate::allows('approveThreads') && Gate::allows('approveThreads', $category)))
3031
<x-forum::button-group>
3132
@if (!$thread->trashed())
3233
@can ('lockThreads', $category)
@@ -61,6 +62,17 @@
6162
<i data-feather="corner-up-right" class="w-4"></i> {{ trans('forum::general.move') }}
6263
</x-forum::button-link>
6364
@endcan
65+
@if (Gate::allows('approveThreads') && Gate::allows('approveThreads', $category))
66+
@if ($thread->isApproved)
67+
<x-forum::button-link href="#" data-open-modal="unapprove-thread" class="inline-flex items-center gap-2 bg-gray-500 hover:bg-gray-400">
68+
<i data-feather="x-circle" class="w-4"></i> {{ trans('forum::general.unapprove') }}
69+
</x-forum::button-link>
70+
@else
71+
<x-forum::button-link href="#" data-open-modal="approve-thread" class="inline-flex items-center gap-2 bg-gray-500 hover:bg-gray-400">
72+
<i data-feather="check-circle" class="w-4"></i> {{ trans('forum::general.approve') }}
73+
</x-forum::button-link>
74+
@endif
75+
@endif
6476
@endif
6577
</x-forum::button-group>
6678
@endcan
@@ -77,6 +89,9 @@
7789
@if ($thread->locked)
7890
<x-forum::badge type="warning">{{ trans('forum::threads.locked') }}</x-forum::badge>
7991
@endif
92+
@if (!$thread->isApproved)
93+
<x-forum::badge type="warning">{{ trans('forum::general.pending_approval') }}</x-forum::badge>
94+
@endif
8095
</div>
8196

8297
@if ((count($posts) > 1 || $posts->currentPage() > 1) && (Gate::allows('deletePosts', $thread) || Gate::allows('restorePosts', $thread)) && count($selectablePosts) > 0)
@@ -334,6 +349,36 @@
334349
@endslot
335350
@endcomponent
336351
@endcan
352+
353+
@if (Gate::allows('approveThreads') && Gate::allows('approveThreads', $category))
354+
@if ($thread->isApproved)
355+
@component('forum::modal-form')
356+
@slot('key', 'unapprove-thread')
357+
@slot('title', '<i data-feather="x-circle" class="text-gray-500"></i> ' . trans('forum::general.unapprove'))
358+
@slot('route', Forum::route('thread.unapprove', $thread))
359+
@slot('method', 'POST')
360+
361+
{{ trans('forum::general.generic_confirm') }}
362+
363+
@slot('actions')
364+
<x-forum::button type="submit">{{ trans('forum::general.proceed') }}</x-forum::button>
365+
@endslot
366+
@endcomponent
367+
@else
368+
@component('forum::modal-form')
369+
@slot('key', 'approve-thread')
370+
@slot('title', '<i data-feather="check-circle" class="text-gray-500"></i> ' . trans('forum::general.approve'))
371+
@slot('route', Forum::route('thread.approve', $thread))
372+
@slot('method', 'POST')
373+
374+
{{ trans('forum::general.generic_confirm') }}
375+
376+
@slot('actions')
377+
<x-forum::button type="submit">{{ trans('forum::general.proceed') }}</x-forum::button>
378+
@endslot
379+
@endcomponent
380+
@endif
381+
@endif
337382
@endif
338383

339384
<script type="module">

0 commit comments

Comments
 (0)