Rob,

Thanks for your reply. I looked through what you wrote, and it was very
helpful. I am slowly starting to understand the greatness of plone 3,
but it will take some more time...;-)

My remember product is an old style plone 2.5 product, so this is what I
did:

1. Created a String field called team_affiliation that has a vocabulary
of values in my WolvesMember class (the one like your example)
2. Created two dictionaries that translate from team_affiliation values
to roles and groups
3. Added this method to my WolvesMember class:

    def setTeam_affiliation(self, value):
        if value != '':
            self.Schema()['team_affiliation'].set(self, value)
            self.setRoles(ROLES_TEAM_AFFILIATION[value])
            self.setGroups(GROUPS_TEAM_AFFILIATION[value])

It all works!

You may have noticed the "if value == ''" statement. Well, I found that
I was getting an error each time I added a new member. However, plone
would continue to chug along and set the roles and groups correctly. The
error was from the dictionaries because value = ''. I guess this method
is called once before the team_affiliation value is ready, so the value
argument passed to it is an empty string.

My explanation is based on wild guessing, and not any rigorous
analysis. 

Perhaps you can shed some light on what is actually happening?

Also, when I look in membrane_tool, search the catalog, and select one
of the WolvesMembers I have created, I find that the roles and groups
are set correctly (yeah!!). However, there is a field called GroupIds
that is blank (empty). Is that field important? 

Should I be worried about this field, or is it Miller Time and I can
take the weekend off and enjoy my daughter's softball tournament??? ;-)
I probably will anyway; just trying to gage the level of stress I should
feel about this issue come Monday morning....

My next project is to adapt this for another project and do it all in a
plone 3 fashion - interfaces, adapters, browser views, etc. So your
explanation of groups and how to make the new adapters will come in
handy.

Just when I thought it was safe to venture out into the night, plone 3
comes alone, Martin writes a book that makes Mckay's book obsolete (and
I just finished memorizing that book)! Well, two steps back and one step
forward is still progress in the world of plone. Somedays, I wish for
the "simplicity" of Java Beans, JSPs, Servlets, and.....shudder,
EJB. ;-)

Cheers!

Mark

On Thu, 2008-09-11 at 23:10 -0700, Rob Miller wrote:
> Mark Phillips wrote:
> > I created my own remember object patterned after sampleremember. In the
> > schema is a string field that the user selects a value from a list.
> > These values happen to be the names of the various groups defined in the
> > site. How (and where) do I write the code to add this user to the group
> > he/she has selected in this field?
> 
> well, if you named the field "groups" and used AT's default "getGroups" for 
> the accessor then it should Just Work(tm).  here are some details about how 
> it 
> works, though:
> 
> Membrane registers a groups plugin that uses the membrane_tool to find any 
> content in the site that can be adapted to the IMembraneUserGroups interface. 
>   Remember's BaseMember class implements the IRememberGroupsProvider 
> interface, and Remember registers an adapter from IRememberGroupsProvider -> 
> IMembraneUserGroups.  this adapter is trivial, it simply calls 'getGroups' on 
> the context (i.e. the adapted Member object) and returns the results:
> 
> http://tinyurl.com/3g7ngw
> 
> if your custom member class inherits from BaseMember then it probably still 
> implements the IRememberGroupProvider interface, and so the 'groups' field 
> value would be checked.
> 
> if you want to use a different fieldname, you can create an 
> IYourOwnCustomGroupsProvider interface, subclassing IRememberGroupsProvider, 
> and make sure your member class implements the interface.  then register a 
> different adapter from IYourOwnCustomGroupsProvider -> IMembraneUserGroups. 
> this adapter registration will beat the other one, since yours will be a more 
> specific interface, and you can retrieve the set of groups from your custom 
> field.
> 
> > Would I do this in the sampleremember.py code?
> 
> not really, see above.
> 
> > How do I add a user to a group?
> 
> by using the Users/Groups configlet in Plone's control panel, or by setting 
> the value of the field directly on the member object (either UI or 
> programmatically).
> 
> > If the user is not approved in the workflow, do I have to do
> > something special in the code to "remove" him/her from the groups
> > selected, or does that just happen magically?
> 
> i just checked and it looks like a user _will_ still show up as "in" the 
> group 
>   when a Manager uses Plone's control panel interface, even if his account is 
> in one of the inactive workflow states.  this could maybe be considered a UI 
> bug, though, b/c if a user is in an inactive workflow state, then he can't 
> log 
> in at all... the group membership won't do him any good.
> 
> > Or should I add the user to the selected groups in a script on a
> > workflow transition when the user is approved? How would I code this
> > scenario?
> 
> probably a better idea would be to either improve the adapter i linked to 
> above, or to write your own custom adapter, so that it checks to see if the 
> member is in an active state before returning the value of the groups field.
> 
> -r
> 
> 
> --
> Archive: 
> http://www.openplans.org/projects/remember/lists/remember/archive/2008/09/1221199822945
> To unsubscribe send an email with subject "unsubscribe" to [EMAIL PROTECTED]  
> Please contact [EMAIL PROTECTED] for questions.
> 



--
Archive: 
http://www.openplans.org/projects/remember/lists/remember/archive/2008/09/1221265862997
To unsubscribe send an email with subject "unsubscribe" to [EMAIL PROTECTED]  
Please contact [EMAIL PROTECTED] for questions.

Reply via email to