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}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@
|
|||
namespace Inhaus\Plugins\Ideen;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Digest\Digest;
|
||||
use App\Editorial\Editorial;
|
||||
use App\Models\User;
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Inhaus\Plugins\Ideen\Models\Idea;
|
||||
|
||||
class IdeenPlugin extends Plugin
|
||||
|
|
@ -15,12 +17,22 @@ class IdeenPlugin extends Plugin
|
|||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('ideen', 'Ideenbox', '/ideen', active: 'ideas.*', sort: 76);
|
||||
$this->app->make(Digest::class)->add('ideen', 'Neue Ideen', 40, fn (User $user, CarbonImmutable $since) => Idea::query()
|
||||
->whereNull('hidden_at')->where('created_at', '>=', $since)->orderByDesc('supports_count')->latest()->limit(5)->get()
|
||||
->map(fn (Idea $idea) => [
|
||||
'title' => $idea->title,
|
||||
'url' => route('ideas.show', $idea),
|
||||
'meta' => $idea->supports_count.' '.($idea->supports_count === 1 ? 'Unterstützung' : 'Unterstützungen'),
|
||||
])->all());
|
||||
|
||||
$this->app->make(Abilities::class)->define('ideas.manage', 'Ideen bewerten, beantworten und moderieren (Gremium)', 'Ideenbox', portal: true);
|
||||
|
||||
// Redaktion: was das Gremium noch sichten muss
|
||||
$this->app->make(Editorial::class)->add('ideen', 'Ideenbox', 'ideen::EditorialIdeas', 34,
|
||||
fn (User $user) => $user->can('ideas.manage'),
|
||||
fn (User $user) => [
|
||||
'reported' => Idea::query()->with('author')->whereHas('reports', fn ($q) => $q->whereNull('resolved_at'))->withCount(['reports' => fn ($q) => $q->whereNull('resolved_at')])
|
||||
->latest()->limit(20)->get()->map(fn (Idea $idea) => [...Presenter::card($idea), 'reports' => $idea->reports_count, 'hidden' => $idea->hidden_at !== null])->all(),
|
||||
'ideas' => Idea::query()->with('author')->whereIn('status', ['new', 'review'])
|
||||
->orderByRaw("status = 'new' DESC")->orderByDesc('supports_count')->latest()->limit(30)->get()
|
||||
->map(fn (Idea $idea) => Presenter::card($idea))->all(),
|
||||
|
|
@ -28,7 +40,7 @@ class IdeenPlugin extends Plugin
|
|||
|
||||
// Startseite: beliebteste offene Ideen
|
||||
$this->app->make(Widgets::class)->add('ideen.popular', 'ideen::Popular', 'aside', sort: 28, props: function () {
|
||||
$ideas = Idea::query()->with('author')->whereIn('status', ['new', 'review'])->where('created_at', '>=', now()->subDays(60))
|
||||
$ideas = Idea::query()->with('author')->whereNull('hidden_at')->whereIn('status', ['new', 'review'])->where('created_at', '>=', now()->subDays(60))
|
||||
->orderByDesc('supports_count')->latest()->limit(3)->get();
|
||||
|
||||
return $ideas->isEmpty() ? null : ['ideas' => $ideas->map(fn (Idea $idea) => Presenter::card($idea))->all()];
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class Idea extends Model
|
|||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['anonymous' => 'boolean', 'status_changed_at' => 'datetime'];
|
||||
return ['anonymous' => 'boolean', 'status_changed_at' => 'datetime', 'hidden_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +48,14 @@ class Idea extends Model
|
|||
return $this->hasMany(IdeaComment::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<IdeaReport, $this>
|
||||
*/
|
||||
public function reports(): HasMany
|
||||
{
|
||||
return $this->hasMany(IdeaReport::class);
|
||||
}
|
||||
|
||||
public function statusLabel(): string
|
||||
{
|
||||
return self::STATUSES[$this->status] ?? $this->status;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class IdeaComment extends Model
|
|||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['official' => 'boolean'];
|
||||
return ['official' => 'boolean', 'hidden_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
49
plugins-core/ideen/src/Models/IdeaReport.php
Normal file
49
plugins-core/ideen/src/Models/IdeaReport.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ideen\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['idea_id', 'comment_id', 'user_id', 'reason', 'note', 'resolved_at'])]
|
||||
class IdeaReport extends Model
|
||||
{
|
||||
public const REASONS = [
|
||||
'offensive' => 'Beleidigend oder respektlos',
|
||||
'personal' => 'Nennt oder bloßstellt Personen',
|
||||
'confidential' => 'Vertrauliche Informationen',
|
||||
'spam' => 'Spam oder unpassend',
|
||||
'other' => 'Sonstiges',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['resolved_at' => 'datetime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<IdeaComment, $this>
|
||||
*/
|
||||
public function comment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(IdeaComment::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Idea, $this>
|
||||
*/
|
||||
public function idea(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Idea::class);
|
||||
}
|
||||
}
|
||||
87
plugins-core/ideen/src/Moderation.php
Normal file
87
plugins-core/ideen/src/Moderation.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Ideen;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Ideen\Models\Idea;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaComment;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaReport;
|
||||
|
||||
/**
|
||||
* Meldungen in der Ideenbox: Wer etwas Unpassendes sieht, meldet es. Ab drei Meldungen
|
||||
* verschiedener Personen wird der Inhalt vorläufig ausgeblendet, bis das Gremium entscheidet.
|
||||
*/
|
||||
class Moderation
|
||||
{
|
||||
public const HIDE_AFTER = 3;
|
||||
|
||||
public function report(Idea $idea, ?IdeaComment $comment, User $user, string $reason, ?string $note): void
|
||||
{
|
||||
$report = IdeaReport::query()->firstOrCreate(
|
||||
['user_id' => $user->id, 'idea_id' => $idea->id, 'comment_id' => $comment?->id],
|
||||
['reason' => $reason, 'note' => $note],
|
||||
);
|
||||
|
||||
if (! $report->wasRecentlyCreated) {
|
||||
return;
|
||||
}
|
||||
|
||||
$open = IdeaReport::query()->where('idea_id', $idea->id)->where('comment_id', $comment?->id)->whereNull('resolved_at')->count();
|
||||
$subject = $comment ?? $idea;
|
||||
|
||||
if ($open >= self::HIDE_AFTER && $subject->hidden_at === null) {
|
||||
$subject->forceFill(['hidden_at' => now()])->save();
|
||||
}
|
||||
|
||||
// Das Gremium bei der ersten offenen Meldung informieren (nicht bei jeder weiteren)
|
||||
if ($open === 1) {
|
||||
Notification::send($this->moderators()->reject(fn (User $u) => $u->id === $user->id), new PortalNotification(
|
||||
($comment ? 'Kommentar gemeldet: ' : 'Idee gemeldet: ').Str::limit($idea->title, 60),
|
||||
IdeaReport::REASONS[$reason] ?? $reason,
|
||||
route('ideas.show', $idea, false).($comment ? '#kommentar-'.$comment->id : ''),
|
||||
'flag',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gremium: Meldungen erledigen – Inhalt bleibt (wieder sichtbar) oder wird gelöscht.
|
||||
*/
|
||||
public function resolve(Idea $idea, ?IdeaComment $comment, bool $remove): void
|
||||
{
|
||||
IdeaReport::query()->where('idea_id', $idea->id)->where('comment_id', $comment?->id)->whereNull('resolved_at')->update(['resolved_at' => now()]);
|
||||
|
||||
if ($remove) {
|
||||
$comment ? $comment->delete() : $idea->delete();
|
||||
$comment && $idea->refreshCounts();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
($comment ?? $idea)->forceFill(['hidden_at' => null])->save();
|
||||
}
|
||||
|
||||
public function openCount(): int
|
||||
{
|
||||
return IdeaReport::query()->whereNull('resolved_at')->distinct()->count('idea_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Wer das Recht „ideas.manage“ über eine Rolle hat – ohne solche Personen die Administration.
|
||||
*
|
||||
* @return Collection<int, User>
|
||||
*/
|
||||
public function moderators(): Collection
|
||||
{
|
||||
$holders = fn (string $ability) => User::query()->active()
|
||||
->whereHas('roles.grants', fn ($q) => $q->where('ability', $ability))->limit(50)->get();
|
||||
|
||||
$moderators = $holders('ideas.manage');
|
||||
|
||||
return $moderators->isNotEmpty() ? $moderators : $holders('*');
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use App\Models\User;
|
|||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Ideen\Models\Idea;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaComment;
|
||||
use Inhaus\Plugins\Ideen\Models\IdeaReport;
|
||||
|
||||
class Presenter
|
||||
{
|
||||
|
|
@ -35,6 +36,11 @@ class Presenter
|
|||
public static function detail(Idea $idea, User $user): array
|
||||
{
|
||||
$manager = $user->can('ideas.manage');
|
||||
$reports = IdeaReport::query()->where('idea_id', $idea->id)->get();
|
||||
$mineReported = $reports->where('user_id', $user->id)->map(fn ($r) => $r->comment_id ?? 0)->all();
|
||||
// Für das Gremium: offene Meldungen je Inhalt – Gründe und Anmerkungen, ohne Namen der Meldenden
|
||||
$open = fn (?int $commentId) => $manager ? $reports->whereNull('resolved_at')->where('comment_id', $commentId)->values()
|
||||
->map(fn (IdeaReport $r) => ['reason' => IdeaReport::REASONS[$r->reason] ?? $r->reason, 'note' => $r->note])->all() : [];
|
||||
|
||||
return [
|
||||
...self::card($idea, $idea->supporters()->whereKey($user->id)->exists()),
|
||||
|
|
@ -45,10 +51,17 @@ class Presenter
|
|||
'mine' => ! $idea->anonymous && $idea->author_id === $user->id,
|
||||
'can_edit' => ! $idea->anonymous && $idea->author_id === $user->id && $idea->status === 'new',
|
||||
'can_manage' => $manager,
|
||||
'hidden' => $idea->hidden_at !== null,
|
||||
'reported' => in_array(0, $mineReported, true),
|
||||
'reports' => $open(null),
|
||||
'comment_list' => $idea->comments()->with('user')->oldest()->oldest('id')->limit(500)->get()
|
||||
->map(fn (IdeaComment $c) => [
|
||||
'id' => $c->id,
|
||||
'body' => $c->body,
|
||||
// Ausgeblendet: nur Gremium und die schreibende Person sehen den Text
|
||||
'body' => $c->hidden_at && ! $manager && $c->user_id !== $user->id ? null : $c->body,
|
||||
'hidden' => $c->hidden_at !== null,
|
||||
'reported' => in_array($c->id, $mineReported, true),
|
||||
'reports' => $open($c->id),
|
||||
'official' => $c->official,
|
||||
'created_at' => $c->created_at?->toIso8601String(),
|
||||
'author' => $c->user ? ['id' => $c->user->id, 'name' => $c->user->name, 'initials' => $c->user->initials, 'avatar_url' => $c->user->avatarUrl(64)] : null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue