- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
Support linking to STI models #2859
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
base: main
Are you sure you want to change the base?
Conversation
| When I proposed this solution (target.class.base_class), I only checked for one level of inheritance. But does it work with multiple level ? For example: Request < Message Authentication < Request | 
| @gh-axel-czarniak It probably doesn't work with multiple levels of inheritance. However, this feature is currently broken for codebases with both one level and multiple levels of inheritance. This PR fixes it for relationships with one level of inheritance, so it's a step in the right direction. We can always follow up by adding additional logic to support multiple levels of inheritance. | 
| Is your proposed workaround supposed to make  | 
| @mitchwolfe1 It needs to be used in combination with the code in the PR. Overwriting  | 
| Thank you for looking into this @matteeyah! I've been playing with it a bit today. Regarding @gh-axel-czarniak's question on multilevel inheritance, how about the following implementation? (Inspired by the one in this PR).     def accessible_action?(target, action_name)
      target = target.to_sym if target.is_a?(String)
      target_class_or_class_name =
        target.is_a?(ActiveRecord::Base) ? target.class : target
      existing_action?(target_class_or_class_name, action_name) &&
        authorized_action?(target, action_name) || superclass_accessible_action?(target, action_name)
    end
    def superclass_accessible_action?(target, action_name)
      return false unless target.is_a?(ActiveRecord::Base)
      return false unless target.class.superclass <= target.class.base_class
      accessible_action?(target.becomes(target.class.superclass), action_name)
    endRe: having the old behaviour of flat hierarchy, I'd rather we didn't need have to implement  | 
| @pablobm Nice idea, I implemented your suggestion for adding support for multi-level inheritance. | 
| I've gone through this again, experimenting and comparing the behaviour currently in  The original issue #2813 is described in the context of a  When I compare  The behaviour I see is the following: 
 This is not something that can be changed via  
 Would you be able to share your experiences to help me understand a bit better? | 
| Maybe we could use this:  | 
Summary
Administrate doesn't support creating links to STI resources. This change changes
ApplicationHelper#accessible_action?so that it:Backwards compatibility
The behavior for STI superclasses is already broken. It displays flat resources, instead of linking to their respective pages. However, if people are relying on this broken behavior, merging this change will break the experience for them and make it result in an error. If they want to continue treating subclasses as the base class, they can add the following to their STI base class.
Related #2813