I'm working on a User object that will support
Groups and Groups-to-Roles mappings.

I modeled it a bit and come up with this model:
(I use Coad's constraints notion, putting constraints with the item the constrain)

User -n------n- Role
   | n
   | 1
GroupRoleItem  -1----- n-  Role (*same as the other role above)
   | 1 
   | n

To make it as simple as possible I whan to keep 
Group and GroupRoleItem in a dictionary inside the User instance.
E.g. {'groupname': ('rolename','rolename',), ... }

In my LM implementation I want to store GroupRoleItems in a SQL table
and Groups in another SQL table (which records awailable groups).

The LoginUser object should have a attribute grouproles_dict that gets
its data from the GroupRoleItems table.

Here's some code:
class GroupLoginUser(LoginUser):
    def getGroupRoles(self):
        # group_list contains the following brains from the LoginManager 
(Skinscript/SQL method):
        # (brains.username)
        # brains.rolename
        # brains.groupname
        groups = ()
        grouproles = {}
        if self.group_list:
            for g in self.group_list:
                if g.groupname in groups:
                    grouproles[g.groupname] = [g.rolename]
                    groups = groups + (g.groupname,)
        return grouproles

The GroupLoginUser is not stored persitently in my implementation,
but I like to cache the grouproles for as long as possible. 
For example I'm planning a method "getGroups" in the GroupLoginUser
which could just return grouproles.keys().

So because GroupLoginUser is a virtual dataskin I'm not sure
where I should save the grouproles. In self._v_grouproles or
as a skinscripted attribute?
E.g. WITH self.getGroupRoles() COMPUTE grouproles = RESULT

I might be thinking wrong in the model as well, so any hints and tips
for corrections are welcome.

Johan Carlsson


Reply via email to