61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
# w.c.s. - web application for online forms
|
|
# Copyright (C) 2005-2010 Entr'ouvert
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from quixote import get_publisher
|
|
|
|
from qommon.storage import StorableObject
|
|
import qommon.misc
|
|
|
|
class Role(StorableObject):
|
|
_names = 'roles'
|
|
name = None
|
|
details = None
|
|
emails = None
|
|
emails_to_members = False
|
|
allows_backoffice_access = True
|
|
|
|
def __init__(self, name = None):
|
|
StorableObject.__init__(self)
|
|
self.name = name
|
|
|
|
def get_emails(self):
|
|
emails = self.emails or []
|
|
if not self.emails_to_members:
|
|
return emails
|
|
users_with_roles = get_publisher().user_class.get_users_with_role(self.id)
|
|
emails.extend([x.email for x in users_with_roles if x.email])
|
|
return emails
|
|
|
|
def get_substitution_variables(self, prefix=''):
|
|
data = {}
|
|
data[prefix + 'name'] = self.name
|
|
if self.emails and not self.emails_to_members:
|
|
data[prefix + 'emails'] = ', '.join(self.emails)
|
|
return data
|
|
|
|
|
|
def logged_users_role():
|
|
volatile_role = Role.volatile()
|
|
volatile_role.id = 'logged-users'
|
|
volatile_role.name = _('Logged Users')
|
|
return volatile_role
|
|
|
|
|
|
def get_user_roles():
|
|
t = sorted([(qommon.misc.simplify(x.name), x.id, x.name) for x in Role.select()])
|
|
return [x[1:] for x in t]
|
|
|