Oh no - as should have expected - the "graphical" part got completely
messed up.. lol..
sorry about that..
ammm.. will try to think of a better way to put this thing..
> > Thank you Colin!
> >> I can't say I fully understand your requirement (I have not much
> >> time
> >> at the moment), but I am sure that to have different models for
> >> GroupAUsers, GroupBUsers and so on cannot be the right way to go. I
> >> would suggest starting with Users and Groups. Then you have a
> >> number
> >> of groups (A, B etc). Then User belongs_to group and Group has_many
> >> Users. (Is that right, a user can only be in one group).
> > Actually - a User can belong to several groups.
> In that case I don't see how your original scheme would work, as a
> user would have to be a GroupAUser and a GroupBUser.
I was trying to "solve" this with the very ugly lines of
User
has_many :group_a_users
has_many :group_b_users
has_many :group_c_users
has_many :group_d_users
As you suggested - thinking of them as Roles rather than Groups of
Users, it seems a bit better.
Yet if changing the terminology - there are probably better solutions
as you already pointed out
> >> Try starting with that approach and see how far you can get and come
> >> back if you can't work it out.
> > The reason I was thinking of making each group a separate model is
> > they are all indeed users,
> > but a user should see different tabs (and of course has different
> > permissions, specifically on other users from other groups
> > hierarchically "below" this current user's group) relevant to his/her
> > group..
> Don't worry about what you want on screen at this poiint. Think about
> the objects and relationships in the underlying problem in the real
> world first. If you get that modeling right then you will be on the
> right track. Talk about the real world problem and identify the nouns
> that use, these are then the candidates for model types.
> > I think it can be thought of as a hierarchy of managers in a company,
> > all users but having different additional attributes and associated
> > models..
> In that case I think roles might be a better way to think about it
> than groups. A user then has_many roles, but a role has_many users
> also so you will probably need a join table (users_roles) to link
> them. Then when working out the hierarchy for display you can use the
> roles that a user has to determine what he can see and do.
> Additionally you talk about a hierarchy of groups, is this really a
> hierarchy of just a variable set of permissions that are implied by a
> particular role?
Roles indeed
After your previous response I started rethinking this problem and
actually you helped me a lot (I should mention I thank radhames as
well for bringing up the self referential associations) "letting go"
of what my mind seemed to be a bit fixed on..
Anyway - I have mainly Users. These Users have many Roles (or - there
are several "types" of Users).
Will try to illustrate this graphically for a moment, seems it might
help:
===== =====
RoleAUsers |
RoleA> >RoleA>
===== =====
/
> \ \ / | \
/
> \ \ / | \
=====
===== ===== ===== ===== =====
RoleBUsers |RoleB| |RoleB| |
RoleB> >RoleB> > > > >
=====
===== ===== ===== ===== =====
/ | \
\ | | \ / | \ / | \ / | \ /
> \
/ | \
\ | | \ / | \ / | \ / | \ /
> \
/ | \
\ | | \ / \
===== =====
===== ===== ===== =====
RoleCUsers |RoleC| |RoleC| |RoleC| |
RoleC> >RoleC> >RoleC>
====== ===== ======
====== ===== =====
/ | /
> \ | \ | \ / | \
/ | /
> \ | \ | \ / | \
/ | /
> \ | \ | \ /----/ | \
/ | /
> \| \ / \ / | \
===== ===== ===== =====
===== ===== ===== ===== =====
RoleDUsers |RoleD| | | | |
> > > > >RoleD> > > > >
> >
===== ===== ===== =====
===== ===== ===== ===== =====
And so on...
(Of course - there are more Resources like "Location", "Attachments"
and others, but I illustrated the core of this hierarchical system,
which also presents most of the difficulty in my case)
This more "graphical" illustration was not such a great idea to put
this way, hope most of the people viewing it will be able to
understand what I was trying to demonstrate here..
I should also mention - and currently it seems more relevant to Users
of RoleD - they can belong to several User with RoleC assigned (and
might have a bit different information assigned to them by the
inserting RoleC User).. though a guess different DB entries for each
such association should be able to deal with such "doubling"/
overlapping or lack of it..
===============
So What I was illustrating here - again:
each User has many Roles (or - belongs to several 'types' of users),
which directly affects his/her place in this hierarchy. Of course, If
a user plays both "RoleA" and "RoleD" (have no better helpful names
for these, otherwise I would have used them to make this discussion
nicer) - I want him/her to be able to view the information in two
different ways, but as you suggested - this is not relevant right now
for mapping the basics (though feel I should keep that somewhere in my
mind..)
With what you suggested - a User has many Roles
and a Role has many Users (plus the join table)
so - each User is connected to other Users.
I want each User to be able to not only see which Roles they have but
also - be able to see and access (nature of accessing - whether read-
only or 'manage' will be handled using an Authorization system) all
Users "below" (probably manage) and "above" (read-only), where "below"
and "above" refer to the "user roles" as described in my "graphical"
explanation.
In case I do - a User also has many Users (and belongs to many Users),
I still need a way to be able to do something like the following:
@current_user.RoleBUsers.create(...)
[if current_user has permission to do it, i.e, either an Admin [OH.. I
probably need to put the Admin somewhere here as well..] or has RoleA
assigned to him/her]
I guess this is why I began to think of "groups" - because wanted to
gather all Users in a particular group as well and access their
hierarchical "parents" and "children"..
Now I'm thinking - maybe I should use a User self-referential
association for each Role-to-Role association (A-B, B-C, C-D), though
right now somehow it seems more of a mess but maybe I should just get
to the idea and play with it some more.. I also want a user to be able
to see more than 1 level above or below...
OK.
Sorry for lengthy email.. hopefully it's viewable..
Appreciate the answers very much, as mentioned before - I find it
irreplaceable talking to others while learning and trying to figure
out things and you've been very helpful. Thank you.
--
Allison
> Colin
> > I do need to think more about the direction you offered. Logically,
> > even while apparently I wasn't clear enough, your way of putting this
> > together sounds (much) better..
> > I'm just not sure if I have a Group model and then I guess - several
> > groups inheriting from it.. oh.. think I making the same mistake over
> > again.. but I still should somehow be able to differentiate between a
> > user of a specific type (or that belongs to a specific group) to a
> > user who belongs to a different group (or is a different type of
> > user,
> > doesn't seem that much of a difference at first glance..), plus
> > ideally allow a user be of several types, or somehow find a way
> > around
> > this (was initially thinking of adding another column to the User
> > model with, say, a sum based on the 'types' this current user is,
> > but
> > that adds some serious holes security-wise, unless I find some ways
> > to
> > protect this column (less experienced with securing the DB, which I
> > need look into as well, but probably there's a better solution to
> > this
> > as well, and hopefully much simpler).
> > Again, thank you.
> > --
> > Allison
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Ruby on Rails:
...
read more »
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.