-
Couldn't load subscription status.
- Fork 67
Allow admins to inspect objects on HCB #11856
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
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first pass!
| def active_teenagers_leaderboard | ||
| end | ||
|
|
||
| def inspect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this overrides a Ruby method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good catch. maybe I'll restructure these to be one route. there was previously a need for them to be separate but I can combine them now since it's all being done in turbo.
| @resource_type = params[:resource] | ||
| @resource_id = params[:id] | ||
|
|
||
| Zeitwerk::Loader.eager_load_all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are likely some columns that we shouldn't even allow admins inspect. I'm specifically thinking of encrypted columns such as session tokens, plaid tokens, etc.
At the moment, encrypted columns are not available to admins via Blazer bc blazer doesn't decrypt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had considered making a concern, say inspectable, that could help us standardize configuration keep track of which columns should be accessible on the model itself. Does that sound like a good path forward?
At the moment, encrypted columns are not available to admins via Blazer bc blazer doesn't decrypt.
Do we want to hide encrypted columns in the inspection toolbar? I can see a case for either being made; on one hand, it allows for more destructive powers as an admin, but on the other hand, it reduces our reliance on the production Rails console.
| Zeitwerk::Loader.eager_load_all | ||
|
|
||
| # get all named classes extending ApplicationRecord | ||
| @all_resource_types = ObjectSpace.each_object(Class).select { |c| c < ApplicationRecord }.select(&:name).map(&:name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this different than calling descendants on ApplicationRecord?
Also, maybe we should do ActiveRecord::Base to capture more models such as those created by gems. See which classes it would add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into this. I think I had that approach initially and it caused some issues, but I don't recall exactly why I switched away from this. I'll get back to you.
|
|
||
| def self.find_relations(object) | ||
| if object.class < ApplicationRecord | ||
| object = object.attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe AR has a method something along the lines of reflect_on_associations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does—this was a quick and dirty way of adding a shortcut for [anything]_id, but it would be nice to work with other association types too.
Summary of the problem
HCB engineers and operations staff frequently need to access information about a record that isn't show in the interface. Sometimes records can get into broken states, and you can't access the intended admin page. Or, sometimes we just don't show enough about an object, requiring staff to use Blazer or use the production console.
Describe your changes
This PR proposes adding an admin-only inspection toolbar. Inspired by Stripe and Cockpit, this toolbar intelligently detects the primary object of the current page you're on (using some Rails routing magic) and renders a text-based representation of the object to assist with troubleshooting and debugging. It also allows you to follow any direct associations or look up an object manually by and of its primary fields.