[Zope-CMF] Exposing the document owner's role
Lucas Hofman
lucas.hofman@pgs.com
Mon, 13 Aug 2001 14:45:35 +0200
On Friday 10 August 2001 16:13, norbert@attira.com wrote:
>
> Thanks Lucas, your snippet makes a lot of sense, except I somehow
> can't get to the getFullName() and getRoles() attributes.
>
Oops, you are right. I created a membershiptool that contains:
def getRoles (self, id=None):
"""Returns a member's roles."""
# print "id ",id
member = None
if id is None:
member = self.getAuthenticatedMember()
if not hasattr(member, 'getMemberId'):
# not logged in
return ('Anonymous',)
else:
member = self.getMemberById(id)
if hasattr(getattr(member, 'aq_base', member), 'getUser'):
user = member.getUser()
else:
user = member
# print "roles ", user.getRoles()
return user.getRoles()
and
security.declarePublic('getFullName')
def getFullName(self, id=None):
"""Returns a member's full name"""
if id is None:
member = self.getAuthenticatedMember()
else:
member = self.getMemberById(id)
fullName = getattr(member, 'first_name','') + " " +
getattr(member,'last_name','')
if fullName != "":
return fullName
else:
return id # fall back in case first/last name not has
been set
--
Lucas Hofman
PGS Research work: +47 67514059
PO Box 354 fax: +47 67526640
N-1326 Lysaker, Norway home: +47 67581373