Skip to content
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

Provide a config option for RailsAdmin to override default_scope #2428

Closed
wants to merge 4 commits into from

Conversation

dburt
Copy link
Contributor

@dburt dburt commented Oct 9, 2015

Synopsis:

RailsAdmin.config do |config|
  config.global_default_scope = :unscoped
  config.global_default_scope = ->{|model| model == User ? User.admins : model.all }
end

I've modelled my approach on this comment by @jxpx777 (#1348 (comment)) but made it more flexible by allowing a block.

There are some things that still need to be resolved, which I need help with:

  • Rubocop failures because I've added enough to the Config and Mongoid adapter modules that they've gone over 164 lines
  • The best name for the config
  • Documentation

@mshibuya
Copy link
Member

Alternative way already exists - please take a look at #1348 (comment).

@mshibuya mshibuya closed this Oct 10, 2015
@dburt
Copy link
Contributor Author

dburt commented Oct 10, 2015

Tried it, it doesn't work. It only works for list views, and if you try to view or edit a record it breaks. Unless I'm missing something?

(See also this comment on Stack Overflow: this only works "if you only need to list the records": http://stackoverflow.com/a/28205484/1279840

@mshibuya
Copy link
Member

@dburt You're right, reopened #1348.

Anyway, I won't merge this in. I believe this kind of configuration should be achieved via instance option style DSL, not attr_accessor.

@dburt
Copy link
Contributor Author

dburt commented Oct 10, 2015

Thanks for reopening.
Can you please show me what you want the config file to look like?
On 10/10/2015 8:24 PM, Mitsuhiro Shibuya [email protected] wrote:

@dburt You're right, reopened
#1348.
Anyway, I won't merge this in. I believe this kind of configuration should be achieved via instance option style DSL, not attr_accessor.

Reply to this email directly or
view it on GitHub.

This communication is confidential. If you are not the intended recipient of this email, any use, forwarding, printing or reproduction of it or any attachment, is prohibited. If you have received this communication in
error, immediately contact us by return email. Whilst we employ an enterprise class anti-virus solution, we give no warranty express or implied that either this email or its attachments are free from viruses or other harmful code and we will accept no liability
in respect of same. It is your responsibility to check for viruses or other harmful components before opening or using any attachments to this email. You should not copy, use, disclose or distribute this e-mail without the author's permission.

Please consider the environment and don't print this e-mail unless you really need to.

@dalpo
Copy link
Contributor

dalpo commented Oct 10, 2015

@mshibuya @dburt I think you could already manage it, using an authorization adapert like cancancan.

https://github.com/sferik/rails_admin/wiki/CanCanCan

For instance:

class Ability
  include CanCan::Ability
  def initialize(user)
    if user.admin?
      can :manage, User, User.unscoped 
    else
      can :manage, User, User.another_scope
    end
  end
end

@dburt
Copy link
Contributor Author

dburt commented Oct 13, 2015

Thanks @dalpo and I can see that that can work. But I don't think it's the best solution to use a separate authorization tool with 8 extra lines of configuration for each model for this simple, non-authorization-related use-case.

@mshibuya please show me what you want the DSL to look like, and I'll be happy to change my implementation.

@dburt
Copy link
Contributor Author

dburt commented Mar 6, 2016

@mshibuya can this change be acceptable with a new DSL? If so, could you please show me what you'd like the DSL to look like? Then I could change the implementation. Otherwise, we could abandon and close this ticket.

@ghost
Copy link

ghost commented Mar 12, 2016

@dburt, I'm interested in this feature; maybe doing a quick search for instance option style can give you some clue to what @mshibuya refers to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants