-
-
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
Can't apply rules to create
action without affecting new
because of aliasing
#832
Comments
similar case with Reason for this behaviour is described at cancancan docs. @durierem: Could it be a workaround to put another |
Redefining I don't understand how these aliases have been thought through without realizing that it clashes with the very same action it tries to alias. The reasoning is given as:
Which, to my understanding, doesn't change anything apart from the fact that I can write |
Same like in my case: The first |
For me, the aliases are very reasonable, even with the clash of names of My understanding is:
so there is no reason to allow a All case I saw that seem to require such a decoupling were misuse of Use dedicated actions. |
I set up a new project, just for testing this. In a current project, I have read-only permissions through a form with a can
This way you can create a read-only privilege set that allows you to see the forms, but not to write anything to the database (:update / :create). But a
Now i understand what @mameier says: in that case theese linkins making sense! Because if update is allowed there would be no reason for restrict the form. And that exactly is described at the docs and thats making sense. But when is the first case I want to restrict cannotBut the point comes now:
|
I understand the argument that Or This should be clearified by the maintainers. |
@mameier Your point is completely valid... in an ideal world. Also, organizing my app to satisfy CanCanCan's assumptions feels off. It should be the other way around. |
Yes. Its really better to use dedicated controller actions for new apps like @mameier says. But for the |
In my example, the customer did not want to have an edit and a show button separately. So if you really want to have "dedicated actions" at this point, that means separate routes (edit/show), separate request tests, separate route tests, and separate controller actions. The controller action needs to provide instance variables. And in the index view you would need a condition: If update allowed, then take the edit route helper, otherwise take the show route helper. For each view in the entire application From a concise naming point of view, you have to separate: edit is edit and show is show. The same app has a "backoffice" with edit and show actions, and yes, of course it is cleaner. But from a functional point of view, it is a lot of code for nothing else than always rendering the same partial with a form that is disabled in one case and enabled in the other case. Why Html is givig us the My example application was taken from another developer. In short, I'd say: @mameier's statement should be a general recommendation, and in case of doubt: be more conciese. But is should not be a requirement. |
Imagine a form for which some controls are locked because of insufficient permissions or a paid feature you don't have access to. In this case, it seems perfectly logical to me to have the |
Of course there is a reason in a In my case, I want to create a can [:create], Member, plan: { condition: false } The user has many roles and permissions that let him create members with a dropdown of multiple plans. I'm not gonna create a I want a single def new
@member = Member.new
end |
Suggestion:
|
Or just add some way to disable/remove selected aliases. |
Steps to reproduce
I have a resource for which I would want to have different rules for
#new
and#create
. But when I do:Since
create
is an alias fornew
andcreate
I can't have seperate rules forcreate
only without affectingnew
Can I opt-out of aliasing somehow?
Expected behavior
N/A
Actual behavior
N/A
System configuration
Rails version: 6.1.7
Ruby version: 3.2.0
CanCanCan version: 3.5.0
The text was updated successfully, but these errors were encountered: