Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !1941

Unify action checks

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Pablo Brasero requested to merge github/fork/pablobm/unify-action-checks into main Mar 11, 2021
  • Overview 8
  • Commits 1
  • Pipelines 0
  • Changes 34

Fixes: https://github.com/thoughtbot/administrate/issues/1861

When referring to a route in the code, we run two checks:

  • valid_action? is true if the route is defined, false otherwise.
  • show_action? is expected to be overridden by developers in order to implement authorization. For example, it's implemented by Administrate::Punditize in order to integrate Administrate with Pundit. It should return true if the current user can access a given route, false otherwise.

These two check should (almost) always happen together. For this reason, our code is peppered with if statements where both are checked... and a few others where we forget one or the other.

These checks should be unified into a single method call, in order to avoid issues like the one described at https://github.com/thoughtbot/administrate/issues/1861. Here I propose such a method, which I call accessible_action?.

The original methods should still exist, as they do have their uses individually. The new method will delegate to the existing ones.

I have also renamed the two existing methods to something that I hope will make their intent clear:

  • valid_action? becomes existing_action?
  • show_action? becomes authorized_action?
  • In order to provide a clear upgrade path, the old names still exist and work, but they show a deprecation warning when used. They can be removed properly at a later version of Administrate.

Open question!

The original methods have a signature the_old_question?(action, resource). I have flipped the order of parameters to be the_new_question?(resource, action), as I find that more natural. But if people think the original order is better (or have some other proposal), I'm happy to oblige.

Also! The old valid_action? has a default parameter value (the full signature is valid_action?(name, resource = resource_class)). The new version doesn't have it, as I can't see that it has a good use case. Incidentally, this makes sense with the parameter order flip just described.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/pablobm/unify-action-checks