Ideenbox-Moderation und Wochenüberblick per E-Mail (0.36.0)
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
11c5ef5baf
commit
f9922f7308
172 changed files with 1524 additions and 363 deletions
|
|
@ -16,6 +16,8 @@ use Inertia\Inertia;
|
|||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Ideen\Models\Idea;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaComment;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaReport;
|
||||
use Inhaus\Plugins\Ideen\Moderation;
|
||||
use Inhaus\Plugins\Ideen\Presenter;
|
||||
|
||||
/**
|
||||
|
|
@ -33,6 +35,7 @@ class IdeaController extends Controller
|
|||
$user = $request->user();
|
||||
|
||||
$ideas = Idea::query()->with('author')
|
||||
->when(! $user->can('ideas.manage'), fn ($q) => $q->where(fn ($q) => $q->whereNull('hidden_at')->orWhere(fn ($q) => $q->where('author_id', $user->id)->where('anonymous', false))))
|
||||
->when($data['status'] ?? null, fn ($q, $status) => $q->where('status', $status))
|
||||
->when($data['q'] ?? null, fn ($q, $term) => $q->where(fn ($q) => $q->where('title', 'like', '%'.addcslashes($term, '%_\\').'%')->orWhere('body', 'like', '%'.addcslashes($term, '%_\\').'%')))
|
||||
->when(($data['sortierung'] ?? 'neu') === 'beliebt', fn ($q) => $q->orderByDesc('supports_count'))
|
||||
|
|
@ -58,11 +61,12 @@ class IdeaController extends Controller
|
|||
|
||||
public function show(Request $request, Idea $idea): Response|JsonResponse
|
||||
{
|
||||
$this->ensureVisible($request, $idea);
|
||||
$detail = Presenter::detail($idea->load('author'), $request->user());
|
||||
|
||||
return $this->wantsJson($request)
|
||||
? response()->json(['data' => $detail])
|
||||
: Inertia::render('ideen::Show', ['idea' => $detail, 'statuses' => Idea::STATUSES]);
|
||||
: Inertia::render('ideen::Show', ['idea' => $detail, 'statuses' => Idea::STATUSES, 'reasons' => IdeaReport::REASONS]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse|JsonResponse
|
||||
|
|
@ -109,6 +113,7 @@ class IdeaController extends Controller
|
|||
|
||||
public function support(Request $request, Idea $idea): RedirectResponse|JsonResponse
|
||||
{
|
||||
$this->ensureVisible($request, $idea);
|
||||
abort_if(! $idea->anonymous && $idea->author_id === $request->user()->id, 422, 'Die eigene Idee lässt sich nicht unterstützen.');
|
||||
$idea->supporters()->syncWithoutDetaching([$request->user()->id => ['created_at' => now()]]);
|
||||
|
||||
|
|
@ -124,6 +129,7 @@ class IdeaController extends Controller
|
|||
|
||||
public function comment(Request $request, Idea $idea): RedirectResponse|JsonResponse
|
||||
{
|
||||
$this->ensureVisible($request, $idea);
|
||||
$data = $request->validate(['body' => ['required', 'string', 'max:'.IdeaComment::MAX_LENGTH], 'official' => ['boolean']], [], ['body' => 'Kommentar']);
|
||||
$user = $request->user();
|
||||
$official = ($data['official'] ?? false) && $user->can('ideas.manage');
|
||||
|
|
@ -192,6 +198,51 @@ class IdeaController extends Controller
|
|||
return back()->with('status', 'Status gespeichert.');
|
||||
}
|
||||
|
||||
/** Etwas melden – die Idee selbst oder einen Kommentar */
|
||||
public function report(Request $request, Idea $idea, Moderation $moderation): RedirectResponse|JsonResponse
|
||||
{
|
||||
$this->ensureVisible($request, $idea);
|
||||
$data = $request->validate([
|
||||
'reason' => ['required', Rule::in(array_keys(IdeaReport::REASONS))],
|
||||
'note' => ['nullable', 'string', 'max:500'],
|
||||
'comment_id' => ['nullable', 'integer'],
|
||||
]);
|
||||
|
||||
$comment = isset($data['comment_id']) ? $idea->comments()->findOrFail($data['comment_id']) : null;
|
||||
$own = $comment ? $comment->user_id === $request->user()->id : (! $idea->anonymous && $idea->author_id === $request->user()->id);
|
||||
abort_if($own, 422, 'Eigene Beiträge lassen sich nicht melden.');
|
||||
|
||||
$moderation->report($idea, $comment, $request->user(), $data['reason'], filled($data['note'] ?? null) ? trim($data['note']) : null);
|
||||
|
||||
return $this->wantsJson($request)
|
||||
? response()->json(['message' => 'Danke, das Gremium sieht es sich an.'])
|
||||
: back()->with('status', 'Danke für den Hinweis – das Gremium sieht es sich an.');
|
||||
}
|
||||
|
||||
/** Gremium: Meldungen erledigen */
|
||||
public function moderate(Request $request, Idea $idea, Moderation $moderation): RedirectResponse
|
||||
{
|
||||
Gate::authorize('ideas.manage');
|
||||
$data = $request->validate(['comment_id' => ['nullable', 'integer'], 'action' => ['required', 'in:keep,remove']]);
|
||||
$comment = isset($data['comment_id']) ? $idea->comments()->findOrFail($data['comment_id']) : null;
|
||||
|
||||
$moderation->resolve($idea, $comment, $data['action'] === 'remove');
|
||||
Audit::log('idea.moderated', ['idea' => $idea->id, 'comment' => $comment?->id, 'action' => $data['action']]);
|
||||
|
||||
if ($data['action'] === 'remove' && ! $comment) {
|
||||
return to_route('ideas.index')->with('status', 'Idee gelöscht.');
|
||||
}
|
||||
|
||||
return back()->with('status', $data['action'] === 'remove' ? 'Kommentar gelöscht.' : 'Meldungen erledigt – der Inhalt ist wieder sichtbar.');
|
||||
}
|
||||
|
||||
/** Ausgeblendete Ideen sehen nur das Gremium und die einreichende Person */
|
||||
private function ensureVisible(Request $request, Idea $idea): void
|
||||
{
|
||||
$user = $request->user();
|
||||
abort_if($idea->hidden_at && ! $user->can('ideas.manage') && ($idea->anonymous || $idea->author_id !== $user->id), 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{title: string, body: string}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue