fix: 🚑️ Harmonize formatting and merge some try catch

This commit is contained in:
Johannes F 2023-02-14 18:33:43 +01:00 committed by IceToast
parent 371a37df7a
commit e78bd37da0
2 changed files with 66 additions and 62 deletions

View file

@ -66,7 +66,6 @@ class TicketsController extends Controller
} catch (Exception $e) } catch (Exception $e)
{ {
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
} }
TicketComment::where('ticket_id', $ticket->id)->delete(); TicketComment::where('ticket_id', $ticket->id)->delete();
@ -80,11 +79,8 @@ class TicketsController extends Controller
$this->validate($request, ['ticketcomment' => 'required']); $this->validate($request, ['ticketcomment' => 'required']);
try { try {
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
} catch (Exception $e){
}
catch (Exception $e){
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
} }
$ticket->status = 'Answered'; $ticket->status = 'Answered';
$ticket->update(); $ticket->update();
@ -176,13 +172,12 @@ class TicketsController extends Controller
public function blacklistAdd(Request $request) public function blacklistAdd(Request $request)
{ {
try { try {
$user = User::where('id', $request->user_id)->first(); $user = User::where('id', $request->user_id)->firstOrFail();
$check = TicketBlacklist::where('user_id', $user->id)->first();
} }
catch (Exception $e){ catch (Exception $e){
return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.')); return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.'));
} }
$check = TicketBlacklist::where('user_id', $user->id)->first();
if ($check) { if ($check) {
$check->reason = $request->reason; $check->reason = $request->reason;
$check->status = 'True'; $check->status = 'True';
@ -209,7 +204,12 @@ class TicketsController extends Controller
public function blacklistChange($id) public function blacklistChange($id)
{ {
try {
$blacklist = TicketBlacklist::where('id', $id)->first(); $blacklist = TicketBlacklist::where('id', $id)->first();
}
catch (Exception $e){
return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.'));
}
if ($blacklist->status == 'True') { if ($blacklist->status == 'True') {
$blacklist->status = 'False'; $blacklist->status = 'False';
} else { } else {

View file

@ -26,19 +26,6 @@ class TicketsController extends Controller
return view('ticket.index', compact('tickets', 'ticketcategories')); return view('ticket.index', compact('tickets', 'ticketcategories'));
} }
public function create()
{
//check in blacklist
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
if ($check && $check->status == 'True') {
return redirect()->route('ticket.index')->with('error', __("You can't make a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator"));
}
$ticketcategories = TicketCategory::all();
$servers = Auth::user()->servers;
return view('ticket.create', compact('ticketcategories', 'servers'));
}
public function store(Request $request) public function store(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
@ -59,9 +46,15 @@ class TicketsController extends Controller
); );
$ticket->save(); $ticket->save();
$user = Auth::user(); $user = Auth::user();
if(config('SETTINGS::TICKET:NOTIFY') == "all"){ $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get();} if (config('SETTINGS::TICKET:NOTIFY') == "all") {
if(config('SETTINGS::TICKET:NOTIFY') == "admin"){ $admin = User::where('role', 'admin')->get();} $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get();
if(config('SETTINGS::TICKET:NOTIFY') == "moderator"){ $admin = User::where('role', 'mod')->get();} }
if (config('SETTINGS::TICKET:NOTIFY') == "admin") {
$admin = User::where('role', 'admin')->get();
}
if (config('SETTINGS::TICKET:NOTIFY') == "moderator") {
$admin = User::where('role', 'mod')->get();
}
$user->notify(new CreateNotification($ticket)); $user->notify(new CreateNotification($ticket));
if (config('SETTINGS::TICKET:NOTIFY') != "none") { if (config('SETTINGS::TICKET:NOTIFY') != "none") {
Notification::send($admin, new AdminCreateNotification($ticket, $user)); Notification::send($admin, new AdminCreateNotification($ticket, $user));
@ -74,8 +67,7 @@ class TicketsController extends Controller
{ {
try { try {
$ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail();
} catch (Exception $e) } catch (Exception $e) {
{
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
} }
$ticketcomments = $ticket->ticketcomments; $ticketcomments = $ticket->ticketcomments;
@ -95,8 +87,7 @@ class TicketsController extends Controller
$this->validate($request, ['ticketcomment' => 'required']); $this->validate($request, ['ticketcomment' => 'required']);
try { try {
$ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail();
} catch (Exception $e) } catch (Exception $e) {
{
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
} }
$ticket->status = 'Client Reply'; $ticket->status = 'Client Reply';
@ -114,12 +105,25 @@ class TicketsController extends Controller
return redirect()->back()->with('success', __('Your comment has been submitted')); return redirect()->back()->with('success', __('Your comment has been submitted'));
} }
public function create()
{
//check in blacklist
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
if ($check && $check->status == 'True') {
return redirect()->route('ticket.index')->with('error', __("You can't make a ticket because you're on the blacklist for a reason: '" . $check->reason . "', please contact the administrator"));
}
$ticketcategories = TicketCategory::all();
$servers = Auth::user()->servers;
return view('ticket.create', compact('ticketcategories', 'servers'));
}
public function changeStatus($ticket_id) public function changeStatus($ticket_id)
{ {
try { try {
$ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail(); $ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail();
} catch (Exception $e) } catch (Exception $e) {
{
return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier'));
} }
if ($ticket->status == "Closed") { if ($ticket->status == "Closed") {