-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Filter and form do not honor scope_to :current_user #70
Comments
You can set the filter :folder, :as => :select, :collection => proc{ current_user.folders.all } That work for you? |
I have the same issue. With
|
Are you using ActiveAdmin's default user naming? If so it's 'current_admin_user', not 'current_user'. |
No, I have exactly |
Like adie I tried a lot of combinations (also with proc) but the problem is still there |
same issue here. At filter and form DSL block no access to current_admin_user, but scope_to :current_admin_user work fine. |
Me three... i can't access current_admin_user from the form block. |
Same form issues here. |
Same here |
Not sure if this can be considered a proper solution, but until that shows up you can use
Still haven't figured out how to access |
I have the same issue. It is correctly set: also tried:
|
I'm having the same issue with trying to set a default value on a hidden form element. Current user config:
Formtastic input:
Resultant HTML:
|
can't believe this hasn't been fixed yet. I am having the same issue. @gregbell you said it should work, but doesn't. What makes you think it should work? Have you got it to work before? |
Whoa, slow it down there @cgunnels! This is open source and you are not paying for it. @gregbell (and others) have put in a lot of work to ensure that ActiveAdmin works for the majority of its users. I'm quite thankful for that. If it's as big of an issue as you're making it out to be then I think it's time to get your hands dirty and contribute some code. |
didn't mean any ill will, came across wrong when you read it. |
Actually, it came out wrong when you wrote it. |
So I hacked something together...for the filters in the register block you can do something like this: In the applicationcontroller.rb set a before filter like so, before_filter :set_current_user and a method like so, If anyone has a better way, I'd love to hear. I think this is a hack and would like a better way to go about using the current user at the scope of ActiveAdmin::DSL |
hello guys I had the same problem and I am a newbie with Ruby. but I understand that the problem was different from scope_to why the filter is processed when the collection is defined. so I made a very ugly monkey patch that solved my problem by processing the collection when the filter will be displayed .. then it is in an instance of the object and not in static class. I set the filter as
and the patch below changes the scope to be the collection when the view is generated if someone has a better solution .. and can send a pull request I appreciate it. unfortunately I have no knowledge for this. module ActiveAdmin
class ResourceController < ::InheritedResources::Base
module Filters
protected
def filters_config
filters = self.class.filters_config
new_filters = []
filters.each do |options|
options = options.merge(:collection => instance_exec(&options[:scope])) if options[:scope]
new_filters << options
end
new_filters
end
end
end
end |
+1, gabpaladino seems to be working for me |
+1 gabpaladino, nasty but it works, although I changed the first 3 lines to this: ActiveAdmin::ResourceController::Filters.module_eval do |
Hey everybody! Could you confirm that @samvincent's pull request #847 fixes the issue you were encountering? |
Hi @samvincent and @pcreux, Our problem is different. I did not know this counts bug, our need scope_to is applied to the values of the filter. For example, we have a Client model, and user has many clients. So if we have a filter select for clients all they are displayed to user, not only that have relationship with current_user. The default :collection option of filters does not accept current_user because is processed as config before the instances of objects. |
I have the same use case than @gabpaladino, it's the list of options for the filter that depends on the current_user |
Hey Guys, i am now with the same problem on new/edit forms! =/ Any sugestion?! I did not get an monkey patch for it! |
Pull request 847 had interesting behavior on my application. Some of the "Show" pages were no longer working, though I'm still a little new to this project, attribute that started erroring was (:body). At any rate, it may address the counts (as I couldn't validate the bug via recreation). I'm really interested in seeing that scope_to is applied to relationships (has_one) dropdown specifically in forms, and even filters would be nice, though I guess I can remove that. Shall I open this a new defect and provide better details and an empty project showing this behavior. (I'm tracking master currently) |
I created a base project with a bare minimum config to show this issue. You can see it here, https://github.com/jancel/scoping_active_admin I'd like to go farther, perhaps creating the tests to recreate this issue, or even a fix. But just knowing that this is in fact not the intended behavior, would help me go farther. |
Show Stopper: Bug 70 This BUG 70 is a show stopper for my multi tenant SaaS App. All models (filters and association selects) must scope to current_account. Apologies but I have insufficient knowledge of AA to assist. Any progress on resolving this Bug 70 much appreciated. Currently using alternative to Active Admin. |
Unfortunately the pull request #847 is not working, we are having both issues mentioned on here, the issue around We have a scope on our model
And when I tried to upgrade to 0.4.0, all the filters were back to their old behaviour (previous to using the patch idea from @gabpaladino ) |
As an interim measure I am putting the following in my initializer: ActiveAdmin::Views::Scopes.class_eval do
protected
def build_scope(scope)
span :class => classes_for_scope(scope) do
begin
scope_name = I18n.t!("active_admin.scopes.#{scope.scope_method}")
rescue I18n::MissingTranslationData
scope_name = scope.name
end
if current_scope?(scope)
em(scope_name)
else
a(scope_name, :href => url_for(params.merge(:scope => scope.id, :page => 1)))
end
end
end
end As you can see, I have removed the following: text_node(" ")
scope_count(scope)
text_node(" ") Just as to avoid confusing our users when the counts are not respecting the |
Of course, my solution sucks and I'm not yet as familiar with the inner workings of ActiveAdmin as to fix this problem. I'll keep on looking though. |
For the form, I confirm that you can do: form do |f|
f.inputs do
f.input :group_id, :as => :select, :collection => f.template.controller.current_client.groups
end
end |
Thanks @pcreux, it works for me! |
When defining a filter, you can pass a collection that will be rendered within the context of the view. For example: ActiveAdmin.register Post do filter :some_attr, :as => :select, :collection => proc{ current_admin_user.some_collection } end
You can now do: ActiveAdmin.register Post do form do if current_admin_user.super_admin? f.inputs "For Super Admins", :super_admin_thing end f.buttons end end
Listed commits above should fix all the issues present here. |
uow it's good! :D thanks @gregbell, i will test |
Has any one actually tested this? I'm still having the same issue with the filters on my index. |
I've done it successfully on versions 0.4.0+ On Sat, Mar 17, 2012 at 11:21 AM, Matt Topper <
|
Ugh, must be something I'm doing then, putting something like filter :user, :as => :select, :collection => User.where(:company_id => current_user.company_id).map(&:email) If I hard code the company_id I get the results I expect, but that isn't going to work obviously |
Ok. Here is what I have in my collection... :collection => f.template.controller.current_user.signatures i'd imagine that you want to do... :collection => f.template.controller.current_user.company_id ... and then On Sat, Mar 17, 2012 at 12:15 PM, Matt Topper <
|
@jancel do you happen to have the project you're referring to on github? I'm getting an " undefined local variable or method 'f' " with your example but could probably figure it out with a code example |
Sorry, I don't. Here's my form block though: form do |f| On Sat, Mar 17, 2012 at 2:45 PM, Matt Topper <
|
@jancel Mine works on a form as well, its when I'm using the collection as part of a filter like on a show or index page that I'm getting the error |
Ok, may want to move the question over to google groups where we can get more visibility. I'm not sure I've seen a need for this yet, so I'm unfamiliar with using select drop downs in index/show methods. |
@topperge This should be fixed by placing this in the user model
|
scope_to :current_user
is set inActiveAdmin.register
If I set a filter for an association to filter
:folder, :as => :select
it will callFolder.all
.If I try to set
filter :folder, :as => :select, :collection => current_user.folders.all
rails fails with acurrent_user not found
error.if scope is set the filter method should scope the association to the current_users objects.
The text was updated successfully, but these errors were encountered: