refactor: moved user eligibility check
Additionally, deprecated the ApplicationEligibility middleware
This commit is contained in:
parent
43e6859366
commit
b96a20a0a9
@ -22,6 +22,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Application;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Closure;
|
||||
use Exception;
|
||||
@ -35,6 +36,8 @@ class ApplicationEligibility
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @deprecated Deprecated in 0.9.0
|
||||
* @see User::isEligible()
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @return mixed
|
||||
|
26
app/User.php
26
app/User.php
@ -29,7 +29,10 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Mpociot\Teamwork\Traits\UserHasTeams;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
@ -116,7 +119,23 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return $this->hasMany('App\Absence', 'requesterID');
|
||||
}
|
||||
|
||||
// UTILITY LOGIC
|
||||
|
||||
public function isEligible(): bool {
|
||||
$eligible = false;
|
||||
$lastApplication = Application::where('applicantUserID', $this->id)->latest()->first();
|
||||
|
||||
if (is_null($lastApplication)) {
|
||||
$eligible = true;
|
||||
}
|
||||
|
||||
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
||||
|
||||
$eligible = true;
|
||||
}
|
||||
|
||||
return $eligible;
|
||||
}
|
||||
|
||||
|
||||
public function isVerified(): bool {
|
||||
return !is_null($this->email_verified_at);
|
||||
@ -173,9 +192,4 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
return !is_null($this->discord_token) && !is_null($this->discord_refresh_token);
|
||||
}
|
||||
|
||||
|
||||
public function routeNotificationForSlack($notification)
|
||||
{
|
||||
return config('slack.webhook.integrationURL');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user