Mercurial > p > roundup > code
diff roundup/mailgw.py @ 4306:966592263fb8
Clean up all the places where role processing occurs.
This is now in a central place in hyperdb.Class and is used
consistently throughout. This also means now a template can override
the way role processing occurs (e.g. for elaborate permission
schemes). Thanks to intevation for funding the change.
Note: On first glance the hyperdb.Class may not be the ideal place for
role processing. On second thought: Roles may appear in other classes,
too (e.g., a user_group or similar) which then don't need to reinvent
the wheel. And I didn't want to introduce a separate UserClass (as is
the case for the HTML classes) due to compatibility issues with existing
schema.py out there.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Tue, 15 Dec 2009 15:11:27 +0000 |
| parents | d47245c2530a |
| children | 38265325492a |
line wrap: on
line diff
--- a/roundup/mailgw.py Mon Dec 14 21:48:51 2009 +0000 +++ b/roundup/mailgw.py Tue Dec 15 15:11:27 2009 +0000 @@ -86,6 +86,7 @@ from roundup import configuration, hyperdb, date, password, rfc2822, exceptions from roundup.mailer import Mailer, MessageSendError from roundup.i18n import _ +from roundup.hyperdb import iter_roles try: import pyme, pyme.core, pyme.gpgme @@ -163,24 +164,6 @@ yield sig sig = sig.next - -def iter_roles(roles): - ''' handle the text processing of turning the roles list - into something python can use more easily - ''' - for role in [x.lower().strip() for x in roles.split(',')]: - yield role - -def user_has_role(db, userid, role_list): - ''' see if the given user has any roles that appear - in the role_list - ''' - for role in iter_roles(db.user.get(userid, 'roles')): - if role in iter_roles(role_list): - return True - return False - - def check_pgp_sigs(sig, gpgctx, author): ''' Theoretically a PGP message can have several signatures. GPGME returns status on all signatures in a linked list. Walk that @@ -1256,8 +1239,8 @@ # or we will skip PGP processing def pgp_role(): if self.instance.config.PGP_ROLES: - return user_has_role(self.db, author, - self.instance.config.PGP_ROLES) + return self.db.user.has_role(author, + iter_roles(self.instance.config.PGP_ROLES)) else: return True
