Skip to content

Commit

Permalink
Merge branch '3.x' into test-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AravindRam-Ranium committed Feb 14, 2024
2 parents 511ad4e + ac205a3 commit 76d5436
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 44 deletions.
36 changes: 14 additions & 22 deletions src/Http/Middleware/ForceRedirectToUnapprovedConsents.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,28 @@ class ForceRedirectToUnapprovedConsents
{
public function handle(Request $request, Closure $next)
{
if (Auth::guard('admin')->check()) {
$guard = 'admin';
} elseif (Auth::guard('enduser')->check()) {
$guard = 'enduser';
} elseif (Auth::guard('practitioner')->check()) {
$guard = 'practitioner';
} else {
// Get the currently authenticated user across all guards
$user = Auth::user();

// If no user is authenticated, proceed with the request
if (!$user) {
return $next($request);
}

$isConsentRoute = str_contains($request->route()->getName(), 'consent-options');
if (
//must be logged in
Auth::guard($guard)->user()
//have the trait installed
&& method_exists(Auth::guard($guard)->user(), 'hasRequiredConsents')
//Not be a consent route
&& ! $isConsentRoute
//Not an ajax call
&& ! $request->ajax()
//Not have required consents signed
&& ! Auth::guard($guard)->user()->hasRequiredConsents()
) {
//Save current request URL
// Determine if the current route is exempt (a consent route or ends with '.logout')
$route = $request->route()->getName();
$isExemptRoute = str_contains($route, 'consent-options') || str_ends_with($route, '.logout');

// Check for required consents if user is authenticated and not on an exempt or logout route
if (!$isExemptRoute && !$request->ajax() && method_exists($user, 'hasRequiredConsents') && !$user->hasRequiredConsents()) {
// Save the current request URL
$request->session()->put('url.saved', $request->fullUrl());

//Redirect user to ask for consent
// Redirect user to ask for consent
return redirect()->route('consent-option-request');
}

return $next($request);
}

}
44 changes: 22 additions & 22 deletions src/Livewire/ConsentOptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,23 @@ class ConsentOptionRequest extends SimplePage
use InteractsWithFormActions;
use InteractsWithForms;

public Model $user;
public $user;

public Collection $collection;

public $acceptConsents = [];

public function mount(): void
{
if (Auth::guard('admin')->check()) {
$this->user = Auth::guard('admin')->user();
} elseif (Auth::guard('enduser')->check()) {
$this->user = Auth::guard('enduser')->user();
} elseif (Auth::guard('practitioner')->check()) {
$this->user = Auth::guard('practitioner')->user();
}

if (! $this->user) {
abort(403, 'Only authenticated users can set consent options');
}
$this->user = auth()->user();

$this->user->collections = $this->user->outstandingConsents();

if ($this->user->collections->count() < 1) {
abort(403, 'No required consent');
}
}



public static ?string $title = 'Your consent is required';

protected static string $view = 'vendor.user-consent.livewire.consent-option-request';
Expand All @@ -81,11 +70,12 @@ public function infolist(Infolist $infolist): Infolist
->record($this->user)
->schema([

Fieldset::make('Your consent is required')->schema([

TextEntry::make('info')
->label('')
->label("")
->size(TextEntry\TextEntrySize::Medium)
->default(new HtmlString("Hi {$this->user->fullName}, please read these terms and conditions carefully, we will email a copy to {$this->user->email}")),
->default(new HtmlString("Hi {$this->user->firstname}, <br>Please read these terms and conditions carefully, we will email a copy to {$this->user->email}"))
->extraAttributes(['class'=>'mb-4']),

RepeatableEntry::make('collections')
->label('')
Expand Down Expand Up @@ -115,8 +105,18 @@ public function infolist(Infolist $infolist): Infolist
->state(function (ConsentOption $record): string {
return new HtmlString('<strong>Last Updated</strong>: '.$record->updated_at->format('d M Y'));
})
]),
])
->collapsible()
->collapsed(function(ConsentOption $record){
$first = $this->user->collections->first();
return !($first->id === $record->id);

})
->persistCollapsed()
->id(fn (ConsentOption $record) => "consent-option-{$record->id}")
,
])
->contained(false)
->columns(2)
->columnSpanFull(),
Actions::make([
Expand All @@ -130,8 +130,8 @@ public function infolist(Infolist $infolist): Infolist
$this->acceptConsent();
}),
])->alignEnd(),
])->columns(1),
])->columns(3);

])->columns(1);
}

public function previousConsents($key)
Expand Down Expand Up @@ -172,8 +172,8 @@ public function acceptConsent()
);
}
Notification::make()
->title('Welcome.!')
->body('Your submitted all consent options are saved.')
->title('Success')
->body('Your consent preferences have been saved.')
->icon('heroicon-o-check-circle')
->color('success')
->send();
Expand Down

0 comments on commit 76d5436

Please sign in to comment.