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

Allow custom scope for dashboard resource #910

Merged
merged 2 commits into from
Jun 20, 2017

Conversation

bobf
Copy link
Contributor

@bobf bobf commented Jun 13, 2017

end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at block body end.

end
class UserDashboard < Administrate::BaseDashboard
def resource_scope
User.my_scope

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

end
end
resolver = Administrate::ResourceResolver.new("admin/posts")
expect(resolver.resource_scope).to eq('a resource scope')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

class Post; end
class PostDashboard
def resource_scope
'a resource scope'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
end

it 'uses defined scope when present' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
class PostDashboard; end
resolver = Administrate::ResourceResolver.new("admin/posts")
expect(resolver.resource_scope).to eq('default scope')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

begin
class Post
def self.default_scoped
'default scope'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@@ -60,6 +60,38 @@ module Blog; class Post; end; end
end
end

describe '#resource_scope' do
it 'defaults to model default scope when no override defined' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@@ -60,6 +60,38 @@ module Blog; class Post; end; end
end
end

describe '#resource_scope' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@bobf bobf mentioned this pull request Jun 14, 2017
@nickcharlton nickcharlton merged commit c660ecd into thoughtbot:master Jun 20, 2017
@nickcharlton
Copy link
Member

Thanks for this! I didn't have any specific comments, so I've merged it.

@bobf
Copy link
Contributor Author

bobf commented Jun 20, 2017

@nickcharlton Ah, bad timing ! A colleague of mine has been working on what I consider to be a better implementation. He has moved the scoping into the controller, so you can override a method in each controller to provide the relevant scope. This allows using things like properties of current_user to determine the scope. Using the solution I implemented, I had to do some nasty hacks to make current_user available in the Dashboard.

I was actually going to close this PR as I think my colleague's implementation is superior. He should have a PR soon. What do you think is the best way to proceed ?

@bobf
Copy link
Contributor Author

bobf commented Jun 20, 2017

@nickcharlton Just discussed with my colleague - he's going to submit a new PR that reverts my changes and adds his changes instead. I'm optimistic you'll agree that it's a better implementation as it allows the controller to decide the scope, optionally basing it on the request, which I think is much cleaner.

damau pushed a commit to damau/administrate-1 that referenced this pull request Jun 20, 2017
This reverts commit c660ecd.
We feel scoping should occur in the controller which is more
consistent with rails and find_resource customisation
@nickcharlton
Copy link
Member

Oh dammit!

I look forward to the new PR!

@bobf
Copy link
Contributor Author

bobf commented Jun 20, 2017

@nickcharlton Here ya go: #914

We're very keen to see this merged so if you have any feedback just let us know and we will act on it ASAP.

Thanks for getting back to us on this !

nickcharlton pushed a commit that referenced this pull request Jul 4, 2017
* Revert "Allow custom scope for dashboard resource (#910)"

This reverts commit c660ecd.
We feel scoping should occur in the controller which is more
consistent with rails and find_resource customisation

* Scoping for the index action should happen in the controller.

It's standard behaviour for scoping to happen in a controller.
Also makes it more consistent with find_resource.
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