objects in relation not shown unless relation loaded
Reported by Bryan Larsen | September 16th, 2011 @ 10:06 PM
What works:
def index
Package.where(...).all
end
What doesn't:
def index
Package.where(...)
end
Why this doesn't break for everybody:
def view_permitted?(field)
!new_record? # to oversimplify
end
Hobo is checking the permissions on a new object rather than on the actual object.
This bug is probably Hobo 1.3 specific.
Comments and changes to this ticket
-
Bryan Larsen September 16th, 2011 @ 10:07 PM
- no changes were found...
-
Bryan Larsen September 16th, 2011 @ 10:10 PM
Granted, view_permitted should handle the new_record scenario, because Hobo does this sort of thing in other cases for more legitimate reasons.
-
Matt Jones September 20th, 2011 @ 04:20 PM
(from [a450d53d76413d6c47616a13309ce873053b34f7]) [#964] [#726] fix handling of can_view when repeating over an array https://github.com/tablatom/hobo/commit/a450d53d76413d6c47616a13309...
-
Matt Jones September 20th, 2011 @ 04:24 PM
- State changed from new to resolved
On further digging, this was the same issue as #726 - long story short, setting
this_field
to the current (integer) index of the record was causingcan_view?
to feed permission requests to the array/relation instead of to the object.On a related note, does anybody actually USE the mechanism in question? I'm wondering if it might be more straightforward to replace that functionality with something more like the hash iterator's
this_key
(maybethis_index
?) rather than overloading the existing function... -
Tim Griffin September 20th, 2011 @ 04:49 PM
Hi Matt;
This bug arises from an anomaly I detected in my project. I'm not sure if I'm directly using the mechanism in question (a little too low-level for me at this point, but here is my original problem that perhaps sheds some light on how I was using this.
A statement such as this
@packages = Package.where("owner_id = #{current_user.id} OR (state = 'submitted' OR state = 'in_review' OR state = 'accepted')").apply_scopes(lto_scopes).paginate(:per_page => 15, :page => params[:page])
seems to render an empty table-plus for @packages.
But, if I add ".all" to the end, I get the desired result.
@packages = Package.where("owner_id = #{current_user.id} OR (state = 'submitted' OR state = 'in_review' OR state = 'accepted')").apply_scopes(lto_scopes).paginate(:per_page => 15, :page => params[:page]).all
If I remove the ".all" I added to force execution, I simply get the table header rendered with no rows, even though there is a correct count of objects listed above the table. I do not see an empty message, so I didn't think the table empty? test was failing.
Oddly, in the console, I get a listing of packages whether I tack on the ".all" method or not.
Hope that helps a little.
Tim -
Matt Jones September 20th, 2011 @ 05:41 PM
Thanks for the insight, Tim. I suspect the issue that you were hitting was the same one I ran into in #726, where attempting to check permissions on each row in the table-plus was instead trying to check permissions on the array. That would explain the
.all
behavior, as I believe that converts the relation (which can do the whole "create new object to check permissons" thing) into a plain Array (which can't).Can you verify that this no longer occurs with the patch I've added?
-
Tim Griffin September 22nd, 2011 @ 05:28 PM
Hi Matt;
Yes, I can confirm that your patch has resolved this issue.
I now longer need to append the ".all" method to have the table-plus populate. Right on - 4 less characters I have to type. Every little bit helps.
I note, however, that it remains necessary for me to include the ".all" method when creating a <filter-menu>:
<filter-menu model="title" param-name="community" options="&Community.all"/>
Without it, I get:
You must provide an "options" attribute, or set "activerecord.attributes.title.filter_menu.community.options" or "tags.filter_menu.community.options" to an Array or to an Array of Arrays in your locale file(s)
Does <filter-menu> differ from <table-plus> such that .all is necessary?
Tim
-
Matt Jones September 22nd, 2011 @ 06:48 PM
Actually, in this case it's more about
options
expecting something reasonably Array-ish. The bare constantCommunity
is definitely not an Array, whereasCommunity.all
is a Relation (which responds tois_a?(Array)
and will behave like one). Applying awhere
will also return a Relation.The issue with table-plus wasn't that it was failing to get the records, but that it was checking the permissions incorrectly and thus refusing to display any of them.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Tags
Referenced by
- 726 can_view? behaves oddly in a repeat context (from [a450d53d76413d6c47616a13309ce873053b34f7]) [#964] ...
- 964 objects in relation not shown unless relation loaded (from [a450d53d76413d6c47616a13309ce873053b34f7]) [#964] ...