Hobo Permissions -- Read only fields in edit forms

22 views
Skip to first unread message

Gert Thiel

unread,
Oct 23, 2008, 8:02:01 AM10/23/08
to Hobo Users
Hello fellow Hobo addicts ;-)

I added a bunch of methods related to Hobo permissions and were able
to restrict the users who may edit a model.

Beyond that I need an edit form that restricts the field which an user
is allowd to edit (done!) but still shows some of the others field
(readonly).

Sadly Hobo removes any field which the user can not edit/update from
the edit form. But I need some of these field still presented readable
only in such forms. E.g. a description field.

Can you help me?

Regards,

Gert Thiel

Owen Dall

unread,
Oct 23, 2008, 5:58:12 PM10/23/08
to hobo...@googlegroups.com, t...@tomlocke.com
That is n important enhancement which I think Tom is working on...

Gert Thiel

unread,
Oct 24, 2008, 3:57:11 AM10/24/08
to Hobo Users
Well, I need this "yesterday". Until Sunday in fact.

On Oct 23, 11:58 pm, "Owen Dall" <owen.d...@gmail.com> wrote:
> That is n important enhancement which I think Tom is working on...
>

Gert Thiel

unread,
Oct 24, 2008, 4:11:56 AM10/24/08
to Hobo Users
Hobo considers all fields of an updateable model to be updateable as
well until I restrict that using only_changed_fields?
(new, :allowedfield1, :allowedfield2 …), field_editable_by? or by
other related methods.

Just for he sake of clean conventions I expect that every field that
is viewabale in a show form is still presented readonly if it is not
editable/updateable.

Last but not least I should be able to restrict the viewability by
methods like field_viewable_by?.

Gert Thiel

unread,
Oct 24, 2008, 8:35:59 AM10/24/08
to Hobo Users
Seriously, this issue gets me into trouble.

Tom, can you tell me when you will work on this? If you have no time
to do this soon, can you give me hints what of Hobo I could monkey
patch to help myself?

Regards and lots of "Sorry" for being so demanding,

Gert Thiel

Tom Locke

unread,
Oct 24, 2008, 8:49:10 AM10/24/08
to hobo...@googlegroups.com
Here's a modified version of <field-list> that takes a show-non-
editable attribute

<def tag="field-list" attrs="tag, show-non-editable">
<% tag ||= scope.in_form ? "input" : "view" %>
<labelled-item-list merge-attrs="&attributes -
attrs_for(:with_fields)">
<with-fields merge-attrs="&attributes & attrs_for(:with_fields)"><
% field_name = this_field_name %>
<labelled-item unless="&tag == 'input' && !can_edit? && !
show_non_editable">
<item-label param="#{this_field.to_s.sub('?', '')}-label"
unless="&field_name.blank?">
<do param="label"><%= field_name %></do>
</item-label>
<item-value param="#{this_field.to_s.sub('?', '')}-view"
colspan="&2 if field_name.blank?">
<do param="view"><call-tag tag="&tag"
param="#{this_field.to_s.sub('?', '')}-tag"/></do>
<div param="input-help" if="&tag.to_sym == :input && !
this_field_help.blank?"><%= this_field_help %></div>
</item-value>
</labelled-item>
</with-fields>
</labelled-item-list>
</def>


e.g. on an edit page

<edit-page>
<form:><field-list: show-non-editable/></form:>
</edit-page>

(not tested!)

Tom

Gert Thiel

unread,
Oct 24, 2008, 8:57:47 AM10/24/08
to Hobo Users
Thank you. Will try that right now ;-)

Tom Locke

unread,
Oct 24, 2008, 8:58:40 AM10/24/08
to hobo...@googlegroups.com
That change is pushed now.

Tom

Gert Thiel

unread,
Oct 24, 2008, 9:08:27 AM10/24/08
to Hobo Users
It added the <def tag="field-list" attrs="tag, show-non-editable"> ...
</dev> into my application.dryml and updated edit.dryml as well.

I get an undefined method `this_field_name' for #<ActionView::Base:
0x37615f8> error. The trace points to <% field_name = this_field_name
%> as the source of trouble.

Any idea?

Addendum: I use Hobo 0.8.3.

Thanks a lot, Tom, for your instant support!

Regards,

Gert Thiel

Gert Thiel

unread,
Oct 24, 2008, 9:11:49 AM10/24/08
to Hobo Users
Just read your commit http://github.com/tablatom/hobo/commit/4b9556a0d4d46e2987e38a418f7a7b2b1d46b152

I will try monkey patching hobo/taglibs/rapid_core.dryml

Sorry, I did not understand which file I had to monkey patch or update.

Tom Locke

unread,
Oct 24, 2008, 9:13:18 AM10/24/08
to hobo...@googlegroups.com
> Sorry, I did not understand which file I had to monkey patch or
> update.

Adding it to application.dryml would be fine. Maybe some funny stuff
happened with line-breaks when I pasted it in the email?

Tom

Gert Thiel

unread,
Oct 24, 2008, 9:25:48 AM10/24/08
to Hobo Users
Using Hobo 0.8.3 I updated using hobo/taglibs/rapid.dryml @ lines
13 .. 27:

<def tag="field-list" attrs="tag, show-non-editable">
<% tag ||= scope.in_form ? "input" : "view" %>
<labelled-item-list merge-attrs="&attributes -
attrs_for(:with_fields)">
<with-fields merge-attrs="&attributes & attrs_for(:with_fields)">
<labelled-item unless="&tag == 'input' && !can_edit? && !
show_non_editable">
<item-label param="#{this_field.to_s.sub('?', '')}-label">
<do param="label"><%= this_field.to_s.titleize %></do>
</item-label>
<item-value param="#{this_field.to_s.sub('?', '')}-view">
<do param="view"><call-tag tag="&tag"
param="#{this_field.to_s.sub('?', '')}-tag"/></do>
</item-value>
</labelled-item>
</with-fields>
</labelled-item-list>
</def>

The modification is effectively the same.

That works at the first glance.

Gert Thiel

unread,
Oct 24, 2008, 9:28:18 AM10/24/08
to Hobo Users
Instead monkey patching hobo/taglibs/rapid.dryml adding the same code
to application.dryml works as well. Just tested both.

Gert Thiel

unread,
Oct 24, 2008, 9:49:43 AM10/24/08
to Hobo Users
After some more testing* I can declare this issue SOLVED.

Thank you very much, Tom, for your prompt support. You simply saved my
day (and weekend).

Regards,

Gert Thiel

* I tested the solution using Hobo 0.8.3 only.
Reply all
Reply to author
Forward
0 new messages