Skip to content

Commit

Permalink
Merge pull request #183 from bcgov/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
kmarshgov authored Jan 31, 2025
2 parents 7d29fc1 + 03fb9bb commit 873d25c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function index()
$institution = $user->institution;
// $fedCap = FedCap::active()->first();

$cap = Cap::where('fed_cap_guid', Cache::get('global_fed_caps')['default'])->active()
$cap = Cap::where('fed_cap_guid', Cache::get('global_fed_caps_' . $user->id)['default'])->active()
// $cap = Cap::where('fed_cap_guid', $fedCap->guid)->active()
->where('program_guid', null)
->where('institution_guid', $institution->guid)
Expand Down Expand Up @@ -112,7 +112,7 @@ public function store(AttestationStoreRequest $request): RedirectResponse|\Illum
$error = null;
//1. check for duplicate attestations
$check1 = Attestation::where([
'fed_cap_guid' => Cache::get('global_fed_caps')['default'],
'fed_cap_guid' => Cache::get('global_fed_caps_' . Auth::id())['default'],
'first_name' => $request->first_name, 'last_name' => $request->last_name, 'id_number' => $request->id_number,
'dob' => $request->dob, 'institution_guid' => $request->institution_guid,
'program_guid' => $request->program_guid, 'cap_guid' => $request->cap_guid, 'email' => $request->email,
Expand Down Expand Up @@ -148,7 +148,7 @@ public function update(AttestationEditRequest $request): RedirectResponse|\Illum

//2. dont allow duplicate
$check2 = Attestation::where([
'fed_cap_guid' => Cache::get('global_fed_caps')['default'],
'fed_cap_guid' => Cache::get('global_fed_caps_' . Auth::id())['default'],
'first_name' => $request->first_name, 'last_name' => $request->last_name, 'id_number' => $request->id_number,
'dob' => $request->dob, 'institution_guid' => $request->institution_guid,
'program_guid' => $request->program_guid, 'cap_guid' => $request->cap_guid, 'email' => $request->email,
Expand Down Expand Up @@ -204,11 +204,11 @@ public function download(Request $request, Attestation $attestation)

public function exportCsv()
{
$user = User::find(Auth::user()->id);
$user = User::find(Auth::id());
$institution = $user->institution;

$data = Attestation::where('institution_guid', $institution->guid)
->where('fed_cap_guid', Cache::get('global_fed_caps')['default'])
->where('fed_cap_guid', Cache::get('global_fed_caps_' . Auth::id())['default'])
->whereNot('status', 'Cancelled Draft')
->orderByDesc('created_at')->get();

Expand Down Expand Up @@ -291,7 +291,7 @@ private function paginateAtte($institution)
{
// $attestations = Attestation::where('institution_guid', $institution->guid)->with('program');
$attestations = Attestation::where('institution_guid', $institution->guid)
->where('fed_cap_guid', Cache::get('global_fed_caps')['default'])
->where('fed_cap_guid', Cache::get('global_fed_caps_' . Auth::id())['default'])
->whereNot('status', 'Cancelled Draft');

if (request()->filter_term !== null && request()->filter_type !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function rules()
protected function prepareForValidation()
{
$oldAtte = Attestation::where('guid', $this->old_guid)->first();
\Log::info('We got a old_guid: ' . $this->old_guid);
if(!is_null($oldAtte)){

// Get the inst active cap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
use App\Models\AttestationPdf;
use App\Models\Cap;
use App\Models\Country;
use App\Models\FedCap;
use App\Models\Institution;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Inertia\Inertia;
use Auth;

class AttestationController extends Controller
{
Expand Down Expand Up @@ -215,7 +215,7 @@ public function download(Request $request, Attestation $attestation)

private function paginateAtte()
{
$attestations = Attestation::where('fed_cap_guid', Cache::get('global_fed_caps')['default']);
$attestations = Attestation::where('fed_cap_guid', Cache::get('global_fed_caps_' . Auth::id())['default']);

if (request()->filter_name !== null) {
$attestations = $attestations->where('first_name', 'ILIKE', '%'.request()->filter_name.'%')
Expand Down
5 changes: 3 additions & 2 deletions Modules/Ministry/App/Http/Controllers/FedCapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\FedCap;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
Expand Down Expand Up @@ -76,8 +77,8 @@ public function setDefault(Request $request)
{
$fedCap = FedCap::where('guid', $request->input('fed_cap_guid'))->first();

Cache::forget('global_fed_caps');
Cache::remember('global_fed_caps', now()->addHours(10), function () use ($fedCap) {
Cache::forget('global_fed_caps_' . Auth::id());
Cache::remember('global_fed_caps_' . Auth::id(), now()->addHours(10), function () use ($fedCap) {
$fedCaps = FedCap::select('id', 'guid', 'start_date', 'end_date', 'status')
->without(['caps'])
->active()->orderBy('id')->get();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function cancelledUsers(AjaxRequest $request)
*/
public function login(Request $request)
{
Cache::forget('global_fed_caps');
Cache::forget('global_fed_caps_' . Auth::id());
return Inertia::render('Auth/Login', [
'loginAttempt' => false,
'hasAccess' => false,
Expand Down
37 changes: 21 additions & 16 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,34 @@ public function version(Request $request): ?string
public function share(Request $request): array
{
$user = null;
$globalFedCaps = [
'list' => [],
'default' => null,
];
if (Auth::check()) {
$user = User::find(Auth::user()->id);
$user = User::find(Auth::id());

$globalFedCaps = Cache::remember('global_fed_caps_' . $user->id, now()->addHours(10), function () {
$fedCaps = FedCap::select('id', 'guid', 'start_date', 'end_date', 'status')
->without(['caps'])
->active()->orderBy('id')->get();
if($fedCaps->isEmpty()) {
return [
'list' => [],
'default' => null,
];
}
return [
'list' => $fedCaps,
'default' => $fedCaps[0]->guid
];
});
}

$sortedUtils = Cache::remember('sorted_utils', 180, function () {
return Util::getSortedUtils();
});

$globalFedCaps = Cache::remember('global_fed_caps', now()->addHours(10), function () {
$fedCaps = FedCap::select('id', 'guid', 'start_date', 'end_date', 'status')
->without(['caps'])
->active()->orderBy('id')->get();
if($fedCaps->isEmpty()) {
return [
'list' => [],
'default' => null,
];
}
return [
'list' => $fedCaps,
'default' => $fedCaps[0]->guid
];
});

return array_merge(parent::share($request), [
'auth' => [
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Requests/AttestationEditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace App\Http\Requests;

use Auth;
use App\Models\Attestation;
use App\Models\Cap;
use App\Models\Institution;
use App\Models\Program;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

class AttestationEditRequest extends FormRequest
Expand Down Expand Up @@ -70,7 +72,12 @@ protected function prepareForValidation()
$program = Program::where('guid', $this->program_guid)->first();
//get the inst active cap.
$inst = Institution::where('guid', $program->institution_guid)->active()->first();
$cap = Cap::where('institution_guid', $inst->guid)->active()->where('program_guid', null)->first();

$cap = Cap::where('fed_cap_guid', Cache::get('global_fed_caps_' . Auth::id())['default'])->active()
->where('program_guid', null)
->where('institution_guid', $inst->guid)
->first();
// $cap = Cap::where('institution_guid', $inst->guid)->active()->where('program_guid', null)->first();
//now check if there is a cap against the program
$progCap = Cap::where('institution_guid', $inst->guid)->active()->where('program_guid', $this->program_guid)->first();
//if there is a program cap then use it as the cap_guid not the institution cap
Expand Down
10 changes: 9 additions & 1 deletion app/Http/Requests/AttestationStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace App\Http\Requests;

use Auth;
use App\Models\Attestation;
use App\Models\Cap;
use App\Models\Institution;
use App\Models\Program;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

class AttestationStoreRequest extends FormRequest
Expand Down Expand Up @@ -66,7 +68,13 @@ protected function prepareForValidation()
$program = Program::where('guid', $this->program_guid)->first();
//get the inst active cap.
$inst = Institution::where('guid', $program->institution_guid)->active()->first();
$cap = Cap::where('institution_guid', $inst->guid)->active()->where('program_guid', null)->first();

$cap = Cap::where('fed_cap_guid', Cache::get('global_fed_caps_' . Auth::id())['default'])->active()
->where('program_guid', null)
->where('institution_guid', $inst->guid)
->first();

// $cap = Cap::where('institution_guid', $inst->guid)->active()->where('program_guid', null)->first();
//now check if there is a cap against the program
$progCap = Cap::where('institution_guid', $inst->guid)->active()->where('program_guid', $this->program_guid)->first();
//if there is a program cap then use it as the cap_guid not the institution cap
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Cap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Cache;
use Auth;

class Cap extends Model
{
Expand Down Expand Up @@ -78,7 +79,8 @@ public function scopeActive($query)

public function scopeSelectedFedcap($query)
{
$guid = Cache::get('global_fed_caps');
$guid = Cache::get('global_fed_caps_' . Auth::id());

if (is_null($guid)) {
return $query;
}
Expand Down

0 comments on commit 873d25c

Please sign in to comment.