-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Adding support for "can?" check multiple subjects #3
Adding support for "can?" check multiple subjects #3
Conversation
The behaviour when an array of subject is given, is check if there is a permission at least on one of the given subjects.
@ability.can :update, [String, Range] | ||
expect(@ability.can?(:update, ["foo", 1..3])).to be_true | ||
expect(@ability.can?(:update, [123, "foo"])).to be_true | ||
expect(@ability.can?(:update, 123)).to be_false |
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.
Could this be updated to check be_false
against an array, for example, if you sent in an array of [123, 1.0]
it should be false?
Thanks!
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.
sure... but I will not change that line... I will add another assuring that with an array where all subjects have no permission it should be false...
Oh, and add a line to the changelog as well please! |
On further inspection, can we also test this will handle nested You can declare a can? :create, @category => Project I want to ensure we could also send that into the array: can? :create, [{@category => Project}, Category] |
@@ -1,6 +1,11 @@ | |||
Master | |||
|
|||
|
|||
1.7.1 (February 22th, 2014) |
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.
Please drop this line, just add your changelog entry under master. When a new release is cut, we'll assign it to a version.
Thanks!
+1 on this feature. Among other things, it's going to make testing much cleaner. @cefigueiredo are you planning on completing this? |
Sure... I'm working on some problems. Maybe I change a bit how it will deal with multiple subjects... but the functionality will be implemented! |
During the test to permit pass an Object as a hash I needed to change how call can? to mantain the functionality to pass any object inclusive an instance of Array as a single subject. To assure that funciontality, now we need to pass a hash containing a key :any and the array of subjects as his value. The array deals with the same objects that an usual can? does... and obviously, that hash is only necessary when checking multiple subjects.
To ensure that can? can receive the same objects and in the same way a can? with single subject does; I changed how to pass the multple subjects. can? :read, { :any => [{@category => Project}, Category] } |
I like that! We can later add |
Exactly what I thought! I would do that on that commit, but I saw that it was more complex than :any to test and implement. |
@cefigueiredo This is great! Thanks for your contribution! I can't wait to throw this into my tests! @bryanrite is the plan to merge this or should I use @cefigueiredo's fork for the time being? |
Sorry, didn't realize this was ready. @cefigueiredo, @codyolsen I'm going to suggest a couple things to this PR to clean-up the code, afterwards I'll merge it in. |
end | ||
matches.compact.first | ||
else | ||
relevant_rules_for_match(action, subject).detect do |rule| |
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.
Can we extract the relevant_rules_for_match
block into a single method so its not duplicated.
@bryanrite 10-4. Sounds like a plan. |
The method can? was changed and does not pass an array of subject anymore to matches_subject? since last commit. So, I'm removing the method matches_subject_any? that only existed to deal with that array of subjects.
The method can? became a bit messy and repetitive dealing chosing paths almost identical to single and multiple subjects, when only the difference was iterate on the array of subjects. So, I created the method extract_subject that independently if given a single or multiple subjects, it will returns an array of subjects. So, for can? does not matter anymore if subject is single or multiple, it will deal on the same way.
Sorry for the delay on this, just been busy, I'll get this merged in, and try to add |
This has been closed, not merged. State? |
@ekampp The referenced PR was closed. This PR is still open. It is valid, I have just not had a ton of time to integrate it lately, as it will require a new minor version. I'll try and get at it in the next day or two. |
Ohh.. Never mind, then. I'm tiered 😫 |
Are there something I could do to make it easier? On Fri, Apr 11, 2014 at 2:12 AM, Emil Kampp notifications@github.comwrote:
|
Sync with Master repository
Thanks! Sorry it took so long, but I had to spend some time refactoring all the tests before I wanted to add more features. Travis says failing but its due to their latest update and not code, so you can ignore. |
author Remo Fritzsche <remo.fritzsche@sitrox.com> 1612868567 +0100 committer Alessandro Rodi <coorasse@gmail.com> 1657114188 +0200 # This is a combination of 4 commits. # This is the 1st commit message: Preserve nil values as extra arguments # This is the commit message #2: Fix link (#744) # This is the commit message #3: Documentation fixes and improvements - fix typo, punctuations, and grammar - fix broken and misformatted links - fix code sample # This is the commit message #4: Format documentation/guides and fix linting issues The motivation of the changes is to make these documents neater when reading offline using a text or code editor. Reading the documentation offline is faster, and the source code is readily available for further learning. The changes do not affect the meaning of each documentation or instruction. The following changes were made: - remove extra and trailing spaces - add new lines to separate the title, explanation, code samples, etc - fix headings, links - specify code block language (bash, ruby) Updated Devise.md as exception is changed CanCan::Unathorized exception not exists anymore, CanCan::AccessDenied is used. Also added responses for different content types as a recommendation. Add support for non-hash conditions Co-authored-by: Juleffel <juleffel@protonmail.com> Improve ability checks with Hashes Add Ruby 3.0 and Ruby 3.1 to CI Drop ActiveRecord4 from CI (#778)
author Remo Fritzsche <remo.fritzsche@sitrox.com> 1612868567 +0100 committer Alessandro Rodi <coorasse@gmail.com> 1657114188 +0200 # This is a combination of 4 commits. # This is the 1st commit message: Preserve nil values as extra arguments # This is the commit message #2: Fix link (#744) # This is the commit message #3: Documentation fixes and improvements - fix typo, punctuations, and grammar - fix broken and misformatted links - fix code sample # This is the commit message #4: Format documentation/guides and fix linting issues The motivation of the changes is to make these documents neater when reading offline using a text or code editor. Reading the documentation offline is faster, and the source code is readily available for further learning. The changes do not affect the meaning of each documentation or instruction. The following changes were made: - remove extra and trailing spaces - add new lines to separate the title, explanation, code samples, etc - fix headings, links - specify code block language (bash, ruby) Updated Devise.md as exception is changed CanCan::Unathorized exception not exists anymore, CanCan::AccessDenied is used. Also added responses for different content types as a recommendation. Add support for non-hash conditions Co-authored-by: Juleffel <juleffel@protonmail.com> Improve ability checks with Hashes Add Ruby 3.0 and Ruby 3.1 to CI Drop ActiveRecord4 from CI (#778)
author Remo Fritzsche <remo.fritzsche@sitrox.com> 1612868567 +0100 committer Alessandro Rodi <coorasse@gmail.com> 1657114188 +0200 # This is a combination of 4 commits. # This is the 1st commit message: Preserve nil values as extra arguments # This is the commit message #2: Fix link (#744) # This is the commit message #3: Documentation fixes and improvements - fix typo, punctuations, and grammar - fix broken and misformatted links - fix code sample # This is the commit message #4: Format documentation/guides and fix linting issues The motivation of the changes is to make these documents neater when reading offline using a text or code editor. Reading the documentation offline is faster, and the source code is readily available for further learning. The changes do not affect the meaning of each documentation or instruction. The following changes were made: - remove extra and trailing spaces - add new lines to separate the title, explanation, code samples, etc - fix headings, links - specify code block language (bash, ruby) Updated Devise.md as exception is changed CanCan::Unathorized exception not exists anymore, CanCan::AccessDenied is used. Also added responses for different content types as a recommendation. Add support for non-hash conditions Co-authored-by: Juleffel <juleffel@protonmail.com> Improve ability checks with Hashes Add Ruby 3.0 and Ruby 3.1 to CI Drop ActiveRecord4 from CI (#778)
author Remo Fritzsche <remo.fritzsche@sitrox.com> 1612868567 +0100 committer Alessandro Rodi <coorasse@gmail.com> 1657114188 +0200 # This is a combination of 4 commits. # This is the 1st commit message: Preserve nil values as extra arguments # This is the commit message #2: Fix link (#744) # This is the commit message #3: Documentation fixes and improvements - fix typo, punctuations, and grammar - fix broken and misformatted links - fix code sample # This is the commit message #4: Format documentation/guides and fix linting issues The motivation of the changes is to make these documents neater when reading offline using a text or code editor. Reading the documentation offline is faster, and the source code is readily available for further learning. The changes do not affect the meaning of each documentation or instruction. The following changes were made: - remove extra and trailing spaces - add new lines to separate the title, explanation, code samples, etc - fix headings, links - specify code block language (bash, ruby) Updated Devise.md as exception is changed CanCan::Unathorized exception not exists anymore, CanCan::AccessDenied is used. Also added responses for different content types as a recommendation. Add support for non-hash conditions Co-authored-by: Juleffel <juleffel@protonmail.com> Improve ability checks with Hashes Add Ruby 3.0 and Ruby 3.1 to CI Drop ActiveRecord4 from CI (#778)
author Remo Fritzsche <remo.fritzsche@sitrox.com> 1612868567 +0100 committer Alessandro Rodi <coorasse@gmail.com> 1657114188 +0200 # This is a combination of 4 commits. # This is the 1st commit message: Preserve nil values as extra arguments # This is the commit message #2: Fix link (#744) # This is the commit message #3: Documentation fixes and improvements - fix typo, punctuations, and grammar - fix broken and misformatted links - fix code sample # This is the commit message #4: Format documentation/guides and fix linting issues The motivation of the changes is to make these documents neater when reading offline using a text or code editor. Reading the documentation offline is faster, and the source code is readily available for further learning. The changes do not affect the meaning of each documentation or instruction. The following changes were made: - remove extra and trailing spaces - add new lines to separate the title, explanation, code samples, etc - fix headings, links - specify code block language (bash, ruby) Updated Devise.md as exception is changed CanCan::Unathorized exception not exists anymore, CanCan::AccessDenied is used. Also added responses for different content types as a recommendation. Add support for non-hash conditions Co-authored-by: Juleffel <juleffel@protonmail.com> Improve ability checks with Hashes Add Ruby 3.0 and Ruby 3.1 to CI Drop ActiveRecord4 from CI (#778)
Do not run rails >= 7 on ruby < 3
Do not run rails >= 7 on ruby < 3
Do not run rails >= 7 on ruby < 3
* Update gitignore * This is the commit message #3: Do not run rails >= 7 on ruby < 3 * Remove jruby and truffleruby * Fix rubocop * Use rspec instead of rake
The behaviour when an array of subject is given, is check if there is a permission at least on one of the given subjects.