Ticket Blacklist
This commit is contained in:
parent
7bb3caa494
commit
9b3fce2808
|
@ -7,6 +7,7 @@ use App\Models\Ticket;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\TicketCategory;
|
use App\Models\TicketCategory;
|
||||||
use App\Models\TicketComment;
|
use App\Models\TicketComment;
|
||||||
|
use App\Models\TicketBlacklist;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
@ -44,12 +45,13 @@ class TicketsController extends Controller
|
||||||
return redirect()->back()->with('success', __('A ticket has been deleted, ID: #') . $ticket_id);
|
return redirect()->back()->with('success', __('A ticket has been deleted, ID: #') . $ticket_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reply(Request $request) {
|
public function reply(Request $request) {
|
||||||
$this->validate($request, array("ticketcomment" => "required"));
|
$this->validate($request, array("ticketcomment" => "required"));
|
||||||
$ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail();
|
$ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail();
|
||||||
$ticket->status = "Answered";
|
$ticket->status = "Answered";
|
||||||
$ticket->update();
|
$ticket->update();
|
||||||
$ticketcomment = TicketComment::create(array(
|
TicketComment::create(array(
|
||||||
"ticket_id" => $request->input("ticket_id"),
|
"ticket_id" => $request->input("ticket_id"),
|
||||||
"user_id" => Auth::user()->id,
|
"user_id" => Auth::user()->id,
|
||||||
"ticketcomment" => $request->input("ticketcomment"),
|
"ticketcomment" => $request->input("ticketcomment"),
|
||||||
|
@ -59,7 +61,7 @@ class TicketsController extends Controller
|
||||||
$user->notify(new ReplyNotification($ticket, $user, $newmessage));
|
$user->notify(new ReplyNotification($ticket, $user, $newmessage));
|
||||||
return redirect()->back()->with('success', __('Your comment has been submitted'));
|
return redirect()->back()->with('success', __('Your comment has been submitted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataTable()
|
public function dataTable()
|
||||||
{
|
{
|
||||||
$query = Ticket::query();
|
$query = Ticket::query();
|
||||||
|
@ -113,4 +115,88 @@ class TicketsController extends Controller
|
||||||
->rawColumns(['category', 'title', 'user_id', 'status', 'updated_at', 'actions'])
|
->rawColumns(['category', 'title', 'user_id', 'status', 'updated_at', 'actions'])
|
||||||
->make(true);
|
->make(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function blacklist() {
|
||||||
|
$users = User::get();
|
||||||
|
$ticketcategories = TicketCategory::all();
|
||||||
|
return view("moderator.ticket.blacklist", compact("users", "ticketcategories"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blacklistAdd(Request $request) {
|
||||||
|
$user = User::where('id', $request->user_id)->first();
|
||||||
|
$check = TicketBlacklist::where('user_id', $user->id)->first();
|
||||||
|
if($check){
|
||||||
|
return redirect()->back()->with('error', __('Target User already in blacklist'));
|
||||||
|
}
|
||||||
|
TicketBlacklist::create(array(
|
||||||
|
"user_id" => $user->id,
|
||||||
|
"status" => "True",
|
||||||
|
"reason" => $request->reason,
|
||||||
|
));
|
||||||
|
return redirect()->back()->with('success', __('Successfully add User to blacklist, User name: ' . $user->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blacklistDelete($id) {
|
||||||
|
$blacklist = TicketBlacklist::where('id', $id)->first();
|
||||||
|
$blacklist->delete();
|
||||||
|
return redirect()->back()->with('success', __('Successfully remove User from blacklist, User name: ' . $blacklist->user->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blacklistChange($id) {
|
||||||
|
$blacklist = TicketBlacklist::where('id', $id)->first();
|
||||||
|
if($blacklist->status == "True")
|
||||||
|
{
|
||||||
|
$blacklist->status = "False";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$blacklist->status = "True";
|
||||||
|
}
|
||||||
|
$blacklist->update();
|
||||||
|
return redirect()->back()->with('success', __('Successfully change status blacklist from, User name: ' . $blacklist->user->name));
|
||||||
|
|
||||||
|
}
|
||||||
|
public function dataTableBlacklist()
|
||||||
|
{
|
||||||
|
$query = TicketBlacklist::with(['user']);
|
||||||
|
|
||||||
|
return datatables($query)
|
||||||
|
->editColumn('user', function (TicketBlacklist $blacklist) {
|
||||||
|
return '<a href="' . route('admin.users.show', $blacklist->user->id) . '">' . $blacklist->user->name . '</a>';
|
||||||
|
})
|
||||||
|
->editColumn('status', function (TicketBlacklist $blacklist) {
|
||||||
|
switch ($blacklist->status) {
|
||||||
|
case 'True':
|
||||||
|
$badgeColor = 'badge-success';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$badgeColor = 'badge-danger';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<span class="badge ' . $badgeColor . '">' . $blacklist->status . '</span>';
|
||||||
|
})
|
||||||
|
->editColumn('reason', function (TicketBlacklist $blacklist) {
|
||||||
|
return $blacklist->reason;
|
||||||
|
})
|
||||||
|
->addColumn('actions', function (TicketBlacklist $blacklist) {
|
||||||
|
return '
|
||||||
|
<form class="d-inline" method="post" action="' . route('moderator.ticket.blacklist.change', ['id' => $blacklist->id ]) . '">
|
||||||
|
' . csrf_field() . '
|
||||||
|
' . method_field("POST") . '
|
||||||
|
<button data-content="'.__("Change Status").'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-sync-alt"></i></button>
|
||||||
|
</form>
|
||||||
|
<form class="d-inline" method="post" action="' . route('moderator.ticket.blacklist.delete', ['id' => $blacklist->id ]) . '">
|
||||||
|
' . csrf_field() . '
|
||||||
|
' . method_field("POST") . '
|
||||||
|
<button data-content="'.__("Delete").'" data-toggle="popover" data-trigger="hover" data-placement="top" class="btn btn-sm text-white btn-danger mr-1"><i class="fas fa-trash"></i></button>
|
||||||
|
</form>
|
||||||
|
';
|
||||||
|
})
|
||||||
|
->editColumn('created_at', function (TicketBlacklist $blacklist) {
|
||||||
|
return $blacklist->created_at ? $blacklist->created_at->diffForHumans() : '';
|
||||||
|
})
|
||||||
|
->rawColumns(['user', 'status', 'reason', 'created_at', 'actions'])
|
||||||
|
->make(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use App\Models\Ticket;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\TicketComment;
|
use App\Models\TicketComment;
|
||||||
use App\Models\TicketCategory;
|
use App\Models\TicketCategory;
|
||||||
|
use App\Models\TicketBlacklist;
|
||||||
use App\Notifications\Ticket\User\CreateNotification;
|
use App\Notifications\Ticket\User\CreateNotification;
|
||||||
use App\Notifications\Ticket\Admin\AdminCreateNotification;
|
use App\Notifications\Ticket\Admin\AdminCreateNotification;
|
||||||
use App\Notifications\Ticket\Admin\AdminReplyNotification;
|
use App\Notifications\Ticket\Admin\AdminReplyNotification;
|
||||||
|
@ -28,6 +29,11 @@ class TicketsController extends Controller
|
||||||
return view("ticket.index", compact("tickets", "ticketcategories"));
|
return view("ticket.index", compact("tickets", "ticketcategories"));
|
||||||
}
|
}
|
||||||
public function create() {
|
public function create() {
|
||||||
|
#check in blacklist
|
||||||
|
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
|
||||||
|
if($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();
|
$ticketcategories = TicketCategory::all();
|
||||||
$servers = Auth::user()->servers;
|
$servers = Auth::user()->servers;
|
||||||
return view("ticket.create", compact("ticketcategories", "servers"));
|
return view("ticket.create", compact("ticketcategories", "servers"));
|
||||||
|
@ -65,6 +71,11 @@ class TicketsController extends Controller
|
||||||
return view("ticket.show", compact("ticket", "ticketcategory", "ticketcomments", "server"));
|
return view("ticket.show", compact("ticket", "ticketcategory", "ticketcomments", "server"));
|
||||||
}
|
}
|
||||||
public function reply(Request $request) {
|
public function reply(Request $request) {
|
||||||
|
#check in blacklist
|
||||||
|
$check = TicketBlacklist::where('user_id', Auth::user()->id)->first();
|
||||||
|
if($check->status == "True"){
|
||||||
|
return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '" . $check->reason . "', please contact the administrator"));
|
||||||
|
}
|
||||||
$this->validate($request, array("ticketcomment" => "required"));
|
$this->validate($request, array("ticketcomment" => "required"));
|
||||||
$ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail();
|
$ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail();
|
||||||
$ticket->status = "Client Reply";
|
$ticket->status = "Client Reply";
|
||||||
|
|
17
app/Models/TicketBlacklist.php
Normal file
17
app/Models/TicketBlacklist.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class TicketBlacklist extends Model {
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id', 'status', 'reason'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateTicketBlacklistTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('ticket_blacklists', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->unsignedBigInteger('user_id')->unsigned();
|
||||||
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');;
|
||||||
|
$table->string('status');
|
||||||
|
$table->string('reason');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('ticket_blacklists');
|
||||||
|
}
|
||||||
|
}
|
|
@ -238,11 +238,17 @@
|
||||||
<li class="nav-header">{{ __('Moderation') }}</li>
|
<li class="nav-header">{{ __('Moderation') }}</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a href="{{ route('moderator.ticket.index') }}" class="nav-link @if (Request::routeIs('moderator.ticket.*')) active @endif">
|
<a href="{{ route('moderator.ticket.index') }}" class="nav-link @if (Request::routeIs('moderator.ticket.index')) active @endif">
|
||||||
<i class="nav-icon fas fa-ticket-alt"></i>
|
<i class="nav-icon fas fa-ticket-alt"></i>
|
||||||
<p>{{ __('Ticket List') }}</p>
|
<p>{{ __('Ticket List') }}</p>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="{{ route('moderator.ticket.blacklist') }}" class="nav-link @if (Request::routeIs('moderator.ticket.blacklist')) active @endif">
|
||||||
|
<i class="nav-icon fas fa-user"></i>
|
||||||
|
<p>{{ __('Black List') }}</p>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (Auth::user()->role == 'admin')
|
@if (Auth::user()->role == 'admin')
|
||||||
|
|
122
resources/views/moderator/ticket/blacklist.blade.php
Normal file
122
resources/views/moderator/ticket/blacklist.blade.php
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
@extends('layouts.main')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<!-- CONTENT HEADER -->
|
||||||
|
<section class="content-header">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row mb-2">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<h1>{{ __('Ticket Blacklist') }}</h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<ol class="breadcrumb float-sm-right">
|
||||||
|
<li class="breadcrumb-item"><a href="{{ route('home') }}">{{ __('Dashboard') }}</a></li>
|
||||||
|
<li class="breadcrumb-item"><a class="text-muted"
|
||||||
|
href="{{ route('moderator.ticket.blacklist') }}">{{ __('Ticket Blacklist') }}</a>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<!-- END CONTENT HEADER -->
|
||||||
|
|
||||||
|
<!-- MAIN CONTENT -->
|
||||||
|
<section class="content">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<h5 class="card-title"><i class="fas fas fa-users mr-2"></i>{{__('Blacklist List')}}</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body table-responsive">
|
||||||
|
|
||||||
|
<table id="datatable" class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{{__('User')}}</th>
|
||||||
|
<th>{{__('Status')}}</th>
|
||||||
|
<th>{{__('Reason')}}</th>
|
||||||
|
<th>{{__('Created At')}}</th>
|
||||||
|
<th>{{__('Actions')}}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="card-title">{{__('Add To Blacklist')}}
|
||||||
|
<i data-toggle="popover"
|
||||||
|
data-trigger="hover"
|
||||||
|
data-content="{{__('please make the best of it')}}"
|
||||||
|
class="fas fa-info-circle"></i></h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form action="{{route('moderator.ticket.blacklist.add')}}" method="POST" class="ticket-form">
|
||||||
|
@csrf
|
||||||
|
<div class="custom-control mb-3 p-0">
|
||||||
|
<label for="user_id">{{ __('User') }}:
|
||||||
|
<i data-toggle="popover" data-trigger="hover"
|
||||||
|
data-content="{{ __('Please note, the blacklist will make the user unable to make a ticket/reply again') }}" class="fas fa-info-circle"></i>
|
||||||
|
</label>
|
||||||
|
<select id="user_id" style="width:100%" class="custom-select" name="user_id" required
|
||||||
|
autocomplete="off" @error('user_id') is-invalid @enderror>
|
||||||
|
@foreach ($users as $user)
|
||||||
|
<option value="{{$user->id}}" >{{ $user->name }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group ">
|
||||||
|
<label for="reason" class="control-label">Reason</label>
|
||||||
|
<input id="reason" type="text" class="form-control" name="reason" placeholder="Input Some Reason">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary ticket-once">
|
||||||
|
{{__('Submit')}}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<!-- END CONTENT -->
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
$('#datatable').DataTable({
|
||||||
|
language: {
|
||||||
|
url: '//cdn.datatables.net/plug-ins/1.11.3/i18n/{{config("app.datatable_locale")}}.json'
|
||||||
|
},
|
||||||
|
processing: true,
|
||||||
|
serverSide: true,
|
||||||
|
stateSave: true,
|
||||||
|
ajax: "{{route('moderator.ticket.blacklist.datatable')}}",
|
||||||
|
columns: [
|
||||||
|
{data: 'user' , name : 'user.name'},
|
||||||
|
{data: 'status'},
|
||||||
|
{data: 'reason'},
|
||||||
|
{data: 'created_at', sortable: false},
|
||||||
|
{data: 'actions', sortable: false},
|
||||||
|
],
|
||||||
|
fnDrawCallback: function( oSettings ) {
|
||||||
|
$('[data-toggle="popover"]').popover();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
$('[data-toggle="popover"]').popover();
|
||||||
|
$('.custom-select').select2();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endsection
|
||||||
|
|
|
@ -186,6 +186,12 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
|
||||||
Route::post('ticket/reply', [ModTicketsController::class, 'reply'])->name('ticket.reply');
|
Route::post('ticket/reply', [ModTicketsController::class, 'reply'])->name('ticket.reply');
|
||||||
Route::post('ticket/close/{ticket_id}', [ModTicketsController::class, 'close'])->name('ticket.close');
|
Route::post('ticket/close/{ticket_id}', [ModTicketsController::class, 'close'])->name('ticket.close');
|
||||||
Route::post('ticket/delete/{ticket_id}', [ModTicketsController::class, 'delete'])->name('ticket.delete');
|
Route::post('ticket/delete/{ticket_id}', [ModTicketsController::class, 'delete'])->name('ticket.delete');
|
||||||
|
#ticket moderation blacklist
|
||||||
|
Route::get('ticket/blacklist', [ModTicketsController::class, 'blacklist'])->name('ticket.blacklist');
|
||||||
|
Route::post('ticket/blacklist', [ModTicketsController::class, 'blacklistAdd'])->name('ticket.blacklist.add');
|
||||||
|
Route::post('ticket/blacklist/delete/{id}', [ModTicketsController::class, 'blacklistDelete'])->name('ticket.blacklist.delete');
|
||||||
|
Route::post('ticket/blacklist/change/{id}', [ModTicketsController::class, 'blacklistChange'])->name('ticket.blacklist.change');
|
||||||
|
Route::get('ticket/blacklist/datatable', [ModTicketsController::class, 'dataTableBlacklist'])->name('ticket.blacklist.datatable');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/home', [HomeController::class, 'index'])->name('home');
|
Route::get('/home', [HomeController::class, 'index'])->name('home');
|
||||||
|
|
Loading…
Reference in a new issue