Esempio n. 1
0
    def start(self, context, request, appstruct, **kw):
        #improvement_cycle TODO no improve
        members = context.working_group.members
        root = request.root
        alert('internal', [root],
              members,
              internal_kind=InternalAlertKind.working_group_alert,
              subjects=[context],
              alert_kind='no_amendment')
        subject_data = get_entity_data(context, 'subject', request)
        for member in members:
            if getattr(member, 'email', ''):
                mail_template = root.get_mail_template('alert_amendment',
                                                       member.user_locale)
                subject = mail_template['subject'].format(
                    subject_title=context.title)
                email_data = get_user_data(member, 'recipient', request)
                email_data.update(subject_data)
                message = mail_template['template'].format(
                    novaideo_title=request.root.title, **email_data)
                alert('email', [root.get_site_sender()], [member.email],
                      subject=subject,
                      body=message)

        return {}
Esempio n. 2
0
    def start(self, context, request, appstruct, **kw):
        result = set()
        working_group = context.working_group
        for ballot in working_group.amendments_ballots:
            electeds = ballot.report.get_electeds()
            if electeds is not None:
                result.update(electeds)

        amendments = [a for a in result if isinstance(a, Amendment)]
        members = working_group.members
        root = getSite()
        user = get_current()
        if amendments:
            merged_text = html_diff_wrapper.merge(context.text,
                                                  [a.text for a in amendments])
            merged_text = html_diff_wrapper.normalize_text(merged_text)
            #TODO merged_keywords + merged_description
            version = context.get_version(user, (context, 'version'))
            for amendment in version.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

            self._send_ballot_result(context, request, result, members)
            context.text = merged_text
            related_ideas = [a.related_ideas for a in amendments]
            related_ideas = [
                item for sublist in related_ideas for item in sublist
            ]
            related_ideas.extend(context.related_ideas)
            related_ideas = list(set(related_ideas))
            context.set_related_ideas(related_ideas, user)
            context.working_group.init_nonproductive_cycle()
            context.reindex()
            alert('internal', [root],
                  members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context],
                  alert_kind='amendments_result')
            # Add Nia comment
            alert_comment_nia(
                context,
                request,
                root,
                internal_kind=InternalAlertKind.working_group_alert,
                subject_type='proposal',
                alert_kind='new_version',
                diff=diff_analytics(version, context,
                                    ['title', 'text', 'description']))
        else:
            context.state = PersistentList(['amendable', 'published'])
            alert('internal', [root],
                  members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context])
            for amendment in context.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

        context.reindex()
        return {'newcontext': context}
Esempio n. 3
0
    def _alert_users(self, context, request, user, answer):
        root = getSite()
        users = self._get_users_to_alerts(context, request)
        if user in users:
            users.remove(user)

        author_data = get_user_data(user, 'author', request)
        alert_data = get_entity_data(answer, 'comment', request)
        alert_data.update(author_data)
        alert('internal', [root],
              users,
              internal_kind=InternalAlertKind.content_alert,
              alert_kind='new_answer',
              subjects=[context],
              **alert_data)
        subject_data = get_entity_data(context, 'subject', request)
        alert_data.update(subject_data)
        for user_to_alert in [u for u in users if getattr(u, 'email', '')]:
            mail_template = root.get_mail_template('alert_answer',
                                                   user_to_alert.user_locale)
            subject = mail_template['subject'].format(**subject_data)
            email_data = get_user_data(user_to_alert, 'recipient', request)
            email_data.update(alert_data)
            message = mail_template['template'].format(
                novaideo_title=root.title, **email_data)
            alert('email', [root.get_site_sender()], [user_to_alert.email],
                  subject=subject,
                  body=message)
Esempio n. 4
0
    def start(self, context, request, appstruct, **kw):
        email = appstruct.pop('email')
        newnewsletters = appstruct.pop('newsletters')
        first_name = appstruct.get('first_name')
        last_name = appstruct.get('last_name')
        random_key = gen_random_token()
        root = getSite()
        mail_template = root.get_mail_template('newsletter_subscription')
        for newsletter in newnewsletters:
            newsletter.subscribe(first_name, last_name, email, random_key)
            url = request.resource_url(
                context, '@@userunsubscribenewsletter',
                query={'oid': get_oid(newsletter),
                       'user': email+'@@'+random_key})
            email_data = get_entity_data(
                newsletter, 'newsletter', request)
            subject = mail_template['subject'].format(
                newsletter_title=newsletter.title,
                novaideo_title=root.title)
            mail = mail_template['template'].format(
                first_name=first_name,
                last_name=last_name,
                unsubscribeurl=url,
                novaideo_title=root.title,
                **email_data)
            alert('email', [root.get_site_sender()], [email],
                  subject=subject, body=mail)

        return {}
Esempio n. 5
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        invitations = appstruct['invitations']
        user = get_current()
        mail_template = root.get_mail_template('invitation')
        localizer = request.localizer
        novaideo_title = root.title
        for invitation_dict in invitations:
            invitation = invitation_dict['_object_data']
            invitation.state.append('pending')
            invitation.setproperty('manager', user)
            invitation.__name__ = gen_random_token()
            root.addtoproperty('invitations', invitation)
            if not getattr(invitation, 'roles', []):
                invitation.roles = DEFAULT_ROLES

            roles_translate = [localizer.translate(APPLICATION_ROLES.get(r, r))
                               for r in invitation.roles]
            subject = mail_template['subject'].format(
                novaideo_title=novaideo_title
            )
            email_data = get_user_data(invitation, 'recipient', request)
            email_data.update(get_entity_data(
                invitation, 'invitation', request))
            message = mail_template['template'].format(
                roles=", ".join(roles_translate),
                novaideo_title=novaideo_title,
                **email_data)
            alert('email', [root.get_site_sender()], [invitation.email],
                  subject=subject, body=message)

        return {}
Esempio n. 6
0
 def _send_ballot_result(self, context, request, electeds, members):
     root = request.root
     working_group = context.working_group
     ballots_urls = [(ballot.title,
                      request.resource_url(root,
                                           '@@seeballot',
                                           query={'id': get_oid(ballot)}))
                     for ballot in working_group.amendments_ballots]
     values = {
         'ballots': ballots_urls,
         'electeds': electeds,
         'subject': context
     }
     result_body = renderers.render(self.amendments_vote_result_template,
                                    values, request)
     alert('internal', [root],
           members,
           internal_kind=InternalAlertKind.working_group_alert,
           subjects=[context],
           alert_kind='amendment_result',
           ballots=ballots_urls)
     for member in members:
         if getattr(member, 'email', ''):
             mail_template = root.get_mail_template('vote_amendment_result',
                                                    member.user_locale)
             subject = mail_template['subject'].format(
                 subject_title=context.title)
             recipientdata = get_user_data(member, 'recipient', request)
             message = mail_template['template'].format(
                 message_result=result_body,
                 novaideo_title=root.title,
                 **recipientdata)
             alert('email', [root.get_site_sender()], [member.email],
                   subject=subject,
                   html=message)
Esempio n. 7
0
    def start(self, context, request, appstruct, **kw):
        context.state.remove('pending')
        context.state.append('refused')
        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        manager = context.manager
        if manager:
            root = getSite()
            mail_template = root.get_mail_template(
                'refuse_invitation',
                getattr(manager, 'user_locale', root.locale))
            localizer = request.localizer
            email_data = get_user_data(context, 'user', request)
            novaideo_title = request.root.title
            roles_translate = [localizer.translate(APPLICATION_ROLES.get(r, r))
                               for r in context.roles]
            subject = mail_template['subject'].format(
                novaideo_title=novaideo_title,
                **email_data
            )
            email_data.update(get_user_data(manager, 'recipient', request))
            email_data.update(get_entity_data(context, 'invitation', request))
            message = mail_template['template'].format(
                roles=", ".join(roles_translate),
                novaideo_title=novaideo_title,
                **email_data)
            alert('email', [root.get_site_sender()], [manager.email],
                  subject=subject, body=message)

        return {}
Esempio n. 8
0
    def start(self, context, request, appstruct, **kw):
        context.state = PersistentList(['votes for amendments', 'published'])
        wg = context.working_group
        if 'closed' not in wg.state:
            wg.state.append('closed')

        context.reindex()
        members = wg.members
        root = request.root
        alert('internal', [root],
              members,
              internal_kind=InternalAlertKind.working_group_alert,
              subjects=[context],
              alert_kind='voting_amendment')
        subject_data = get_entity_data(context, 'subject', request)
        for member in members:
            if getattr(member, 'email', ''):
                mail_template = root.get_mail_template('start_vote_amendments',
                                                       member.user_locale)
                subject = mail_template['subject'].format(
                    subject_title=context.title)
                email_data = get_user_data(member, 'recipient', request)
                email_data.update(subject_data)
                message = mail_template['template'].format(
                    novaideo_title=root.title, **email_data)
                alert('email', [root.get_site_sender()], [member.email],
                      subject=subject,
                      body=message)

        return {}
Esempio n. 9
0
    def _alert_users(self, context, request, user, answer):
        root = getSite()
        users = self._get_users_to_alerts(context, request)
        if user in users:
            users.remove(user)

        author_data = get_user_data(user, 'author', request)
        alert_data = get_entity_data(answer, 'comment', request)
        alert_data.update(author_data)
        alert('internal', [root], users,
              internal_kind=InternalAlertKind.content_alert,
              alert_kind='new_answer',
              subjects=[context],
              **alert_data)
        subject_data = get_entity_data(context, 'subject', request)
        alert_data.update(subject_data)
        for user_to_alert in [u for u in users if getattr(u, 'email', '')]:
            mail_template = root.get_mail_template(
                'alert_answer', user_to_alert.user_locale)
            subject = mail_template['subject'].format(
                **subject_data)
            email_data = get_user_data(user_to_alert, 'recipient', request)
            email_data.update(alert_data)
            message = mail_template['template'].format(
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [user_to_alert.email],
                  subject=subject, body=message)
Esempio n. 10
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        explanation = appstruct['explanation']
        context.state = PersistentList(['archived'])
        context.reindex()
        user = context.author
        alert('internal', [root], [user],
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[context],
              alert_kind='object_archive')
        if getattr(user, 'email', ''):
            mail_template = root.get_mail_template('archive_content_decision',
                                                   user.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            email_data = get_user_data(user, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                explanation=explanation,
                novaideo_title=root.title,
                **email_data)
            alert('email', [root.get_site_sender()], [user.email],
                  subject=subject,
                  body=message)

        return {}
Esempio n. 11
0
 def _send_ballot_result(self, context, request, electeds, members):
     root = request.root
     working_group = context.working_group
     ballots_urls = [(ballot.title, request.resource_url(
                     root, '@@seeballot', query={'id': get_oid(ballot)}))
                     for ballot in working_group.amendments_ballots]
     values = {'ballots': ballots_urls,
               'electeds': electeds,
               'subject': context}
     result_body = renderers.render(
         self.amendments_vote_result_template, values, request)
     alert(
         'internal', [root], members,
         internal_kind=InternalAlertKind.working_group_alert,
         subjects=[context],
         alert_kind='amendment_result',
         ballots=ballots_urls)
     for member in members:
         if getattr(member, 'email', ''):
             mail_template = root.get_mail_template(
                 'vote_amendment_result', member.user_locale)
             subject = mail_template['subject'].format(
                 subject_title=context.title)
             recipientdata = get_user_data(member, 'recipient', request)
             message = mail_template['template'].format(
                 message_result=result_body,
                 novaideo_title=root.title,
                 **recipientdata
             )
             alert('email', [root.get_site_sender()], [member.email],
                   subject=subject, html=message)
Esempio n. 12
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        proposal = context.proposal
        working_group = context.proposal.working_group
        author = working_group.get_member(user)
        context.state.remove('draft')
        context.state.remove('explanation')
        not_published_ideas = []
        if not request.moderate_ideas and\
           'idea' not in request.content_to_examine:
            not_published_ideas = [
                i for i in context.get_used_ideas()
                if 'published' not in i.state
            ]
            publish_ideas(not_published_ideas, request)

        context.justification = appstruct.get('justification', '')
        context.state.append('submitted')
        explanations, text_diff = get_text_amendment_diff_submitted(
            context, request)
        context.explanations = PersistentDict(explanations)
        context.text_diff = text_diff

        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        not_published_ideas.extend(context)
        request.registry.notify(
            ActivityExecuted(self, not_published_ideas, author))
        alert('internal', [request.root],
              working_group.members,
              internal_kind=InternalAlertKind.working_group_alert,
              alert_kind='new_amendments',
              subjects=[proposal])
        return {}
Esempio n. 13
0
    def start(self, context, request, appstruct, **kw):
        context.state = PersistentList(['votes for amendments', 'published'])
        wg = context.working_group
        if 'closed' not in wg.state:
            wg.state.append('closed')

        context.reindex()
        members = wg.members
        root = request.root
        alert('internal', [root], members,
              internal_kind=InternalAlertKind.working_group_alert,
              subjects=[context], alert_kind='voting_amendment')
        subject_data = get_entity_data(context, 'subject', request)
        for member in members:
            if getattr(member, 'email', ''):
                mail_template = root.get_mail_template(
                    'start_vote_amendments', member.user_locale)
                subject = mail_template['subject'].format(subject_title=context.title)
                email_data = get_user_data(member, 'recipient', request)
                email_data.update(subject_data)
                message = mail_template['template'].format(
                    novaideo_title=root.title,
                    **email_data
                )
                alert('email', [root.get_site_sender()], [member.email],
                      subject=subject, body=message)

        return {}
Esempio n. 14
0
    def start(self, context, request, appstruct, **kw):
        from ..proposal_management.behaviors import exclude_participant_from_wg
        root = getSite()
        context.state.remove('active')
        context.state.append('deactivated')
        context.set_organization(None)
        proposals = getattr(context, 'participations', [])
        anonymous_proposals = getattr(context.mask, 'participations', [])
        for proposal in proposals:
            exclude_participant_from_wg(
                proposal, request, context, root)

        for proposal in anonymous_proposals:
            exclude_participant_from_wg(
                proposal, request, context.mask, root)

        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        pref_author = list(get_users_by_preferences(context))
        alert('internal', [request.root], pref_author,
              internal_kind=InternalAlertKind.content_alert,
              subjects=[context], alert_kind='user_deactivated')
        request.registry.notify(ActivityExecuted(
            self, [context], get_current()))
        return {}
Esempio n. 15
0
    def start(self, context, request, appstruct, **kw):
        newsletter = appstruct.pop('newsletter')
        user = appstruct.pop('user', None)
        if user and getattr(newsletter, 'allow_unsubscribing', True):
            parts = user.split('@@')
            key = parts[0]
            user_id = parts[1]
            subscribed = newsletter.subscribed.get(key, None)
            if subscribed and user_id == subscribed.get('id', None):
                newsletter.subscribed.pop(key)
                first_name = subscribed.get('first_name')
                last_name = subscribed.get('last_name')
                email = subscribed.get('email')
                root = getSite()
                mail_template = root.get_mail_template(
                    'newsletter_unsubscription')
                email_data = get_entity_data(
                    newsletter, 'newsletter', request)
                subject = mail_template['subject'].format(
                    newsletter_title=newsletter.title,
                    novaideo_title=root.title)
                mail = mail_template['template'].format(
                    first_name=first_name,
                    last_name=last_name,
                    novaideo_title=root.title,
                    **email_data)
                alert('email', [root.get_site_sender()], [email],
                      subject=subject, body=mail)

        return {}
Esempio n. 16
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        proposal = context.proposal
        working_group = context.proposal.working_group
        author = working_group.get_member(user)
        context.state.remove('draft')
        context.state.remove('explanation')
        not_published_ideas = []
        if not request.moderate_ideas and\
           'idea' not in request.content_to_examine:
            not_published_ideas = [i for i in context.get_used_ideas()
                                   if 'published' not in i.state]
            publish_ideas(not_published_ideas, request)

        context.justification = appstruct.get('justification', '')
        context.state.append('submitted')
        explanations, text_diff = get_text_amendment_diff_submitted(
            context, request)
        context.explanations = PersistentDict(explanations)
        context.text_diff = text_diff

        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        not_published_ideas.extend(context)
        request.registry.notify(ActivityExecuted(
            self, not_published_ideas, author))
        alert('internal', [request.root], working_group.members,
              internal_kind=InternalAlertKind.working_group_alert, alert_kind='new_amendments',
              subjects=[proposal])
        return {}
Esempio n. 17
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        explanation = appstruct['explanation']
        context.state = PersistentList(['archived'])
        context.reindex()
        user = context.author
        alert('internal', [root], [user],
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[context], alert_kind='object_archive')
        if getattr(user, 'email', ''):
            mail_template = root.get_mail_template(
                'archive_content_decision', user.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            email_data = get_user_data(user, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                explanation=explanation,
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [user.email],
                  subject=subject, body=message)

        return {}
Esempio n. 18
0
    def start(self, context, request, appstruct, **kw):
        root = request.root
        url = request.resource_url(context, "")
        deadline_date = context.init_deadline(
            datetime.datetime.now(tz=pytz.UTC))
        deadline_str = to_localized_time(
            deadline_date, request, translate=True)
        mail_template = root.get_mail_template(
            'preregistration', getattr(context, 'locale', root.locale))
        email_data = get_user_data(context, 'recipient', request)
        subject = mail_template['subject'].format(
            novaideo_title=root.title)
        deadline_str = to_localized_time(
            deadline_date, request, translate=True)
        message = mail_template['template'].format(
            url=url,
            deadline_date=deadline_str.lower(),
            novaideo_title=root.title,
            **email_data)
        alert('email', [root.get_site_sender()], [context.email],
              subject=subject, body=message)

        request.registry.notify(ActivityExecuted(
            self, [context], get_current()))
        return {}
Esempio n. 19
0
 def start(self, context, request, appstruct, **kw):
     subject = appstruct.get('subject')
     mail = appstruct.get('message')
     sender = appstruct.get('email')
     services = appstruct.get('services')
     alert('email', [sender], list(services),
           subject=subject, body=mail)
     return {}
Esempio n. 20
0
 def restor(self, request):
     self.context.state = PersistentList(['published'])
     members = [self.context.author]
     alert(
         'internal', [request.root], members,
         internal_kind=InternalAlertKind.moderation_alert,
         subjects=[self.context], alert_kind='object_restor')
     self.context.reindex()
Esempio n. 21
0
    def start(self, context, request, appstruct, **kw):
        data = context.get_data(PersonSchema())
        annotations = getattr(context, 'annotations',
                              {}).get(PROCESS_HISTORY_KEY, [])
        data.update({'password': appstruct['password']})
        data = {
            key: value
            for key, value in data.items() if value is not colander.null
        }
        data.pop('title')
        root = getSite()
        locale = my_locale_negotiator(request)
        data['locale'] = locale
        person = Person(**data)
        principals = find_service(root, 'principals')
        name = person.first_name + ' ' + person.last_name
        users = principals['users']
        name = name_chooser(users, name=name)
        users[name] = person
        grant_roles(person, roles=('Member', ))
        grant_roles(person, (('Owner', person), ))
        person.state.append('active')
        oid = str(get_oid(context))
        get_socket().send_pyobj(('stop', 'persistent_' + oid))
        organization = context.organization
        if organization:
            person.setproperty('organization', organization)

        root.delfromproperty('preregistrations', context)
        person.init_annotations()
        person.annotations.setdefault(PROCESS_HISTORY_KEY,
                                      PersistentList()).extend(annotations)
        person.reindex()
        request.registry.notify(ActivityExecuted(self, [person], person))
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(person.first_name, person.last_name,
                                     email)

        transaction.commit()
        if email:
            mail_template = root.get_mail_template('registration_confiramtion',
                                                   person.user_locale)
            subject = mail_template['subject'].format(
                novaideo_title=root.title)
            recipientdata = get_user_data(person, 'recipient', request)
            message = mail_template['template'].format(
                login_url=request.resource_url(root, '@@login'),
                novaideo_title=root.title,
                **recipientdata)
            alert('email', [root.get_site_sender()], [email],
                  subject=subject,
                  body=message)

        return {'person': person}
Esempio n. 22
0
    def start(self, context, request, appstruct, **kw):
        datas = context.get_data(
            select(omit(InvitationSchema(), ['_csrf_token_']), [
                'user_title', 'roles', 'first_name', 'last_name', 'email',
                'organization'
            ]))
        roles = datas.pop('roles')
        password = appstruct['password']
        datas['locale'] = my_locale_negotiator(request)
        person = Person(password=password, **datas)
        root = getSite(context)
        principals = find_service(root, 'principals')
        users = principals['users']
        name = person.first_name + ' ' + person.last_name
        name = name_chooser(users, name=name)
        users[name] = person
        if getattr(context, 'ismanager', False) and \
           context.organization:
            grant_roles(person,
                        (('OrganizationResponsible', context.organization), ))

        person.state.append('active')
        grant_roles(person, roles)
        grant_roles(person, (('Owner', person), ))
        manager = context.manager
        root.delfromproperty('invitations', context)
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(person.first_name, person.last_name,
                                     email)

        context.person = person
        if manager:
            mail_template = root.get_mail_template(
                'accept_invitation',
                getattr(manager, 'user_locale', root.locale))
            localizer = request.localizer
            email_data = get_user_data(person, 'user', request)
            novaideo_title = request.root.title
            roles_translate = [
                localizer.translate(APPLICATION_ROLES.get(r, r)) for r in roles
            ]
            subject = mail_template['subject'].format(
                novaideo_title=novaideo_title, **email_data)
            email_data.update(get_user_data(manager, 'recipient', request))
            email_data.update(get_entity_data(person, 'user', request))
            message = mail_template['template'].format(
                roles=", ".join(roles_translate),
                novaideo_title=novaideo_title,
                **email_data)
            alert('email', [root.get_site_sender()], [manager.email],
                  subject=subject,
                  body=message)

        return {}
Esempio n. 23
0
 def restor(self, request):
     self.context.state = PersistentList(['published'])
     members = [self.context.author]
     alert('internal', [request.root],
           members,
           internal_kind=InternalAlertKind.moderation_alert,
           subjects=[self.context],
           alert_kind='object_restor')
     self.context.reindex()
Esempio n. 24
0
    def start(self, context, request, appstruct, **kw):
        result = set()
        working_group = context.working_group
        for ballot in working_group.amendments_ballots:
            electeds = ballot.report.get_electeds()
            if electeds is not None:
                result.update(electeds)

        amendments = [a for a in result if isinstance(a, Amendment)]
        members = working_group.members
        root = getSite()
        user = get_current()
        if amendments:
            merged_text = html_diff_wrapper.merge(
                context.text, [a.text for a in amendments])
            merged_text = html_diff_wrapper.normalize_text(merged_text)
            #TODO merged_keywords + merged_description
            version = context.get_version(
                user, (context, 'version'))
            for amendment in version.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

            self._send_ballot_result(context, request,
                                     result, members)
            context.text = merged_text
            related_ideas = [a.related_ideas for a in amendments]
            related_ideas = [item for sublist in related_ideas
                             for item in sublist]
            related_ideas.extend(context.related_ideas)
            related_ideas = list(set(related_ideas))
            context.set_related_ideas(related_ideas, user)
            context.working_group.init_nonproductive_cycle()
            context.reindex()
            alert('internal', [root], members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context], alert_kind='amendments_result')
            # Add Nia comment
            alert_comment_nia(
                context, request, root,
                internal_kind=InternalAlertKind.working_group_alert,
                subject_type='proposal',
                alert_kind='new_version',
                diff=diff_analytics(
                    version, context, ['title', 'text', 'description'])
                )
        else:
            context.state = PersistentList(['amendable', 'published'])
            alert('internal', [root], members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context])
            for amendment in context.amendments:
                amendment.state = PersistentList(['archived'])
                amendment.reindex()

        context.reindex()
        return {'newcontext': context}
Esempio n. 25
0
 def censor(self, request, **kw):
     self.context.state = PersistentList(['censored'])
     members = [self.context.author]
     alert('internal', [request.root],
           members,
           internal_kind=InternalAlertKind.moderation_alert,
           subjects=[self.context],
           alert_kind='object_censor',
           ballot=kw.get('ballot_url', ''))
     self.context.reindex()
Esempio n. 26
0
 def censor(self, request):
     self.context.state_befor_censor = PersistentList(
         list(self.context.state))
     self.context.state = PersistentList(['censored'])
     members = [self.context.author]
     alert(
         'internal', [request.root], members,
         internal_kind=InternalAlertKind.moderation_alert,
         subjects=[self.context], alert_kind='object_censor')
     self.context.reindex()
Esempio n. 27
0
    def start(self, context, request, appstruct, **kw):
        data = context.get_data(PersonSchema())
        annotations = getattr(context, 'annotations', {}).get(PROCESS_HISTORY_KEY, [])
        data.update({'password': appstruct['password']})
        data = {key: value for key, value in data.items()
                if value is not colander.null}
        data.pop('title')
        root = getSite()
        locale = my_locale_negotiator(request)
        data['locale'] = locale
        person = Person(**data)
        principals = find_service(root, 'principals')
        name = person.first_name + ' ' + person.last_name
        users = principals['users']
        name = name_chooser(users, name=name)
        users[name] = person
        grant_roles(person, roles=('Member',))
        grant_roles(person, (('Owner', person),))
        person.state.append('active')
        oid = str(get_oid(context))
        get_socket().send_pyobj(('stop', 'persistent_' + oid))
        organization = context.organization
        if organization:
            person.setproperty('organization', organization)

        root.delfromproperty('preregistrations', context)
        person.init_annotations()
        person.annotations.setdefault(
            PROCESS_HISTORY_KEY, PersistentList()).extend(annotations)
        person.reindex()
        request.registry.notify(ActivityExecuted(self, [person], person))
        root.addtoproperty('news_letter_members', person)
        newsletters = root.get_newsletters_automatic_registration()
        email = getattr(person, 'email', '')
        if newsletters and email:
            for newsletter in newsletters:
                newsletter.subscribe(
                    person.first_name, person.last_name, email)

        transaction.commit()
        if email:
            mail_template = root.get_mail_template(
                'registration_confiramtion', person.user_locale)
            subject = mail_template['subject'].format(
                novaideo_title=root.title)
            recipientdata = get_user_data(person, 'recipient', request)
            message = mail_template['template'].format(
                login_url=request.resource_url(root, '@@login'),
                novaideo_title=root.title,
                **recipientdata)
            alert('email', [root.get_site_sender()], [email],
                  subject=subject, body=message)

        return {'person': person}
Esempio n. 28
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        if root.support_ideas:
            context.state = PersistentList(['submitted_support', 'published'])
        else:
            context.state = PersistentList(['published', 'submitted_support'])

        context.init_published_at()
        root.merge_keywords(context.keywords)
        context.reindex()
        user = context.author
        alert('internal', [root], [user],
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[context], alert_kind='moderation')
        if context.originalentity:
            # Add Nia comment
            alert_comment_nia(
                context.originalentity, request, root,
                internal_kind=InternalAlertKind.content_alert,
                subject_type='idea',
                alert_kind='duplicated',
                duplication=context
                )

        transformed_from = context.transformed_from
        if transformed_from:
            context_type = transformed_from.__class__.__name__.lower()
            # Add Nia comment
            alert_comment_nia(
                transformed_from, request, root,
                internal_kind=InternalAlertKind.content_alert,
                subject_type=context_type,
                alert_kind='transformation_idea',
                idea=context
                )

        if getattr(user, 'email', ''):
            mail_template = root.get_mail_template(
                'publish_idea_decision', user.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            email_data = get_user_data(user, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [user.email],
                  subject=subject, body=message)

        request.registry.notify(ObjectPublished(object=context))
        request.registry.notify(ActivityExecuted(
            self, [context], get_current(request)))
        return {}
Esempio n. 29
0
 def censor(self, request):
     self.context.state_befor_censor = PersistentList(
         list(self.context.state))
     self.context.state = PersistentList(['censored'])
     members = [self.context.author]
     alert('internal', [request.root],
           members,
           internal_kind=InternalAlertKind.moderation_alert,
           subjects=[self.context],
           alert_kind='object_censor')
     self.context.reindex()
Esempio n. 30
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        proposal = context.proposal
        working_group = context.proposal.working_group
        author = working_group.get_member(user)
        single_amendment = appstruct['single_amendment']
        groups = []
        if single_amendment:
            group = {'title': context.title,
                     'explanations': list(context.explanations.values()),
                     'justification': appstruct.get('justification', '')}
            groups = [group]
        else:
            groups = appstruct['groups']
            for group in groups:
                group['explanations'] = [context.explanations[e]
                                         for e in group['explanations']]

        context.state.remove('draft')
        context.state.remove('explanation')
        not_published_ideas = []
        if not request.moderate_ideas and\
           'idea' not in request.content_to_examine:
            not_published_ideas = [i for i in context.get_used_ideas()
                                   if 'published' not in i.state]
            publish_ideas(not_published_ideas, request)

        if len(groups) == 1:
            group = groups[0]
            data = self._get_explanation_data(context, group)
            # data.pop('description')
            data.pop('text')
            context.set_data(data)
            context.state.append('submitted')
            explanations, text_diff = get_text_amendment_diff_submitted(
                context, request)
            context.explanations = PersistentDict(explanations)
            context.text_diff = text_diff
        else:
            for group in groups:
                if group['explanations']:
                    self._add_sub_amendment(context, request, group, author)

            context.state.append('archived')

        context.modified_at = datetime.datetime.now(tz=pytz.UTC)
        context.reindex()
        not_published_ideas.extend(context)
        request.registry.notify(ActivityExecuted(
            self, not_published_ideas, author))
        alert('internal', [request.root], working_group.members,
              internal_kind=InternalAlertKind.working_group_alert, alert_kind='new_amendments',
              subjects=[proposal])
        return {'single_amendment': single_amendment or len(groups) == 1}
Esempio n. 31
0
    def start(self, context, request, appstruct, **kw):
        user = get_current(request)
        user = context.working_group.get_member(user)
        correction = appstruct['_object_data']
        correction.text = html_diff_wrapper.normalize_text(correction.text)
        old_text = correction.text
        correction.setproperty('author', user)
        version = context.get_version(user, (context, 'version'))
        context.addtoproperty('corrections', correction)
        correction.setproperty('current_version', version)
        context.setproperty('version', version.version)
        souptextdiff, textdiff = html_diff_wrapper.render_html_diff(
            getattr(context, 'text', ''),
            getattr(correction, 'text', ''),
            "correction")
        soupdescriptiondiff, descriptiondiff = html_diff_wrapper.render_html_diff(
            getattr(context, 'description', ''),
            getattr(correction, 'description', ''),
            "correction")
        souptitlediff, titlediff = html_diff_wrapper.render_html_diff(
            getattr(context, 'title', ''),
            getattr(correction, 'title', ''),
            "correction")
        descriminator = 0
        descriminator = self._identify_corrections(souptitlediff,
                                                   correction,
                                                   descriminator,
                                                   'title',
                                                   user)
        self._add_actions(correction, request, souptitlediff)
        descriminator = self._identify_corrections(soupdescriptiondiff,
                                                   correction,
                                                   descriminator,
                                                   'description',
                                                   user)
        self._add_actions(correction, request, soupdescriptiondiff)
        self._identify_corrections(souptextdiff, correction,
                                   descriminator, 'text',
                                   user)
        self._add_actions(correction, request, souptextdiff)
        correction.text = html_diff_wrapper.soup_to_text(souptextdiff)
        correction.description = html_diff_wrapper.soup_to_text(soupdescriptiondiff)
        correction.title = html_diff_wrapper.soup_to_text(souptitlediff)
        if souptextdiff.find_all("span", id="correction") or \
           soupdescriptiondiff.find_all("span", id="correction") or\
           souptitlediff.find_all("span", id="correction"):
            correction.state.append('in process')
            alert('internal', [request.root], context.working_group.members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context], alert_kind='correction_added')
        else:
            context.text = old_text

        return {}
Esempio n. 32
0
 def _alert_users(self, context, request, user, comment, channel):
     root = getSite()
     users = self._get_users_to_alerts(context, request, user, channel)
     comment_oid = getattr(comment, '__oid__', 'None')
     authordata = get_user_data(user, 'author', request)
     alert('internal', [root], users, exclude=[user],
           internal_kind=InternalAlertKind.comment_alert,
           subjects=[channel],
           comment_oid=comment_oid,
           comment_content=comment.comment,
           comment_kind='general_discuss',
           **authordata)
Esempio n. 33
0
 def censor(self, request):
     self.context.state = PersistentList(['censored'])
     self.context.remove_tokens(True)
     end_work(self.context, request)
     working_group = self.context.working_group
     members = working_group.members
     alert(
         'internal', [request.root], members,
         internal_kind=InternalAlertKind.moderation_alert,
         subjects=[self.context], alert_kind='object_censor')
     working_group.empty()
     self.context.reindex()
     working_group.reindex()
Esempio n. 34
0
    def start(self, context, request, appstruct, **kw):
        user = get_current()
        report = appstruct['_object_data']
        context.addtoproperty('reports', report)
        report.state.append('pending')
        context.state.append('reported')
        grant_roles(user=user, roles=(('Owner', report), ))
        report.setproperty('author', user)
        report.reindex()
        context.reindex()
        if hasattr(user, 'add_report'):
            user.add_report(context)

        root = getSite()
        # get random moderators
        ballots = [
            b for b in getattr(context, 'ballot_processes', [])
            if b.id == 'contentreportdecision'
        ]
        if not ballots:
            moderators = get_random_users(ELECTORS_NB, [context.author])
            if not moderators:
                ignore(context, request, root)
            else:
                author = context.author

                def before_start(b_proc):
                    b_proc.content = context

                start_ballot(context,
                             author,
                             request,
                             root,
                             moderators,
                             'contentreportdecision',
                             before_start=before_start,
                             initiator=user,
                             subjects=[context])
                alert_data = get_ballot_alert_data(context, request, root,
                                                   moderators)
                alert_data.update(get_user_data(author, 'recipient', request))
                mail_template = root.get_mail_template('alert_report',
                                                       author.user_locale)
                if mail_template:
                    subject = mail_template['subject'].format(**alert_data)
                    message = mail_template['template'].format(**alert_data)
                    alert('email', [root.get_site_sender()], [author.email],
                          subject=subject,
                          body=message)

        return {}
Esempio n. 35
0
def _invite_first_user(root, request, title, first_name, last_name, email,
                       phone):
    registry = request.registry
    first_user_roles = ['SiteAdmin']
    settings = registry.settings
    application_url = settings.get('application.url')
    principals = find_service(root, 'principals')
    user = principals['users']['admin']
    invitation = Invitation(
        user_title=title,
        first_name=first_name,
        last_name=last_name,
        email=email,
        phone=phone,
        roles=first_user_roles,
    )
    mail_template = root.get_mail_template('invitation')
    novaideo_title = root.title
    invitation.state.append('pending')
    invitation.setproperty('manager', user)
    invitation.__name__ = gen_random_token()
    root.addtoproperty('invitations', invitation)
    invitation.reindex()
    roles_translate = [APPLICATION_ROLES.get(r, r) for r in invitation.roles]
    url = application_url + '/' + invitation.__name__
    if email:
        # send email
        subject = FIRST_INVITATION['subject'].format(
            novaideo_title=novaideo_title)
        message = FIRST_INVITATION['template'].format(
            recipient_title='',
            recipient_first_name=invitation.first_name,
            recipient_last_name=invitation.last_name,
            invitation_url=url,
            roles=", ".join(roles_translate),
            novaideo_title=novaideo_title)
        alert('email', [root.get_site_sender()], [invitation.email],
              subject=subject,
              body=message)

    if phone:
        # send sms
        message = FIRST_INVITATION_SMS['template'].format(
            recipient_title='',
            recipient_first_name=invitation.first_name,
            recipient_last_name=invitation.last_name,
            invitation_url=url,
            roles=", ".join(roles_translate),
            novaideo_title=novaideo_title)
        alert('sms', recipients=[phone], request=request, message=message)
Esempio n. 36
0
 def censor(self, request):
     self.context.state = PersistentList(['censored'])
     self.context.remove_tokens(True)
     end_work(self.context, request)
     working_group = self.context.working_group
     members = working_group.members
     alert('internal', [request.root],
           members,
           internal_kind=InternalAlertKind.moderation_alert,
           subjects=[self.context],
           alert_kind='object_censor')
     working_group.empty()
     self.context.reindex()
     working_group.reindex()
Esempio n. 37
0
def add_files_to_workspace(files_data, workspace):
    files = []
    for file_data in files_data:
        file_ = file_data.get('_object_data', None)
        if file_:
            workspace.addtoproperty('files', file_)
            files.append(file_)

    root = getSite()
    members = workspace.working_group.members
    alert('internal', [root], members,
          internal_kind=InternalAlertKind.working_group_alert,
          subjects=[workspace.proposal], alert_kind='add_files')
    return files
Esempio n. 38
0
 def _alert_users(self, context, request, user, comment, channel):
     root = getSite()
     users = self._get_users_to_alerts(context, request, user, channel)
     comment_oid = getattr(comment, '__oid__', 'None')
     authordata = get_user_data(user, 'author', request)
     alert('internal', [root],
           users,
           exclude=[user],
           internal_kind=InternalAlertKind.comment_alert,
           subjects=[channel],
           comment_oid=comment_oid,
           comment_content=comment.comment,
           comment_kind='general_discuss',
           **authordata)
Esempio n. 39
0
    def start(self, context, request, appstruct, **kw):
        user = get_current(request)
        user = context.working_group.get_member(user)
        correction = appstruct['_object_data']
        correction.text = html_diff_wrapper.normalize_text(correction.text)
        old_text = correction.text
        correction.setproperty('author', user)
        version = context.get_version(user, (context, 'version'))
        context.addtoproperty('corrections', correction)
        correction.setproperty('current_version', version)
        context.setproperty('version', version.version)
        souptextdiff, textdiff = html_diff_wrapper.render_html_diff(
            getattr(context, 'text', ''), getattr(correction, 'text', ''),
            "correction")
        soupdescriptiondiff, descriptiondiff = html_diff_wrapper.render_html_diff(
            getattr(context, 'description', ''),
            getattr(correction, 'description', ''), "correction")
        souptitlediff, titlediff = html_diff_wrapper.render_html_diff(
            getattr(context, 'title', ''), getattr(correction, 'title', ''),
            "correction")
        descriminator = 0
        descriminator = self._identify_corrections(souptitlediff, correction,
                                                   descriminator, 'title',
                                                   user)
        self._add_actions(correction, request, souptitlediff)
        descriminator = self._identify_corrections(soupdescriptiondiff,
                                                   correction, descriminator,
                                                   'description', user)
        self._add_actions(correction, request, soupdescriptiondiff)
        self._identify_corrections(souptextdiff, correction, descriminator,
                                   'text', user)
        self._add_actions(correction, request, souptextdiff)
        correction.text = html_diff_wrapper.soup_to_text(souptextdiff)
        correction.description = html_diff_wrapper.soup_to_text(
            soupdescriptiondiff)
        correction.title = html_diff_wrapper.soup_to_text(souptitlediff)
        if souptextdiff.find_all("span", id="correction") or \
           soupdescriptiondiff.find_all("span", id="correction") or\
           souptitlediff.find_all("span", id="correction"):
            correction.state.append('in process')
            alert('internal', [request.root],
                  context.working_group.members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context],
                  alert_kind='correction_added')
        else:
            context.text = old_text

        return {}
Esempio n. 40
0
    def start(self, context, request, appstruct, **kw):
        user = get_current(request)
        user.remove_token(context)
        context.remove_token(user)
        context.init_support_history()
        context._support_history.append(
            (get_oid(user), datetime.datetime.now(tz=pytz.UTC), -1))
        context.reindex()
        request.registry.notify(ActivityExecuted(self, [context], user))
        if user is not context.author:
            alert('internal', [request.root], [context.author],
                  internal_kind=InternalAlertKind.support_alert,
                  subjects=[context], support_kind='withdraw')

        return {}
Esempio n. 41
0
    def restor(self, request):
        self.context.state = PersistentList(
            list(self.context.state_befor_censor))
        del self.context.state_befor_censor
        members = [self.context.author]
        alert('internal', [request.root],
              members,
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[self.context],
              alert_kind='object_restor')
        for event in self.context.events:
            event.state = PersistentList(['published'])
            event.update()
            event.reindex()

        self.context.reindex()
Esempio n. 42
0
def add_files_to_workspace(files_data, workspace):
    files = []
    for file_data in files_data:
        file_ = file_data.get('_object_data', None)
        if file_:
            workspace.addtoproperty('files', file_)
            files.append(file_)

    root = getSite()
    members = workspace.working_group.members
    alert('internal', [root],
          members,
          internal_kind=InternalAlertKind.working_group_alert,
          subjects=[workspace.proposal],
          alert_kind='add_files')
    return files
Esempio n. 43
0
 def start(self, context, request, appstruct, **kw):
     user = get_current()
     report = appstruct['_object_data']
     context.addtoproperty('reports', report)
     report.state.append('pending')
     context.state.append('reported')
     grant_roles(user=user, roles=(('Owner', report), ))
     report.setproperty('author', user)
     report.reindex()
     context.reindex()
     moderators = get_users_with_role(role='Moderator')
     alert(
         'internal', [request.root], moderators,
         internal_kind=InternalAlertKind.moderation_alert,
         subjects=[context], alert_kind='new_report')
     return {}
Esempio n. 44
0
    def restor(self, request):
        self.context.state = PersistentList(['draft'])
        author = self.context.author
        working_group = self.context.working_group
        members = working_group.members
        if author not in members:
            grant_roles(user=author, roles=(('Participant', self.context), ))
            working_group.addtoproperty('members', author)

        members = working_group.members
        alert(
            'internal', [request.root], members,
            internal_kind=InternalAlertKind.moderation_alert,
            subjects=[self.context], alert_kind='object_restor')
        self.context.reindex()
        working_group.reindex()
Esempio n. 45
0
 def start(self, context, request, appstruct, **kw):
     user = get_current()
     report = appstruct['_object_data']
     context.addtoproperty('reports', report)
     report.state.append('pending')
     context.state.append('reported')
     grant_roles(user=user, roles=(('Owner', report), ))
     report.setproperty('author', user)
     report.reindex()
     context.reindex()
     moderators = get_users_with_role(role='Moderator')
     alert('internal', [request.root],
           moderators,
           internal_kind=InternalAlertKind.moderation_alert,
           subjects=[context],
           alert_kind='new_report')
     return {}
Esempio n. 46
0
    def restor(self, request):
        self.context.state = PersistentList(['draft'])
        author = self.context.author
        working_group = self.context.working_group
        members = working_group.members
        if author not in members:
            grant_roles(user=author, roles=(('Participant', self.context), ))
            working_group.addtoproperty('members', author)

        members = working_group.members
        alert('internal', [request.root],
              members,
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[self.context],
              alert_kind='object_restor')
        self.context.reindex()
        working_group.reindex()
Esempio n. 47
0
    def censor(self, request, **kw):
        self.context.state_befor_censor = PersistentList(
            list(self.context.state))
        self.context.state = PersistentList(['censored'])
        self.context.remove_tokens(True)
        members = [self.context.author]
        alert('internal', [request.root],
              members,
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[self.context],
              alert_kind='object_censor',
              ballot=kw.get('ballot_url', ''))
        for event in self.context.events:
            event.state = PersistentList(['censored'])
            event.reindex()

        self.context.reindex()
Esempio n. 48
0
 def start(self, context, request, appstruct, **kw):
     root = getSite()
     mail_template = root.get_mail_template('invitation')
     localizer = request.localizer
     roles_translate = [localizer.translate(APPLICATION_ROLES.get(r, r))
                        for r in getattr(context, 'roles', [])]
     subject = mail_template['subject'].format(
         novaideo_title=root.title
     )
     email_data = get_user_data(context, 'recipient', request)
     email_data.update(get_entity_data(context, 'invitation', request))
     message = mail_template['template'].format(
         roles=", ".join(roles_translate),
         novaideo_title=root.title,
         **email_data)
     alert('email', [root.get_site_sender()], [context.email],
           subject=subject, body=message)
     return {}
Esempio n. 49
0
def run_notation_process(context, request, user, members, alert_id=None):
    if members:
        subjects = [context]
        title = _('Mark of the cooperative behaviour of ${member}',
                  mapping={'member': user.title})
        ballot = Ballot('FPTP',
                        members,
                        subjects,
                        DURATION,
                        vote_process_id='membernotationmanagement',
                        group_values=NOTATIONS,
                        group_default=DEFAULT_NOTATION,
                        group=NOTATION_GROUP)
        context.addtoproperty('ballots', ballot)
        ballot.title = title
        ballot.report.description_template = 'novaideo:views/templates/ballots/member_notation.pt'
        processes = ballot.run_ballot(context=context)
        for process in processes:
            process.execution_context.add_involved_entity('member', user)

        if alert_id:
            root = getSite()
            alert_data = get_user_data(user, 'user', request)
            alert_data.update(get_entity_data(user, 'user', request))
            alert('internal', [root],
                  members,
                  internal_kind=InternalAlertKind.working_group_alert,
                  subjects=[context],
                  alert_kind=alert_id,
                  **alert_data)
            alert_data.update(get_entity_data(context, 'subject', request))
            for member in [a for a in members if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(alert_id,
                                                       member.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title, **alert_data)
                email_data = get_user_data(member, 'recipient', request)
                alert_data.update(email_data)
                message = mail_template['template'].format(
                    novaideo_title=root.title, **alert_data)
                alert('email', [root.get_site_sender()], [member.email],
                      subject=subject,
                      body=message)
Esempio n. 50
0
 def start(self, context, request, appstruct, **kw):
     root = getSite()
     mail_template = root.get_mail_template('invitation')
     localizer = request.localizer
     roles_translate = [
         localizer.translate(APPLICATION_ROLES.get(r, r))
         for r in getattr(context, 'roles', [])
     ]
     subject = mail_template['subject'].format(novaideo_title=root.title)
     email_data = get_user_data(context, 'recipient', request)
     email_data.update(get_entity_data(context, 'invitation', request))
     message = mail_template['template'].format(
         roles=", ".join(roles_translate),
         novaideo_title=root.title,
         **email_data)
     alert('email', [root.get_site_sender()], [context.email],
           subject=subject,
           body=message)
     return {}
Esempio n. 51
0
def mysubscriber_object_modified(event):
    content = event.object
    args = event.args
    state_source = args.get('state_source', '')
    state_target = args.get('state_target', '')
    request = get_current_request()
    users = get_users_by_preferences(content)
    root = request.root
    localizer = request.localizer
    subject_data = get_entity_data(content, 'subject', request)
    all_users = []
    for member in users:
        all_users.append(member)
        if getattr(member, 'email', ''):
            mail_template = root.get_mail_template('alert_content_modified',
                                                   member.user_locale)
            subject = mail_template['subject'].format(**subject_data)
            state_source_translate = state_source
            state_target_translate = state_target
            if state_source:
                state_source_translate = localizer.translate(
                    get_states_mapping(member, content, state_source))
            if state_target:
                state_target_translate = localizer.translate(
                    get_states_mapping(member, content, state_target))

            email_data = get_user_data(member, 'recipient', request)
            email_data.update(subject_data)
            message = mail_template['template'].format(
                state_source=state_source_translate,
                state_target=state_target_translate,
                novaideo_title=root.title,
                **email_data)
            alert('email', [root.get_site_sender()], [member.email],
                  subject=subject,
                  body=message)

    alert('internal', [root],
          all_users,
          internal_kind=InternalAlertKind.content_alert,
          subjects=[content],
          alert_kind='modified')
Esempio n. 52
0
    def start(self, context, request, appstruct, **kw):
        appstruct.pop('_csrf_token_')
        context.opinion = PersistentDict(appstruct)
        context.state = PersistentList(
            ['examined', 'published', context.opinion['opinion']])
        context.init_examined_at()
        context.remove_tokens()
        context.reindex()
        member = context.author
        root = getSite()
        users = list(get_users_by_preferences(context))
        users.append(member)
        alert(
            'internal', [root], users,
            internal_kind=InternalAlertKind.examination_alert,
            subjects=[context])
        # Add Nia comment
        alert_comment_nia(
            context, request, root,
            internal_kind=InternalAlertKind.examination_alert,
            subject_type='idea'
            )
        if getattr(member, 'email', ''):
            mail_template = root.get_mail_template(
                'opinion_idea', member.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            localizer = request.localizer
            email_data = get_user_data(member, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                opinion=localizer.translate(_(context.opinion_value)),
                explanation=context.opinion['explanation'],
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [member.email],
                  subject=subject, body=message)

        request.registry.notify(ActivityExecuted(
            self, [context], get_current(request)))
        return {}
Esempio n. 53
0
    def after_execution(self, context, request, **kw):
        content = self.process.execution_context.involved_entity('content')
        close_ballot(self, content, request)
        # content not removed
        if content and content.__parent__:
            root = getSite()
            moderators = self.process.execution_context.get_involved_collection(
                'electors')
            for moderator in moderators:
                revoke_roles(user=moderator,
                             roles=(('LocalModerator', content), ))

            ballots = getattr(self.sub_process, 'ballots', [])
            ballot = None
            for ballot_ in ballots:
                ballot_.finish_ballot()
                ballot = ballot_

            ballot_oid = get_oid(ballot, '')
            ballot_url = request.resource_url(
                root, '@@seeballot', query={'id': ballot_oid}) \
                if ballot_oid else None
            accepted = ballot_result(self, _marker)
            if accepted:
                ignore(content, request, root)
                alert('internal', [request.root],
                      moderators,
                      internal_kind=InternalAlertKind.moderation_alert,
                      subjects=[content],
                      alert_kind='object_report_ignored',
                      ballot=ballot_url if accepted is not _marker else None)
            else:
                censor(content, request, root, ballot_url=ballot_url)
                alert('internal', [request.root],
                      moderators,
                      internal_kind=InternalAlertKind.moderation_alert,
                      subjects=[content],
                      alert_kind='object_censor',
                      ballot=ballot_url)

        super(ModerationVote, self).after_execution(content, request, **kw)
Esempio n. 54
0
    def start(self, context, request, appstruct, **kw):
        root = getSite()
        context.state = PersistentList(['published', 'pending'])
        context.init_published_at()
        root.merge_keywords(context.keywords)
        context.reindex()
        user = appstruct.get('user', get_current(request))
        author = context.author
        alert('internal', [root], [author],
              internal_kind=InternalAlertKind.moderation_alert,
              subjects=[context], alert_kind='moderation')
        # transformed_from = context.transformed_from
        # if transformed_from:
        #     context_type = transformed_from.__class__.__name__.lower()
        #     # Add Nia comment
        #     alert_comment_nia(
        #         transformed_from, request, root,
        #         internal_kind=InternalAlertKind.content_alert,
        #         subject_type=context_type,
        #         alert_kind='transformation_challenge',
        #         idea=context
        #         )

        if user is not author and getattr(author, 'email', ''):
            mail_template = root.get_mail_template(
                'publish_challenge_decision', user.user_locale)
            subject = mail_template['subject'].format(
                subject_title=context.title)
            email_data = get_user_data(author, 'recipient', request)
            email_data.update(get_entity_data(context, 'subject', request))
            message = mail_template['template'].format(
                novaideo_title=root.title,
                **email_data
            )
            alert('email', [root.get_site_sender()], [author.email],
                  subject=subject, body=message)

        request.registry.notify(ObjectPublished(object=context))
        request.registry.notify(ActivityExecuted(
            self, [context], user))
        return {}
Esempio n. 55
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        preregistration.locale = my_locale_negotiator(request)
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(remove_expired_preregistration_callback,
                                   deadline,
                                   call_id,
                                   root=root,
                                   preregistration=preregistration)
        preregistration.state.append('pending')
        preregistration.reindex()
        transaction.commit()
        if not getattr(root, 'moderate_registration', False):
            accept_preregistration(request, preregistration, root)
        else:
            admins = get_users_with_role(role='SiteAdmin')
            alert('internal', [root],
                  admins,
                  internal_kind=InternalAlertKind.admin_alert,
                  subjects=[preregistration],
                  alert_kind='new_registration')
            url = request.resource_url(preregistration, '@@index')
            for admin in [a for a in admins if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(
                    'moderate_preregistration', admin.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title)
                email_data = get_user_data(admin, 'recipient', request)
                message = mail_template['template'].format(
                    url=url, novaideo_title=root.title, **email_data)
                alert('email', [root.get_site_sender()], [admin.email],
                      subject=subject,
                      body=message)

        request.registry.notify(ActivityExecuted(self, [preregistration],
                                                 None))
        return {'preregistration': preregistration}
Esempio n. 56
0
def accept_preregistration(request, preregistration, root):
    preregistration.init_deadline(datetime.datetime.now(tz=pytz.UTC))
    if getattr(preregistration, 'email', ''):
        deadline_date = preregistration.get_deadline_date()
        locale = my_locale_negotiator(request)
        url = request.resource_url(preregistration, "")
        mail_template = root.get_mail_template(
            'preregistration', getattr(preregistration, 'locale', locale))
        email_data = get_user_data(preregistration, 'recipient', request)
        subject = mail_template['subject'].format(
            novaideo_title=root.title)
        deadline_str = to_localized_time(
            deadline_date, request, translate=True)
        message = mail_template['template'].format(
            url=url,
            deadline_date=deadline_str.lower(),
            novaideo_title=root.title,
            **email_data
            )
        alert('email', [root.get_site_sender()], [preregistration.email],
              subject=subject, body=message)
Esempio n. 57
0
    def start(self, context, request, appstruct, **kw):
        preregistration = appstruct['_object_data']
        preregistration.__name__ = gen_random_token()
        preregistration.locale = my_locale_negotiator(request)
        root = getSite()
        root.addtoproperty('preregistrations', preregistration)
        deadline = DEADLINE_PREREGISTRATION * 1000
        call_id = 'persistent_' + str(get_oid(preregistration))
        push_callback_after_commit(
            remove_expired_preregistration_callback, deadline, call_id,
            root=root, preregistration=preregistration)
        preregistration.state.append('pending')
        preregistration.reindex()
        transaction.commit()
        if not getattr(root, 'moderate_registration', False):
            accept_preregistration(request, preregistration, root)
        else:
            admins = get_users_with_role(role='SiteAdmin')
            alert(
                'internal', [root], admins,
                internal_kind=InternalAlertKind.admin_alert,
                subjects=[preregistration], alert_kind='new_registration')
            url = request.resource_url(preregistration, '@@index')
            for admin in [a for a in admins if getattr(a, 'email', '')]:
                mail_template = root.get_mail_template(
                    'moderate_preregistration', admin.user_locale)
                subject = mail_template['subject'].format(
                    novaideo_title=root.title)
                email_data = get_user_data(admin, 'recipient', request)
                message = mail_template['template'].format(
                    url=url,
                    novaideo_title=root.title,
                    **email_data)
                alert('email', [root.get_site_sender()], [admin.email],
                      subject=subject, body=message)

        request.registry.notify(ActivityExecuted(self, [preregistration], None))
        return {'preregistration': preregistration}