Update Admin routes

This commit is contained in:
Daniel Supernault 2024-10-10 02:00:55 -06:00
parent 45f19ded61
commit 3004c438f1
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
2 changed files with 53 additions and 3 deletions

View file

@ -13,6 +13,7 @@ use App\Http\Controllers\Admin\AdminReportController;
use App\Http\Controllers\Admin\AdminSettingsController; use App\Http\Controllers\Admin\AdminSettingsController;
use App\Http\Controllers\Admin\AdminUserController; use App\Http\Controllers\Admin\AdminUserController;
use App\Instance; use App\Instance;
use App\Mail\AdminMessageResponse;
use App\Models\CustomEmoji; use App\Models\CustomEmoji;
use App\Newsroom; use App\Newsroom;
use App\OauthClient; use App\OauthClient;
@ -29,6 +30,7 @@ use Cache;
use DB; use DB;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Mail;
use Storage; use Storage;
class AdminController extends Controller class AdminController extends Controller
@ -221,18 +223,62 @@ class AdminController extends Controller
public function messagesHome(Request $request) public function messagesHome(Request $request)
{ {
$messages = Contact::orderByDesc('id')->paginate(10); $this->validate($request, [
'sort' => 'sometimes|string|in:all,open,closed',
]);
$sort = $request->input('sort', 'open');
return view('admin.messages.home', compact('messages')); $messages = Contact::when($sort, function ($query, $sort) {
if ($sort === 'open') {
$query->whereNull('read_at');
}
if ($sort === 'closed') {
$query->whereNotNull('read_at');
}
})
->orderByDesc('id')
->paginate(10)
->withQueryString();
return view('admin.messages.home', compact('messages', 'sort'));
} }
public function messagesShow(Request $request, $id) public function messagesShow(Request $request, $id)
{ {
$message = Contact::findOrFail($id); $message = Contact::findOrFail($id);
$user = User::whereNull('status')->findOrFail($message->user_id);
return view('admin.messages.show', compact('message')); return view('admin.messages.show', compact('message'));
} }
public function messagesReply(Request $request, $id)
{
$this->validate($request, [
'message' => 'required|string|min:1|max:500',
]);
$message = Contact::whereNull('responded_at')->findOrFail($id);
$message->response = $request->input('message');
$message->read_at = now();
$message->responded_at = now();
$message->save();
Mail::to($message->user->email)->send(new AdminMessageResponse($message));
return redirect('/i/admin/messages/home')->with('status', 'Sent response to '.$message->user->username);
}
public function messagesReplyPreview(Request $request, $id)
{
$this->validate($request, [
'message' => 'required|string|min:1|max:500',
]);
$message = Contact::whereNull('read_at')->findOrFail($id);
return new AdminMessageResponse($message);
}
public function messagesMarkRead(Request $request) public function messagesMarkRead(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
@ -245,7 +291,9 @@ class AdminController extends Controller
} }
$message->read_at = now(); $message->read_at = now();
$message->save(); $message->save();
$request->session()->flash('status', 'Marked response from '.$message->user->username.' as read!');
return ['status' => 200];
} }
public function newsroomHome(Request $request) public function newsroomHome(Request $request)
@ -355,7 +403,7 @@ class AdminController extends Controller
if (Newsroom::whereSlug($slug)->exists()) { if (Newsroom::whereSlug($slug)->exists()) {
$slug = $slug.'-'.str_random(4); $slug = $slug.'-'.str_random(4);
} }
$news = new Newsroom(); $news = new Newsroom;
$fields = [ $fields = [
'title' => 'string', 'title' => 'string',
'summary' => 'string', 'summary' => 'string',

View file

@ -77,6 +77,8 @@ Route::domain(config('pixelfed.domain.admin'))->prefix('i/admin')->group(functio
Route::get('messages/home', 'AdminController@messagesHome')->name('admin.messages'); Route::get('messages/home', 'AdminController@messagesHome')->name('admin.messages');
Route::get('messages/show/{id}', 'AdminController@messagesShow'); Route::get('messages/show/{id}', 'AdminController@messagesShow');
Route::post('messages/mark-read', 'AdminController@messagesMarkRead'); Route::post('messages/mark-read', 'AdminController@messagesMarkRead');
Route::post('messages/show/{id}', 'AdminController@messagesReply');
Route::post('messages/preview/{id}', 'AdminController@messagesReplyPreview');
Route::redirect('site-news', '/i/admin/newsroom'); Route::redirect('site-news', '/i/admin/newsroom');
Route::get('newsroom', 'AdminController@newsroomHome')->name('admin.newsroom.home'); Route::get('newsroom', 'AdminController@newsroomHome')->name('admin.newsroom.home');
Route::get('newsroom/create', 'AdminController@newsroomCreate')->name('admin.newsroom.create'); Route::get('newsroom/create', 'AdminController@newsroomCreate')->name('admin.newsroom.create');