Skip to content

Commit 71d62cb

Browse files
authored
Merge pull request #11 from soap/develop
Develop
2 parents 1744e77 + 670bda7 commit 71d62cb

File tree

3 files changed

+10
-42
lines changed

3 files changed

+10
-42
lines changed

config/workflow-process.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
// 'evaluator' => function (array $variables) { return true; },
1313
// ],
1414

15-
// 'authenicated' => \Soap\LaravelWorkflowProcess\GuardFunctions\Authenticated::class,
16-
17-
'authenticated' => [
18-
'compiler' => function ($guard = 'web') {
19-
return sprintf('authenticated("%s")', $guard);
20-
},
21-
'evaluator' => function (array $variables, $guard = 'web') {
22-
// This allows checking a specific guard (e.g., 'web', 'api', etc.)
23-
return auth()->guard($guard)->check();
24-
},
25-
],
15+
// 'isAdmin' => \Soap\LaravelWorkflowProcess\GuardFunctions\AdminGuardFunction::class,
2616
],
2717
];

src/Listeners/WorkflowGuardSubscriber.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,13 @@ public function handleOnGuard(GuardEvent $event): void
3838
$guardExpression = $metaData['guard'];
3939
// Prepare variables to pass to the evaluator.
4040
// You can pass the workflow subject, user, or any other required objects.
41+
42+
$workflowProcess = app('workflow-process');
4143
$variables = [
4244
'subject' => $event->getSubject(),
45+
'authenticated' => $workflowProcess->getAuthenticated(),
46+
'user' => $workflowProcess->getUser(),
4347
];
44-
$workflowProcess = app('workflow-process');
45-
46-
$authenticated = $workflowProcess->getAuthenticated();
47-
$user = $workflowProcess->getUser();
48-
49-
$variables['authenticated'] = $authenticated;
50-
51-
// Optionally include the authenticated user.
52-
if ($authenticated) {
53-
$variables['user'] = $workflowProcess->getUser();
54-
}
5548

5649
// Evaluate the guard expression using the GuardEvaluator.
5750
$result = $this->guardEvaluator->evaluate($guardExpression, $variables);

src/WorkflowProcess.php

+5-20
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,13 @@ public function getAuthenticated()
4141
public function getUser()
4242
{
4343
$guards = config($this->configFile.'.authentication.guards', ['web']);
44-
$logic = config($this->configFile.'.authentication.logic', 'or');
45-
46-
if ($logic === 'and') {
47-
// The user is considered authenticated only if all guards return true.
48-
$user = null;
44+
$user = null;
4945

50-
foreach ($guards as $guard) {
51-
if (auth()->guard($guard)->check()) {
52-
$user = auth()->guard($guard)->user();
53-
break;
54-
}
46+
foreach ($guards as $guard) {
47+
if (auth()->guard($guard)->check()) {
48+
$user = auth()->guard($guard)->user();
49+
break;
5550
}
56-
} elseif ($logic === 'or') {
57-
$user = null;
58-
foreach ($guards as $guard) {
59-
if (auth()->guard($guard)->check()) {
60-
$user = auth()->guard($guard)->user();
61-
break;
62-
}
63-
}
64-
} else {
65-
throw new \InvalidArgumentException('Invalid authentication logic. Use "and" or "or".');
6651
}
6752

6853
return $user;

0 commit comments

Comments
 (0)