CanCan exception in Spree::Api::BaseController #4819
Replies: 1 comment 6 replies
-
Good question! I don't have a real answer but I'll try to write some discussion points here to see if we can find the reason why it's like that. I'm assuming you are talking about the API, even if we might have similar logic in the other components as well. First of all, it has been like that from the origin of that code, see 08656fb. I think the decision here has been to treat both cases (unauthorized and forbidden) in the same way, because there are resources that can be configured to be accessed by guests users as well, which do not require any authentication. To solve that case, being the permission set the single source of truth for who has access to a specific resource, someone decided that returning 401 for everything was enough. That said, I think what you are saying makes a lot of sense and I think there's a better solution for this problem, which is probably implementing something similar to what has been proposed here: ryanb/cancan#659. Do you think that would be a proper solution? |
Beta Was this translation helpful? Give feedback.
-
Hi everybody! Can you please tell me if it makes sense that rescue_from CanCan::AccessDenied, with: :unauthorized returns 401 when the user is denied an action? For example, "authorize! :update, @order, order_token" - if I set a condition in the rights set that I can't update the order, then I'll get 401, not 403, because the controller has rescue_from CanCan::AccessDenied, with: :unauthorized. How can i get 403 in normal way?
Beta Was this translation helpful? Give feedback.
All reactions