-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add filter permission and group #535
Add filter permission and group #535
Conversation
There is a conflict. Please rebase. |
c14dcb3
to
714bdd1
Compare
I rebased. Though it's giving me Rector fails now. If I fix the Rector issues then it becomes PHPStan issues since it doesn't know what type of variable it is, so I don't know how to please both, here.
vs:
|
Co-authored-by: kenjis <kenji.uui@gmail.com>
Lang items are missing.
https://github.com/codeigniter4/shield/actions/runs/3580771788/jobs/6023181104 |
…ell/shield into add-filter-permission-and-group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since really all that is different is the actually Auth check (inGroup()
versus can()
) can we make an abstract filter class that handles all the rest and just processes the arguments in a separate method?
abstract protected function isAuthorized(array $arguments);
This would make a convenient starting point for developers making their own authorization filters as well.
@MGatner Good call. Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If the previous_url is from this site, then | ||
// we can redirect back to it. | ||
if (strpos(previous_url(), site_url()) === 0) { | ||
return redirect()->back()->with('error', lang('Auth.notEnoughPrivilege')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this PR in a practical way. I did not see a problem.
What bothers me is displaying the error message to the user.
Bonfire2 uses Tatter/Alerts to display errors, but the following code should be used to display errors on the shield:
<?php if (session('error') !== null) : ?>
<div class="alert alert-danger" role="alert"><?= session('error') ?></div>
<?php elseif (session('errors') !== null) : ?>
<div class="alert alert-danger" role="alert">
<?php if (is_array(session('errors'))) : ?>
<?php foreach (session('errors') as $error) : ?>
<?= $error ?>
<br>
<?php endforeach ?>
<?php else : ?>
<?= session('errors') ?>
<?php endif ?>
</div>
<?php endif ?>
In fact, I'm not sure how Shield users should know what to do to display error message (Auth.notEnoughPrivilege
). Perhaps the need to add an explanation in the documentation or something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks all.
Supersedes #393
Provides new Groups/Permission filters.
Most of the original work was done by @jlopes90, I just tweaked the filters and added tests.