Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 59 |
| CheckLeavePermission | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
1806 | |
0.00% |
0 / 59 |
| handle | |
0.00% |
0 / 1 |
1806 | |
0.00% |
0 / 59 |
|||
| <?php | |
| namespace App\Http\Middleware; | |
| use Closure; | |
| use Illuminate\Support\Facades\Auth; | |
| use Route; | |
| use Illuminate\Support\Facades\Schema; | |
| use App\Models\Admin\Setting; | |
| class CheckLeavePermission | |
| { | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * @param string|null $guard | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next, $guard = null) | |
| { | |
| /*if (Auth::guard($guard)->check()) {*/ | |
| $currentroutename = Route::currentRouteName(); | |
| $route_basic_name = array(); | |
| $route_basic_name = explode(".",$currentroutename); | |
| $comp_off = 'disable'; | |
| $comp_off_approval = null; | |
| if (Schema::hasTable('settings')) { | |
| $setting = Setting::where('name','comp_off')->first(); | |
| if(!empty($setting)){ | |
| $comp_off = $setting->value; | |
| $approval = Setting::where('name','comp_off_approval')->first(); | |
| if(!empty($approval)){ | |
| $comp_off_approval = $approval->value; | |
| } | |
| } | |
| } | |
| switch ($route_basic_name[0]) { | |
| case "apply-leave": | |
| if(auth()->user()->can('Request Leave For Self')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "view-leave-balance": | |
| if(auth()->user()->can('View Self Leave Balance')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "leave-report": | |
| if(auth()->user()->can('View All leave requests') || auth()->user()->can('View All leave requests of assigned employees') || auth()->user()->can('View All leave requests of team')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "admin-apply-leave": | |
| if(auth()->user()->can('Can mark leave for all employees') || auth()->user()->can('Can mark leave for reporting employees')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "manage-leave-request": | |
| if(auth()->user()->can('Edit All leave requests') || auth()->user()->can('Edit All leave requests of assigned employees') || auth()->user()->can('Edit All leave requests of team')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "admin-leave-report": | |
| if(auth()->user()->can('View All Leave Report') || auth()->user()->can('View Team Leave Report')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "leave-balance-report": | |
| if(auth()->user()->can('View All Leave Balance') || auth()->user()->can('View Reporting Employees Leave Balance')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "leave-balance-report": | |
| if(auth()->user()->can('View All Leave Balance') || auth()->user()->can('View Reporting Employees Leave Balance')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "comp-off-leave-report": | |
| if((auth()->user()->can('View All leave requests') || auth()->user()->can('View All leave requests of assigned employees') || auth()->user()->can('View All leave requests of team')) && | |
| $comp_off == 'enable' && ($comp_off_approval == 'manual' || $comp_off_approval == 'semi_automatic')) | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| break; | |
| case "apply-comp-off-leave": | |
| if($currentroutename == "apply-comp-off-leave.index"){ | |
| if(auth()->user()->can('Request Leave For Self') && $comp_off == 'enable') | |
| return $next($request); | |
| else | |
| return redirect('/home'); | |
| } | |
| else if(auth()->user()->can('Request Leave For Self') && $comp_off == 'enable' && $comp_off_approval == 'manual'){ | |
| return $next($request); | |
| }else{ | |
| return redirect('/home'); | |
| } | |
| break; | |
| default: | |
| return redirect('/home'); | |
| } | |
| } | |
| } |