administrate
administrate copied to clipboard
Namespaced dashboards for different level of administrations
- What would you like to be able to do? Can you provide some examples? Is it possible at the moment to handle different levels of administration ? Say I want an admin with it's set of specific dashboards and a super_admin with it's own set of routes, dashboards and resources ?
At the moment, if I already have an administrate setup for admins, generating rails generate administrate:install --namespace=super_admin for super admins seem to overwrite my current dashboards in app/dashboards, I would like my dashboards to be namespaced, so I can handle this scenario
Thank you for the feedback. I'm aware of this issue, and I'm afraid it doesn't have an easy solution. It's something I'd like to look into in the future, but it will be a while before that.
A workaround would be to host these two separate admins as separate applications altogether. It's probably a bit of work, but with the right setup you could be running them off the same code, with some if
/etc in place to avoid duplication.
Any solution for this?
made this solution but I didn't test in all conditions
#config/route.rb
namespace :control do
resources :accounts
end
#app/controllers/control/accounts_controller.rb
class AccountsController < Admin::ApplicationController
def dashboard
@dashboard ||= Control::AccountDashboard.new
end
end
#/lib/base.rb
module Administrate
module Page
class Base
def resource_name
@resource_name =
dashboard.class.to_s.scan(/(.+)Dashboard/).first.first.underscore.gsub("control/", "")
end
end
end
end
#app/dashboards/control/account_dashboard.rb
# different attributes for account_dashboard for same resource account
#app/controllers/admin/application_controller.rb
require 'base'
I know this is a code smell, but it's working
#lib/administrate/base_dashboard.rb
...
module Administrate
class BaseDashboard
include Administrate
def permitted_attributes
form_attributes.map do |attr|
attribute_types[attr].permitted_attribute(
attr,
# resource_class: self.class.model,
resource_class: self.class.to_s.gsub("Control::", "").constantize.model,
)
end.uniq
end
@brenoperucchi - I think you are generally on the right track. At the moment Administrate doesn't support this, but it could be fixed by going through the code addressing all situations where assumptions are made about the namespace and location of the dashboards. The sort of changes that you are proposing could be made into Administrate.
https://github.com/brenoperucchi/administrate/tree/main_imentore
I have been using this solution for a while to add one more namespace. I have not covered all administrate codes but works to my use.
this is the major updates: https://github.com/brenoperucchi/administrate/commit/e8ff7594d3afff3e44ceb13747f9b739ba4c4669
Closing in favour of https://github.com/thoughtbot/administrate/issues/1764