def save_voters_userids(obj, event): if event.new_state == 'ongoing': obj.set_field_value('voters_mark_ongoing', find_role_userids(obj, ROLE_VOTER)) if event.new_state == 'closed': obj.set_field_value('voters_mark_closed', find_role_userids(obj, ROLE_VOTER))
def contact(self): """ Contact moderators of the meeting """ recipients = [] for userid in find_role_userids(self.context, ROLE_MODERATOR): user = self.api.get_user(userid) email = user.get_field_value('email') if email: recipients.append(email) if not recipients: for userid in find_authorized_userids(self.context, (MODERATE_MEETING, )): user = self.api.get_user(userid) email = user.get_field_value('email') if email: recipients.append(email) schema = createSchema('ContactSchema').bind(context=self.context, request=self.request, api=self.api) form = Form(schema, buttons=(button_send, )) self.api.register_form_resources(form) post = self.request.POST if self.request.method == 'POST': controls = post.items() try: appstruct = form.validate(controls) except ValidationFailure, e: self.response['form'] = e.render() return self.response if appstruct.get('email', None): sender = appstruct['email'] if self.api.user_profile: sender += " <%s>" % self.api.user_profile.title else: sender = None response = { 'api': self.api, 'meeting': self.context, 'name': appstruct['name'], 'email': appstruct['email'], 'subject': appstruct['subject'], 'message': appstruct['message'], } body_html = render('templates/email/help_contact.pt', response, request=self.request) subject = "[%s] %s" % (self.context.title, appstruct['subject']) send_email(subject, recipients, body_html, sender=sender, request=self.request) self.api.flash_messages.add(_(u"Message sent to the moderators")) url = self.request.resource_url(self.context) return HTTPFound(location=url)
def test_find_role_userids_other_context(self): root = self._fixture() from voteit.core.models.meeting import Meeting from voteit.core.models.user import User root['m'] = meeting = Meeting() root.users['a_user'] = User() root.users['b_user'] = User() root.users['c_user'] = User() meeting.add_groups('a_user', ['role:a']) meeting.add_groups('b_user', ['role:a']) self.assertEqual(security.find_role_userids(meeting, 'role:a'), frozenset(['a_user', 'b_user']))
def test_find_role_userids_other_context(self): from voteit.core.models.meeting import Meeting from voteit.core.models.user import User self.root['m'] = meeting = Meeting() self.root.users['a_user'] = User() self.root.users['b_user'] = User() self.root.users['c_user'] = User() meeting.add_groups('a_user', ['role:a']) meeting.add_groups('b_user', ['role:a']) self.assertEqual(security.find_role_userids(meeting, 'role:a'), frozenset(['a_user', 'b_user']))
def get_recipients(self): recipients = [] for userid in find_role_userids(self.context, ROLE_MODERATOR): user = self.api.get_user(userid) email = user.get_field_value('email') if email: recipients.append(email) if not recipients: for userid in find_authorized_userids(self.context, (MODERATE_MEETING,)): user = self.api.get_user(userid) email = user.get_field_value('email') if email: recipients.append(email) return recipients
def contact(self): """ Contact moderators of the meeting """ recipients = [] for userid in find_role_userids(self.context, ROLE_MODERATOR): user = self.api.get_user(userid) email = user.get_field_value('email') if email: recipients.append(email) if not recipients: for userid in find_authorized_userids(self.context, (MODERATE_MEETING,)): user = self.api.get_user(userid) email = user.get_field_value('email') if email: recipients.append(email) schema = createSchema('ContactSchema').bind(context = self.context, request = self.request, api = self.api) form = Form(schema, buttons=(button_send,)) self.api.register_form_resources(form) post = self.request.POST if self.request.method == 'POST': controls = post.items() try: appstruct = form.validate(controls) except ValidationFailure, e: self.response['form'] = e.render() return self.response if appstruct.get('email', None): sender = appstruct['email'] if self.api.user_profile: sender += " <%s>" % self.api.user_profile.title else: sender = None response = {'api': self.api, 'meeting': self.context, 'name': appstruct['name'], 'email': appstruct['email'], 'subject': appstruct['subject'], 'message': appstruct['message'],} body_html = render('templates/email/help_contact.pt', response, request=self.request) subject = "[%s] %s" % (self.context.title, appstruct['subject']) send_email(subject, recipients, body_html, sender = sender, request = self.request) self.api.flash_messages.add(_(u"Message sent to the moderators")) url = self.request.resource_url(self.context) return HTTPFound(location = url)
def save_voters_userids(obj, event): if event.new_state == 'ongoing': obj.set_field_value('voters_mark_ongoing', security.find_role_userids(obj, security.ROLE_VOTER)) if event.new_state == 'closed': obj.set_field_value('voters_mark_closed', security.find_role_userids(obj, security.ROLE_VOTER))
# -*- coding: utf-8 -*- from __future__ import unicode_literals import argparse from pyramid.paster import bootstrap from skl_theme.schemas import get_kommun_values from voteit.core.security import ROLE_VOTER, find_role_userids if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("config_uri", help="Paster ini file to load settings from") parser.add_argument("meeting", help="Meeting name") args = parser.parse_args() env = bootstrap(args.config_uri) root = env['root'] request = env['request'] meeting = root[args.meeting] kommuner = dict(get_kommun_values()) for userid in find_role_userids(meeting, ROLE_VOTER): user = root['users'][userid] print kommuner.get(user.kommun, ''), "\t", user.work_role env['closer']()
def test_find_role_userids(self): root = self._fixture() self.assertEqual(security.find_role_userids(root, 'role:Administrator'), frozenset(['admin']))
def test_find_role_userids_no_match(self): root = self._fixture() self.assertEqual(security.find_role_userids(root, 'role:404'), frozenset())
def test_find_role_userids_no_match(self): self.assertEqual(security.find_role_userids(self.root, 'role:404'), frozenset())
def test_find_role_userids(self): self.assertEqual(security.find_role_userids(self.root, 'role:Admin'), frozenset(['admin']))
def test_find_role_userids(self): root = self._fixture() self.assertEqual( security.find_role_userids(root, 'role:Administrator'), frozenset(['admin']))