Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/Http/Controllers/Admin/ChatSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ChatSettingsController extends Controller
{
public function edit()
{
$bannedWords = AppSetting::get('global_chat_banned_words', '');
$bannedWordsText = is_array($bannedWords) ? implode(', ', $bannedWords) : (string) $bannedWords;
$allowedEmojis = AppSetting::get('global_chat_allowed_emojis', ['👍', '❤️', '🔥', '😂', '🎉', '😮', '😢', '👏']);

$durationMinutes = (int) AppSetting::get('global_chat_auto_ban_duration_minutes', 0);
Expand All @@ -36,7 +34,6 @@ public function edit()
'max_messages' => (int) AppSetting::get('global_chat_max_messages', 200),
'max_length' => (int) AppSetting::get('global_chat_max_length', 280),
'profanity_filter_enabled' => (bool) AppSetting::get('global_chat_profanity_filter_enabled', true),
'banned_words' => $bannedWordsText,
'allowed_emojis' => (array) $allowedEmojis,
'bot_username' => (string) AppSetting::get('global_chat_bot_username', 'hscstack'),
'auto_ban_enabled' => (bool) AppSetting::get('global_chat_auto_ban_enabled', true),
Expand Down Expand Up @@ -99,7 +96,6 @@ public function update(Request $request)
'max_messages' => ['required', 'integer', 'min:20', 'max:1000'],
'max_length' => ['required', 'integer', 'min:50', 'max:1000'],
'profanity_filter_enabled' => ['required', 'boolean'],
'banned_words' => ['nullable', 'string'],
'allowed_emojis' => ['nullable', 'array'],
'allowed_emojis.*' => ['required', 'string', 'max:32'],
'bot_username' => ['nullable', 'string', 'max:50', 'exists:users,username'],
Expand All @@ -116,7 +112,6 @@ public function update(Request $request)
AppSetting::set('global_chat_max_messages', $validated['max_messages'], 'integer');
AppSetting::set('global_chat_max_length', $validated['max_length'], 'integer');
AppSetting::set('global_chat_profanity_filter_enabled', $validated['profanity_filter_enabled'], 'boolean');
AppSetting::set('global_chat_banned_words', $validated['banned_words'] ?? '', 'string');
AppSetting::set('global_chat_auto_ban_enabled', $validated['auto_ban_enabled'], 'boolean');
AppSetting::set('global_chat_auto_ban_reports_threshold', $validated['auto_ban_threshold'], 'integer');
AppSetting::set('global_chat_auto_ban_duration_minutes', $validated['auto_ban_duration_minutes'], 'integer');
Expand Down
6 changes: 0 additions & 6 deletions app/Http/Controllers/Admin/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ public function clearReports(Request $request)

public function settings()
{
$bannedWords = AppSetting::get('global_chat_banned_words', '');
$bannedWordsText = is_array($bannedWords) ? implode(', ', $bannedWords) : (string) $bannedWords;

return Inertia::render('admin/forums/Settings', [
'settings' => [
'approval_mode' => (string) AppSetting::get('forum_approval_mode', 'auto'),
Expand All @@ -224,7 +221,6 @@ public function settings()
'disabled_reason' => (string) AppSetting::get('forum_disabled_reason', ''),
'auto_unpublish_threshold' => (int) AppSetting::get('forum_auto_unpublish_threshold', 3),
'profanity_filter_enabled' => (bool) AppSetting::get('global_chat_profanity_filter_enabled', true),
'banned_words' => $bannedWordsText,
],
'pendingReportsCount' => Report::where('status', 'pending')->whereIn('reportable_type', [ForumPost::class, ForumAnswer::class])->count(),
]);
Expand All @@ -239,7 +235,6 @@ public function updateSettings(Request $request)
'disabled_reason' => ['nullable', 'string', 'max:255'],
'auto_unpublish_threshold' => ['required', 'integer', 'min:0', 'max:50'],
'profanity_filter_enabled' => ['required', 'boolean'],
'banned_words' => ['nullable', 'string'],
]);

AppSetting::set('forum_approval_mode', $validated['approval_mode'], 'string');
Expand All @@ -248,7 +243,6 @@ public function updateSettings(Request $request)
AppSetting::set('forum_disabled_reason', $validated['disabled_reason'] ?? '', 'string');
AppSetting::set('forum_auto_unpublish_threshold', $validated['auto_unpublish_threshold'], 'integer');
AppSetting::set('global_chat_profanity_filter_enabled', $validated['profanity_filter_enabled'], 'boolean');
AppSetting::set('global_chat_banned_words', $validated['banned_words'] ?? '', 'string');

return back()->with('success', 'Forum settings updated successfully.');
}
Expand Down
177 changes: 177 additions & 0 deletions app/Http/Controllers/Admin/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\AppSetting;
use App\Models\ChatMessage;
use App\Models\Report;
use App\Models\User;
use App\Notifications\UserSuspensionNotification;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class ReportController extends Controller
{
/**
* Display a unified list of all community reports.
*/
public function index(Request $request): Response
{
$status = $request->query('status', 'pending');
$type = $request->query('type', 'all');

$query = Report::with([
'reporter:id,name,username,image_path',
'reportedUser:id,name,username,image_path,is_verified,banned_until',
'reviewer:id,name,username',
]);

if ($status !== 'all') {
$query->where('status', $status);
}

if ($type !== 'all') {
$modelMap = [
'chat' => 'App\Models\ChatMessage',
'forum_post' => 'App\Models\ForumPost',
'forum_answer' => 'App\Models\ForumAnswer',
'resource_comment' => 'App\Models\ResourceComment',
'blog_comment' => 'App\Models\BlogComment',
];

if (isset($modelMap[$type])) {
$query->where('reportable_type', $modelMap[$type]);
}
}

$reports = $query->latest('id')
->paginate(20)
->withQueryString();

$counts = [
'all' => Report::count(),
'pending' => Report::where('status', 'pending')->count(),
'resolved' => Report::where('status', 'resolved')->count(),
'dismissed' => Report::where('status', 'dismissed')->count(),
];

$bannedWords = AppSetting::get('global_chat_banned_words', '');
$bannedWordsText = is_array($bannedWords) ? implode(', ', $bannedWords) : (string) $bannedWords;

return Inertia::render('admin/Reports', [
'reports' => $reports,
'counts' => $counts,
'filters' => [
'status' => $status,
'type' => $type,
],
'safety_settings' => [
'banned_words' => $bannedWordsText,
'profanity_filter_enabled' => (bool) AppSetting::get('global_chat_profanity_filter_enabled', true),
],
]);
}

/**
* Update the moderation status of a report.
*/
public function updateStatus(Request $request, Report $report): RedirectResponse
{
$validated = $request->validate([
'status' => ['required', 'in:pending,resolved,dismissed'],
'action_taken' => ['nullable', 'string', 'max:100'],
]);

$report->update([
'status' => $validated['status'],
'action_taken' => $validated['action_taken'] ?? null,
'reviewed_by' => $request->user()->id,
'reviewed_at' => now(),
]);

return back()->with('success', 'Report status updated successfully.');
}

/**
* Delete a single report.
*/
public function destroy(Report $report): RedirectResponse
{
$report->delete();

return back()->with('success', 'Report deleted successfully.');
}

/**
* Batch clear or resolve reports.
*/
public function clear(Request $request): RedirectResponse
{
$status = $request->input('status');

if ($status && in_array($status, ['pending', 'resolved', 'dismissed'], true)) {
Report::where('status', $status)->delete();
$message = ucfirst($status).' reports cleared successfully.';
} else {
Report::truncate();
$message = 'All reports cleared successfully.';
}

return back()->with('success', $message);
}

/**
* Centralized endpoint to suspend/ban or unban a user.
* Only users with `manage reports` can access this action.
*/
public function updateUserBan(Request $request, User $user): RedirectResponse
{
if ($user->is_verified) {
return back()->with('error', 'Verified accounts cannot be suspended.');
}

$validated = $request->validate([
'banned_until' => ['nullable', 'date'],
]);

$bannedUntil = $validated['banned_until'] ?? null;

$user->update([
'banned_until' => $bannedUntil,
]);

$moderator = $request->user();

if ($user->isBanned()) {
$durationText = $user->banned_until->diffForHumans();
ChatMessage::sendBotMessage("Moderator @{$moderator->username} suspended @{$user->username} from community participation until {$user->banned_until->toDayDateTimeString()} ({$durationText}).");
$user->notify(new UserSuspensionNotification(true, $user->banned_until->toDayDateTimeString()." ({$durationText})"));
$message = "User @{$user->username} has been suspended until {$user->banned_until->toDateTimeString()}.";
} else {
ChatMessage::sendBotMessage("Moderator @{$moderator->username} removed suspension for @{$user->username}.");
$user->notify(new UserSuspensionNotification(false));
$message = "Suspension for @{$user->username} has been removed.";
}

return back()->with('success', $message);
}

/**
* Update platform-wide banned keywords and profanity filter settings.
*/
public function updateBannedWords(Request $request): RedirectResponse
{
$validated = $request->validate([
'banned_words' => ['nullable', 'string'],
'profanity_filter_enabled' => ['required', 'boolean'],
]);

AppSetting::set('global_chat_banned_words', $validated['banned_words'] ?? '', 'string');
AppSetting::set('global_chat_profanity_filter_enabled', $validated['profanity_filter_enabled'], 'boolean');

return back()->with('success', 'Platform banned keywords updated successfully.');
}
}
Loading
Loading