Controller design for app with different user types


#1

Hi,

I am trying to implement an application where there are different types
of users (about 5-6). The privileges of each type of user varies pretty
drastically and hence when each logs into the application, each will
have his own home page and set of things that he can do that differs
from other types of users.

Since the views would also change (or rather look totally different) for
each of them, I thought it would be better to have totally different
controllers and actions based on the type of users. I have been reading
about how to design this kind of an scenario but have not been able to
stumble upon a sound design as of now. There was one reference to
namespaced controllers… do you think this would be the best approach
for the situation in hand. If you know of any tutorial, that would be
useful.

Plus, I see that a lot of my actions don’t fall just within the CRUD
actions, I need more… can some lead me to design tips or tutorials for
such a thing too? Any help is appreciated. Thanks in advance!

-J


#2

Roles are fairly well-documented in the blogosphere, even if the roles
are entirely orthogonal. Here are a few readings to get you started:

http://metautonomo.us/2008/09/30/easy-role-based-authorization/
http://railsforum.com/viewtopic.php?id=1579
http://www.vaporbase.com/postings/Authorization_in_Rails

Are the views actually that different? It may be just that the content
of the profiles is determined by the user’s role(s), but the template
can remain the same for all roles.


#3

Hey Eric,

Thanks a lot for the links. The first one was really useful as that
addresses overlapping permissions for various roles and my application,
I suppose, falls in that domain.

As for the views, yes they are radically different for each type of
user. The app brings different types of users together and hence
generally they all don’t interact with the same set of models. There are
some common models that they all interact with but many models are
specific to the user type. Hence the views look different for each user
type. That’s why I was wondering if I could use something like the
following:

map.namespace :client do |client|
client.resources :projects, :preferences
client.resources :forums do |forums|
forums.resources :topics
end
end

map.namespace :employee do |employee|
employee.resources :profile, :calendar
employee.resources :forums do |forums|
forums.resources :topics
end
end

…and so on for each type of user. The above code is just an example,
I’ve not used the exact project details.

I’ve used :forums in both user types to just give an example for shared
models but even in those the view would look very different for each
user type.

Can someone tell me if I am on the right path?

Thanks!
-J