# How to limit some HTML blocks for a certain role/permission?

**URL:** <https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425>\
**Category:** Engines\
**Created:** [March 28, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425 "2006-03-28T15:11:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 28, 2006, 3:11pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/1 "2006-03-28T15:11:59Z")

</div>

Hi

```
I have a small problem here. I have few roles, eg. Client User and

```

Client Manager. I would like to let view both of them a certain View,  
but normal Client User shall not see any blocks of HTML code like  
payment lists etc. on a page. How can I achieve this?

Piotr

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 28, 2006, 4:06pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/2 "2006-03-28T16:06:12Z")

</div>

You can use something like this in a view:

\<% if current\_user.roles.include?(Role.find\_by\_name(“Client Manager”) do  
%\>

\<% end %\>

Would that be ok? This presumes that you’re using the User Engine…

- james

On 3/28/06, Piotr U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> engine-users mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org)

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 28, 2006, 4:30pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/3 "2006-03-28T16:30:41Z")

</div>

James A. napisaÅ?(a):

> You can use something like this in a view:
> 
> \<% if current\_user.roles.include?(Role.find\_by\_name(“Client Manager”) do %\>
> 
> \<% end %\>
> 
> Would that be ok? This presumes that you’re using the User Engine…

Yeah, I have figured it out. But still, it won’t work as expected.

My application shall grant access to ‘our’ users, and our client’s  
users.

So our users arent assigned to Client roles, but instead like Helpdesk  
Users or whatever.

Here, if a certain user (or admin) arent assigned Client Manager role  
won’t see the block aswell… Which is not the way it should be.

Any solution? 🙂

Peter

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 29, 2006, 4:54am UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/4 "2006-03-29T04:54:01Z")

</div>

Sure… a hack of sorts. Just make some permissions for “fake”  
controllers & actions (that need not exist/do anything useful). Then  
assign these permissions to the roles you want and use the authorized?  
method. This gives arbitrarily fine-grained control:

\<% if authorized?(:controller =\>‘htmlacesscheck’ :action =\>  
‘thisbitofhtml’) %\>  
  
\<% end %\>

Piotr U. wrote:

> > Yeah, I have figured it out. But still, it won’t work as expected.
> 
> My application shall grant access to ‘our’ users, and our client’s  
> users.
> 
> So our users arent assigned to Client roles, but instead like Helpdesk  
> Users or whatever.
> 
> Here, if a certain user (or admin) arent assigned Client Manager role  
> won’t see the block aswell… Which is not the way it should be.
> 
> Any solution? 🙂
> 
> Peter

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 29, 2006, 9:36am UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/5 "2006-03-29T09:36:49Z")

</div>

Jonathan Bloch napisaÅ?(a):

> 

Oh thanks. But it’s nasty! ;]

Peter

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 29, 2006, 9:45am UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/6 "2006-03-29T09:45:19Z")

</div>

If a set of users all need to see the same chunk of HTML, they should  
share the same role. Importantly, though, bear in mind that users can  
have MANY roles. So define your roles in a sensible way which reflects  
the fine granularity of what information they should/should not see,  
and use these presence/absence of those fine-grained roles in your  
conditional statements.

- james

On 3/29/06, Piotr U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> [http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org](http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-engines.org)

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 29, 2006, 12:54pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/7 "2006-03-29T12:54:34Z")

</div>

Perhaps roles are not the right metaphor for the kind of discriminant  
functionality or display that you need. Good luck.

- james

On 3/29/06, Piotr U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [March 29, 2006, 12:39pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/8 "2006-03-29T12:39:55Z")

</div>

James A. napisa³(a):

> If a set of users all need to see the same chunk of HTML, they should  
> share the same role. Importantly, though, bear in mind that users can  
> have MANY roles. So define your roles in a sensible way which reflects  
> the fine granularity of what information they should/should not see,  
> and use these presence/absence of those fine-grained roles in your  
> conditional statements.
> 
> - james

Yes I know, but it would be somewhat difficult to administer all the  
users (for example, we have about 20 internal users and 300+ external  
ones). Setting many different roles for eg. every variable of html code  
chunks can be annoying. I am not sure, but maybe ActiveRBAC would let  
this be less complicated.

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [August 30, 2006, 7:59pm UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/9 "2006-08-30T19:59:52Z")

</div>

Hello all,

Has anyone tried to use the UserEngine alongside the upload progress  
plugin? We have everything working correctly for both of those, but  
we’re finding that when a user is logged in, the ajax requests used  
in the upload plugin get hung up. They never return anything, and I  
have to kill off the fcgi processes it kicks up manually.

The strange thing is that if the user logs out, everything works fine.

I’ve tried changing the protect? method of the LoginEngine’s  
user\_controller.rb so that ostensibly the controller handling those  
ajax requests isn’t protected, but that still doesn’t seem to make  
any difference.

Anyone else have this experience?

* * *

```
Shane Iseminger
Principal
Ethos Media Creative Group
removed_email_address@domain.invalid
719.589.2800
```

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [August 31, 2006, 12:28am UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/10 "2006-08-31T00:28:26Z")

</div>

On Wed, 30 Aug 2006 11:58:13 -0600, Shane Iseminger wrote:

> Has anyone tried to use the UserEngine alongside the upload progress  
> plugin? We have everything working correctly for both of those, but  
> we’re finding that when a user is logged in, the ajax requests used  
> in the upload plugin get hung up. They never return anything, and I  
> have to kill off the fcgi processes it kicks up manually.

I had them both working in an app that no longer exists… sorry that  
doesn’t give you much detail, but at least you know they CAN work. No  
idea  
what’s different about your situation.

Jay L.

---

<div class="post-metadata">

**Author:** ![lopmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/258eb7/32.png) [@lopmx](https://www.ruby-forum.com/u/lopmx)\
**Post date:** [August 31, 2006, 4:10am UTC](https://www.ruby-forum.com/t/how-to-limit-some-html-blocks-for-a-certain-role-permission/88425/11 "2006-08-31T04:10:45Z")

</div>

Thanks Jay,

After a lot of excruciating tracing and debugging, I deduced that  
part of the upload progress plugin is loading the session, but the  
Role model stored in it was undefined. So all it ended up requiring  
is the line

```
require 'roles.rb'

```

in multipart\_progress.rb, right before it loads the session. By the  
way, this problem shows itself in the logs as the following error,  
which someone (I believe here) had tried to solve a while ago (I ran  
across it in Google):

```
"Exception during setup of read_multipart_with_progress: undefined

```

class/module Role"

– Shane

On Aug 30, 2006, at 4:27 PM, Jay L. wrote:

> No idea  
> what’s different about your situation.
> 
> Jay L.
> 
> * * *
> 
> engine-users mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-](http://lists.rails-engines.org/listinfo.cgi/engine-users-rails-)  
> [engines.org](http://engines.org)

* * *

```
Shane Iseminger
Principal
Ethos Media Creative Group
removed_email_address@domain.invalid
719.589.2800

```
