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
  • Issues
  • #1468
Closed
Open
Issue created Nov 14, 2019 by Administrator@rootContributor

Fields without corresponding model methods and fancier behavior for `Page::Base#get_attribute_value`

Created by: dylnclrk

First off, I'm having a great time using Administrate on a project. Thank you for maintaining such a helpful gem!

What would you like to be able to do? Can you provide some examples?

I have a User model and am hitting an external API to gather some additional information about the user (e.g., to get "badges" assigned to a user). I'd love to show the results of this API call on the admin user show page.

One way to do this is to add a method User#badges that hits our badge API and returns the results. However, I think it would be preferable not to add this method to User, as it won't be used outside of the admin pages. Is there a way to do this?

I'd love to be able to somehow modify the way Page::Base#get_attribute_value works for my User page. Such that, when the attribute in question is :badges, it doesn't end up calling resource.public_send(:badges).

Does this already exist? Am I missing an obvious workaround?

How could we go about implementing that?

Provide a hook in the dashboard like ATTRIBUTE_GETTERS, and change get_attribute_value to first look in ATTRIBUTE_GETTERS before calling resource.public_send(:badges). The values in ATTRIBUTE_GETTERS might be methods with the signature some_getter(resource).

Can you think of other approaches to the problem?

  • I could modify the show page for User, and render the badges in the show template manually, and not treat them as fields.
  • I could also create an Admin::User class that decorates User with the additional fields it needs. But I haven't seen a good pattern for doing this.
  • I could also perhaps modify the User Page, so that it has a custom implementation of #get_attribute_value that knows about the special case for :badges. But I'm not exactly sure how to do this.

Also, FWIW, I'd be happy to take a stab at the ATTRIBUTE_GETTERS implementation if that's something that feels like it's in the spirit of the project, and assuming I haven't missed something obvious (I probably have). But it would probably take me a while.

Thanks again!

Assignee
Assign to
Time tracking