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
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('*');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue