/** * Run the request filter. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Agent::isAdmin()) { return $next($request); } // All Agents have access in none restricted mode if (Setting::grab('agent_restrict') == 'no') { if (Agent::isAgent()) { return $next($request); } } // if this is a ticket show page if ($request->route()->getName() == Setting::grab('main_route') . '.show') { $ticket_id = $request->route(Setting::grab('main_route')); } // if this is a new comment on a ticket if ($request->route()->getName() == Setting::grab('main_route') . '-comment.store') { $ticket_id = $request->get('ticket_id'); } // Assigned Agent has access in the restricted mode enabled if (Agent::isAgent() && Agent::isAssignedAgent($ticket_id)) { return $next($request); } // Ticket Owner has access if (Agent::isTicketOwner($ticket_id)) { return $next($request); } return redirect()->action('\\Kordy\\Ticketit\\Controllers\\TicketsController@index')->with('warning', trans('ticketit::lang.you-are-not-permitted-to-access')); }
/** * Send email notifications from the action owner to other involved users * @param string $template * @param array $data * @param object $ticket * @param object $notification_owner */ public function sendNotification($template, $data, $ticket, $notification_owner, $subject, $type) { if (Setting::grab('queue_emails') == 'yes') { Mail::queue($template, $data, function ($m) use($ticket, $notification_owner, $subject, $type) { if ($type != 'agent') { if ($ticket->user->email != $notification_owner->email) { $m->to($ticket->user->email, $ticket->user->name); } if ($ticket->agent->email != $notification_owner->email) { $m->to($ticket->agent->email, $ticket->agent->name); } } else { $m->to($ticket->agent->email, $ticket->agent->name); } //$m->from($notification_owner->email, $notification_owner->name); $m->subject($subject); }); } else { Mail::send($template, $data, function ($m) use($ticket, $notification_owner, $subject, $type) { if ($type != 'agent') { if ($ticket->user->email != $notification_owner->email) { $m->to($ticket->user->email, $ticket->user->name); } if ($ticket->agent->email != $notification_owner->email) { $m->to($ticket->agent->email, $ticket->agent->name); } } else { $m->to($ticket->agent->email, $ticket->agent->name); } //$m->from($notification_owner->email, $notification_owner->name); $m->subject($subject); }); } }
/** * Seed the Plans table */ public function run() { $defaults = []; $defaults = $this->cleanupAndMerge($this->getDefaults(), $this->config); foreach ($defaults as $slug => $column) { $setting = Setting::bySlug($slug); if ($setting->count()) { $setting->first()->update(['default' => $column]); } else { Setting::create(['lang' => null, 'slug' => $slug, 'value' => $column, 'default' => $column]); } } }
public function setup(Request $request) { $master = $request->master; if ($master == 'another') { $another_file = $request->other_path; $views_content = strstr(substr(strstr($another_file, 'views/'), 6), '.blade.php', true); $master = str_replace('/', '.', $views_content); } $this->initialSettings($master); $admin_id = $request->admin_id; $admin = User::find($admin_id); $admin->ticketit_admin = true; $admin->save(); return redirect('/' . Setting::grab('main_route')); }
/** * Grab a setting from cached Settings table by slug. * Cache lifetime: 60 minutes * * @param $slug * @return mixed */ public static function grab($slug) { /** * Comment out prior to 0.2 launch. Will cause massive amount * of Database queries. Only for adding new settings while * in development and testing. */ //Cache::forget('settings'); $settings = Cache::remember('settings', 60, function () { return Table::all(); }); $setting = $settings->where('slug', $slug)->first(); if ($setting->lang) { return trans($setting->lang); } if (Setting::is_serialized($setting->value)) { $setting = unserialize($setting->value); } else { $setting = $setting->value; } return $setting; }
/** * @param $id * @return bool */ public function permToReopen($id) { $reopen_ticket_perm = Setting::grab('reopen_ticket_perm'); if ($this->agent->isAdmin() && $reopen_ticket_perm['admin'] == 'yes') { return 'yes'; } elseif ($this->agent->isAgent() && $reopen_ticket_perm['agent'] == 'yes') { return 'yes'; } elseif ($this->agent->isTicketOwner($id) && $reopen_ticket_perm['owner'] == 'yes') { return 'yes'; } return 'no'; }
/** * Bootstrap the application services. * * @return void */ public function boot() { $installer = new InstallController(); // if a migration is missing scape to the installation if (empty($installer->inactiveMigrations()) && DB::table('ticketit_settings')->count() != 0) { // Send the Agent User model to the view under $u view()->composer('*', function ($view) { if (auth()->check()) { $u = Agent::find(auth()->user()->id); $view->with('u', $u); } $setting = new Setting(); $view->with('setting', $setting); }); // Adding HTML5 color picker to form elements CollectiveForm::macro('custom', function ($type, $name, $value = "#000000", $options = []) { $field = $this->input($type, $name, $value, $options); return $field; }); // Passing to views the master view value from the setting file view()->composer('ticketit::*', function ($view) { $tools = new ToolsController(); $master = Setting::grab('master_template'); $email = Setting::grab('email.template'); $view->with(compact('master', 'email', 'tools')); }); // Send notification when new comment is added Comment::creating(function ($comment) { if (Setting::grab('comment_notification')) { $notification = new NotificationsController(); $notification->newComment($comment); } }); // Send notification when ticket status is modified Ticket::updating(function ($modified_ticket) { if (Setting::grab('status_notification')) { $original_ticket = Ticket::find($modified_ticket->id); if ($original_ticket->status_id != $modified_ticket->status_id || $original_ticket->completed_at != $modified_ticket->completed_at) { $notification = new NotificationsController(); $notification->ticketStatusUpdated($modified_ticket, $original_ticket); } } if (Setting::grab('assigned_notification')) { $original_ticket = Ticket::find($modified_ticket->id); if ($original_ticket->agent->id != $modified_ticket->agent->id) { $notification = new NotificationsController(); $notification->ticketAgentUpdated($modified_ticket, $original_ticket); } } return true; }); // Send notification when ticket status is modified Ticket::created(function ($ticket) { if (Setting::grab('assigned_notification')) { $notification = new NotificationsController(); $notification->newTicketNotifyAgent($ticket); } return true; }); $this->loadTranslationsFrom(__DIR__ . '/Translations', 'ticketit'); $this->loadViewsFrom(__DIR__ . '/Views', 'ticketit'); $this->publishes([__DIR__ . '/Views' => base_path('resources/views/vendor/ticketit')], 'views'); $this->publishes([__DIR__ . '/Translations' => base_path('resources/lang/vendor/ticketit')], 'lang'); $this->publishes([__DIR__ . '/Public' => public_path('vendor/ticketit')], 'public'); $this->publishes([__DIR__ . '/Migrations' => base_path('database/migrations')], 'db'); // Check public assets are present, publish them if not // $installer->publicAssets(); $main_route = Setting::grab('main_route'); $admin_route = Setting::grab('admin_route'); include __DIR__ . '/routes.php'; } elseif (Request::path() == 'tickets-install') { $this->loadTranslationsFrom(__DIR__ . '/Translations', 'ticketit'); $this->loadViewsFrom(__DIR__ . '/Views', 'ticketit'); $this->publishes([__DIR__ . '/Migrations' => base_path('database/migrations')], 'db'); Route::get('/tickets-install', ['middleware' => 'auth', 'uses' => 'Kordy\\Ticketit\\Controllers\\InstallController@index']); Route::post('/tickets-install', ['middleware' => 'auth', 'uses' => 'Kordy\\Ticketit\\Controllers\\InstallController@setup']); } }
public function create() { $users = Agent::paginate(Setting::grab('paginate_items')); return view('ticketit::admin.agent.create', compact('users')); }
/** * Check if user is admin * @return boolean */ public static function isAdmin() { if (auth()->check()) { if (auth()->user()->ticketit_admin) { return true; } elseif (!is_null(Setting::where('slug', 'admin_ids')->first()) && in_array(auth()->user()->id, Setting::grab('admin_ids'))) { return true; } } }