Add LOA feature, improve components
This commit is contained in:
28
app/Absence.php
Normal file
28
app/Absence.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Absence extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'requesterID',
|
||||
'start',
|
||||
'predicted_end',
|
||||
'available_assist',
|
||||
'reason',
|
||||
'status',
|
||||
'reviewer',
|
||||
'reviewed_date'
|
||||
];
|
||||
|
||||
public function requester(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo('App\User', 'requesterID', 'id');
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Appeal extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
138
app/Http/Controllers/AbsenceController.php
Normal file
138
app/Http/Controllers/AbsenceController.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Absence;
|
||||
use App\Http\Requests\StoreAbsenceRequest;
|
||||
use App\Http\Requests\UpdateAbsenceRequest;
|
||||
use App\User;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AbsenceController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Determines whether someone already has an active leave of absence request
|
||||
*
|
||||
* @param User $user The user to check
|
||||
* @return bool Their status
|
||||
*/
|
||||
private function hasActiveRequest(Authenticatable $user): bool {
|
||||
|
||||
$absences = Absence::where('requesterID', $user->id)->get();
|
||||
|
||||
foreach ($absences as $absence) {
|
||||
|
||||
// Or we could adjust the query (using a model scope) to only return valid absences;
|
||||
// If there are any, refuse to store more, but this approach also works
|
||||
// A model scope that only returns cancelled, declined and ended absences could also be implemented for future use
|
||||
if (in_array($absence->status, ['PENDING', 'APPROVED']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('dashboard.absences.index')
|
||||
->with('absences', Absence::all());
|
||||
// display for admin users
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('dashboard.absences.create')
|
||||
->with('activeRequest', $this->hasActiveRequest(Auth::user()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\StoreAbsenceRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(StoreAbsenceRequest $request)
|
||||
{
|
||||
$this->authorize('create', Absence::class);
|
||||
|
||||
if ($this->hasActiveRequest(Auth::user())) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('You already have an active request. Cancel it or let it expire first.'));
|
||||
}
|
||||
|
||||
Absence::create([
|
||||
'requesterID' => Auth::user()->id,
|
||||
'start' => $request->start_date,
|
||||
'predicted_end' => $request->predicted_end,
|
||||
'available_assist' => $request->invalidAbsenceAgreement == 'on',
|
||||
'reason' => $request->reason,
|
||||
'status' => 'PENDING',
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', 'Absence request submitted for approval. You will receive email confirmation shortly.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Absence $absence)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Absence $absence)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\UpdateAbsenceRequest $request
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateAbsenceRequest $request, Absence $absence)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Absence $absence)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Appeal;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
// temp logic
|
||||
/*
|
||||
* Appeal types:
|
||||
* - Discord ban appeal (Will prompt user to login with Discord, if account is not linked)
|
||||
* - Site ban appeal (Can be filled while logged out, requires a valid email address, won't prompt for Discord auth)
|
||||
* - Timeout appeal (Will prompt user to login with Discord, if account is not linked)
|
||||
*
|
||||
*/
|
||||
class AppealController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Appeal $appeal
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Appeal $appeal)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Appeal $appeal
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Appeal $appeal)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Appeal $appeal
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Appeal $appeal)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Appeal $appeal
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Appeal $appeal)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
36
app/Http/Requests/StoreAbsenceRequest.php
Normal file
36
app/Http/Requests/StoreAbsenceRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
class StoreAbsenceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::user()->hasPermissionTo('reviewer.requestAbsence');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'reason' => 'required|string',
|
||||
'start_date' => 'required|date',
|
||||
'predicted_end' => 'required|date|after:start_date',
|
||||
'available_assist' => 'required|string',
|
||||
'invalidAbsenceAgreement' => 'required|accepted'
|
||||
];
|
||||
}
|
||||
}
|
30
app/Http/Requests/UpdateAbsenceRequest.php
Normal file
30
app/Http/Requests/UpdateAbsenceRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateAbsenceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
82
app/Policies/AbsencePolicy.php
Normal file
82
app/Policies/AbsencePolicy.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Absence;
|
||||
use App\Response;
|
||||
use App\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class AbsencePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function viewAny(User $user)
|
||||
{
|
||||
if ($user->hasPermissionTo('admin.viewAllAbsences'))
|
||||
{
|
||||
return \Illuminate\Auth\Access\Response::allow();
|
||||
}
|
||||
|
||||
return \Illuminate\Auth\Access\Response::deny('Forbidden');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function view(User $user, Absence $absence)
|
||||
{
|
||||
if ($user->hasPermissionTo('reviewer.viewAbsence') && $user->id == $absence->requesterID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
return $user->hasPermissionTo('reviewer.requestAbsence');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function update(User $user, Absence $absence)
|
||||
{
|
||||
return $user->hasPermissionTo('admin.manageAbsences');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Absence $absence
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function delete(User $user, Absence $absence)
|
||||
{
|
||||
return $user->hasPermissionTo('admin.manageAbsences') || $user->hasPermissionTo('reviewer.withdrawAbsence') && $user->id == $absence->requesterID;
|
||||
}
|
||||
|
||||
}
|
@@ -92,11 +92,13 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->hasMany('App\TeamFile', 'uploaded_by');
|
||||
}
|
||||
|
||||
public function keys()
|
||||
public function absences()
|
||||
{
|
||||
return $this->hasMany('App\ApiKey', 'owner_user_id');
|
||||
return $this->hasMany('App\Absence', 'requesterID');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// UTILITY LOGIC
|
||||
|
||||
public function isBanned()
|
||||
@@ -129,6 +131,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function routeNotificationForSlack($notification)
|
||||
{
|
||||
return config('slack.webhook.integrationURL');
|
||||
|
@@ -25,20 +25,26 @@ use Illuminate\View\Component;
|
||||
|
||||
class Alert extends Component
|
||||
{
|
||||
public $alertType;
|
||||
|
||||
public $extraStyling;
|
||||
public
|
||||
$alertType,
|
||||
$extraStyling,
|
||||
$title,
|
||||
$icon;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @param $alertType
|
||||
* @param string $extraStyling
|
||||
* @param string $alertType The color the alert should have.
|
||||
* @param string $title The alert's title
|
||||
* @param string $icon The alert's icon, placed before the title
|
||||
* @param string $extraStyling Any extra CSS classes to add
|
||||
*/
|
||||
public function __construct($alertType, $extraStyling = '')
|
||||
public function __construct(string $alertType, string $title = '', string $icon = '', string $extraStyling = '')
|
||||
{
|
||||
$this->alertType = $alertType;
|
||||
$this->extraStyling = $extraStyling;
|
||||
$this->icon = $icon;
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
|
40
app/View/Components/Button.php
Normal file
40
app/View/Components/Button.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Button extends Component
|
||||
{
|
||||
public string
|
||||
$type,
|
||||
$icon,
|
||||
$link,
|
||||
$target,
|
||||
$size,
|
||||
$color,
|
||||
$disabled,
|
||||
$id;
|
||||
|
||||
public function __construct($id, $color, $type = 'button', $disabled = false, $size = '', $target = '', $link = '', $icon = '')
|
||||
{
|
||||
$this->link = $link;
|
||||
$this->disabled = $disabled;
|
||||
$this->type = $type;
|
||||
$this->target = $target;
|
||||
$this->size = $size;
|
||||
$this->color = $color;
|
||||
$this->id = $id;
|
||||
$this->icon = $icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|\Closure|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.button');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user