[WIP] Improvements to SimpleRbac#411
Conversation
|
This is weird... I swear the tests pass locally... Can anyone take a look? Local tests |
Well this screwed me over |
|
Hi @Xymanek this is looking promising, I'm concerned about the BC issue forcing people to refactor their rules if we go ahead with this PR, could you allow a legacy mode or move the changes to a new ImprovedRbac Auth object (possibly reusing most of the code in an abstract class) so we can ensure users will keep their rules working? Keep in mind rules are critical to maintain in existing apps... Thanks! |
|
The changes were aimed to be completely BC which can be seen by existing tests (only CS check failed, I'll fix that if we decide to go on with this). However the As for new Auth object... I've thought about that but decided against since the changes are BC and that would simply make it harder to upgrade for existing users. Although I do agree that calling this TL; DR I aim to not alter the behavior of current use cases in any shape or form. |
|
Excellent! I would be happy to help in any improvements you have in mind 👍 |
|
Well the 'universal auth system' is a very long shot 😀 so it's a topic for another discussion. As for this PR, do you think the idea of making the |
|
Ok, About the role, the reason is using the defaults when no role provided, or role is defined in an associated table and not directly in the users table. I guess we could inject the value into the user array so it can be accessed later on? |
|
I thought about injecting it into the user array but I would rather leave |
|
makes sense for me |
|
I'm almost done with the tests but I have a couple of questions:
|
|
What is the "Cake" way of writing multi-line if conditions? How do I test if a message was logged? Thanks |
|
Okay, tests are almost finished. I also corrected some of existing tests so that they actually run (some array keys were same so only one out of two sets of arguments run). Also some fixes to my previous code (because what are the tests for?:smile:)
When I was asking about multi-line IFs I meant this that caused this error. Also how do I fix this? |
|
ping @steinkel |
|
Hi @Xymanek this is looking good... About this looks like we'll need to put the first condition in the if line, and break after the About this did you try this instead? If this is causing issues to phpcs we might need to send a PR to the sniff rules, please remove it if causing issues to don't block this PR moving fw. Thanks! |
|
Figured out how to use the cs checker locally (I don't use it myself), unfortunately it's unhappy with the docblock either way 😞. As per your request I removed it. |
|
I have no idea why tests involving code that I didn't touch at all failed.... |
|
I've found bugs in my code, please don't merge yet |
…nd updated imports
|
Sorry that this took so long, I have too much stuff going on in my life right now :( |
| Creating rule classes | ||
| --------------------- | ||
|
|
||
| The only requirement is to implement `\CakeDC\Users\Auth\Rules\Rule` interface which has one method: |
There was a problem hiding this comment.
Shouldn't this be called RuleInterface as per conventions?
There was a problem hiding this comment.
I don't see mentions to the Interface convention here http://book.cakephp.org/3.0/en/intro/conventions.html or http://www.php-fig.org/psr/psr-2/ but makes sense for me to add it and match the interfaces defined in the core. Let's do this BBC change in a future milestone.
| * @param string $role role of the user | ||
| * @param Request $request current request, used to get a default table if not provided | ||
| * @return bool | ||
| * @throws \OutOfBoundsException if table is not found or it doesn't have the expected fields |
There was a problem hiding this comment.
I feel like this belongs to the abstract class since custom logic may or may throw any exceptions and we are not catching any specific ones
|
thank you @Xymanek I'll take a look and let you know |
|
I think the failing tests would be corrected after merging develop branch, could you do that please? Thanks, |
|
Sorry, I'm not very experienced with github and cross-fork merging... I've ticked "Allow edits from maintainers" on the right of this PR, I guess you have the rights to do it yourself? |
|
Merged with develop branch and created new PR #423 |
|
Closed per #423 |
This is my take on #407 plus some additional things. It is completely BC (according to existing tests) and features several improvements:
foreach) so if a rule fails, it won't compare the next one and comparison is done in user-defined order (vs previously hard-codedrole -> prefix -> plugin -> extension -> controller -> action -> allowed)\CakeDC\Users\Auth\Rules\Ruledo not have to be placed underallowedkey and you can use many of those inside one permission'role.title' => 'Admin'or'role.id' => 2)allowed) by prependinguser.to the array key (eg.user.allowed)allowedkey will be cast to boolean*the result will be inverted (eg.'*controller' => 'Test'will match any controller besidesTest)controllerand/oractionkey(s), it will be discarded and a message will be logged (previously it would fail silently)I think that's about it... If people think this is a good change I'll go ahead and write the additional tests.
One things that bugs be however is that the
$rolevariable that is passed to_matchRuleis not used anywhere besides being passed to callable/\CakeDC\Users\Auth\Rules\Rulesince we are reading directly from user array now