Beispiel #1
0
    def _notify_users(self, event, event_initiator):
        '''Notify users of relevant state transitions.'''
        #  Notifications on the original response will be handled by the registration workflow
        if not self.previous_response:
            return

        # Generate the "reviews" email context and notify moderators
        if self.state is ApprovalStates.PENDING_MODERATION:
            email_context = notifications.get_email_template_context(resource=self.parent)
            email_context['revision_id'] = self._id
            email_context['referrer'] = self.initiator
            reviews_email_submit_moderators_notifications.send(
                timestamp=timezone.now(), context=email_context
            )

        template = EMAIL_TEMPLATES_PER_EVENT.get(event)
        if not template:
            return

        email_context = {
            'resource_type': self.parent.__class__.__name__.lower(),
            'title': self.parent.title,
            'parent_url': self.parent.absolute_url,
            'update_url': self.absolute_url,
            'initiator': event_initiator.fullname if event_initiator else None,
            'pending_moderation': self.state is ApprovalStates.PENDING_MODERATION,
            'provider': self.parent.provider.name if self.parent.provider else '',
        }

        for contributor, _ in self.parent.get_active_contributors_recursive(unique_users=True):
            email_context['user'] = contributor
            email_context['can_write'] = self.parent.has_permission(contributor, 'write')
            email_context['is_approver'] = contributor in self.pending_approvers.all(),
            email_context['is_initiator'] = contributor == event_initiator
            mails.send_mail(to_addr=contributor.username, mail=template, **email_context)
Beispiel #2
0
def reviews_submit_notification(self, recipients, context):
    # Avoid AppRegistryNotReady error
    from website.notifications.emails import get_user_subscriptions

    event_type = utils.find_subscription_type('global_reviews')

    provider = context['reviewable'].provider
    if provider._id == 'osf':
        if provider.type == 'osf.preprintprovider':
            context['logo'] = OSF_PREPRINTS_LOGO
        elif provider.type == 'osf.registrationprovider':
            context['logo'] = OSF_REGISTRIES_LOGO
        else:
            raise NotImplementedError()
    else:
        context['logo'] = context['reviewable'].provider._id

    for recipient in recipients:
        user_subscriptions = get_user_subscriptions(recipient, event_type)
        context['no_future_emails'] = user_subscriptions['none']
        context['is_creator'] = recipient == context['reviewable'].creator
        context['provider_name'] = context['reviewable'].provider.name
        mails.send_mail(recipient.username,
                        mails.REVIEWS_SUBMISSION_CONFIRMATION,
                        mimetype='html',
                        user=recipient,
                        **context)
Beispiel #3
0
 def notify_accept_reject(self, ev):
     if ev.event.name == DefaultTriggers.REJECT.value:
         context = self.get_context()
         mails.send_mail(self.machineable.creator.username,
                         mails.WITHDRAWAL_REQUEST_DECLINED, **context)
     else:
         pass
Beispiel #4
0
    def notify_withdraw(self, ev):
        context = self.get_context()
        context['ever_public'] = self.machineable.ever_public
        try:
            preprint_request_action = PreprintRequestAction.objects.get(
                target__target__id=self.machineable.id,
                from_state='pending',
                to_state='accepted',
                trigger='accept')
            context['requester'] = preprint_request_action.target.creator
        except PreprintRequestAction.DoesNotExist:
            # If there is no preprint request action, it means the withdrawal is directly initiated by admin/moderator
            context['withdrawal_submitter_is_moderator_or_admin'] = True

        for contributor in self.machineable.contributors.all():
            context['contributor'] = contributor
            if context.get('requester', None):
                context['is_requester'] = context[
                    'requester'].username == contributor.username
            mails.send_mail(
                contributor.username,
                mails.WITHDRAWAL_REQUEST_GRANTED,
                mimetype='html',
                document_type=self.machineable.provider.preprint_word,
                **context)
Beispiel #5
0
 def notify_accept_reject(self, ev):
     """ Notify requester that admins have approved/denied
     """
     if ev.event.name == DefaultTriggers.REJECT.value:
         context = self.get_context()
         mails.send_mail(self.machineable.creator.username,
                         mails.ACCESS_REQUEST_DENIED, **context)
     else:
         # add_contributor sends approval notification email
         pass
Beispiel #6
0
def notify_reject_withdraw_request(resource, action, *args, **kwargs):
    context = get_email_template_context(resource)
    context['requester'] = action.creator

    for contributor in resource.contributors.all():
        context['contributor'] = contributor
        context['requester'] = action.creator
        context['is_requester'] = action.creator == contributor

        mails.send_mail(contributor.username,
                        mails.WITHDRAWAL_REQUEST_DECLINED, **context)
 def notify_accept_reject(self, ev):
     if ev.event.name == DefaultTriggers.REJECT.value:
         context = self.get_context()
         mails.send_mail(
             self.machineable.creator.username,
             mails.PREPRINT_WITHDRAWAL_REQUEST_DECLINED,
             mimetype='html',
             **context
         )
     else:
         pass
Beispiel #8
0
def reviews_submit_notification(self, recipients, context):
    event_type = utils.find_subscription_type('global_reviews')
    for recipient in recipients:
        user_subscriptions = get_user_subscriptions(recipient, event_type)
        context['no_future_emails'] = user_subscriptions['none']
        context['is_creator'] = recipient == context['reviewable'].node.creator
        context['provider_name'] = context['reviewable'].provider.name
        mails.send_mail(recipient.username,
                        mails.REVIEWS_SUBMISSION_CONFIRMATION,
                        mimetype='html',
                        user=recipient,
                        **context)
Beispiel #9
0
 def notify_accept_reject(self, ev):
     """ Notify requester that admins have approved/denied
     """
     if ev.event.name == DefaultTriggers.REJECT.value:
         context = self.get_context()
         mails.send_mail(
             self.machineable.creator.username,
             mails.ACCESS_REQUEST_DENIED,
             **context
         )
     else:
         # add_contributor sends approval notification email
         pass
Beispiel #10
0
 def notify_submit(self, ev):
     """ Notify admins that someone is requesting access
     """
     context = self.get_context()
     context['contributors_url'] = '{}contributors/'.format(
         self.machineable.target.absolute_url)
     context['project_settings_url'] = '{}settings/'.format(
         self.machineable.target.absolute_url)
     for admin in self.machineable.target.admin_contributors:
         mails.send_mail(admin.username,
                         mails.ACCESS_REQUEST_SUBMITTED,
                         admin=admin,
                         **context)
Beispiel #11
0
 def notify_submit(self, ev):
     """ Notify admins that someone is requesting access
     """
     context = self.get_context()
     context['contributors_url'] = '{}contributors/'.format(self.machineable.target.absolute_url)
     context['project_settings_url'] = '{}settings/'.format(self.machineable.target.absolute_url)
     for admin in self.machineable.target.admin_contributors:
         mails.send_mail(
             admin.username,
             mails.ACCESS_REQUEST_SUBMITTED,
             admin=admin,
             **context
         )
Beispiel #12
0
def notify_withdraw_registration(resource, action, *args, **kwargs):
    context = get_email_template_context(resource)

    context[
        'force_withdrawal'] = action.trigger == RegistrationModerationTriggers.FORCE_WITHDRAW.db_name
    context['requester'] = resource.retraction.initiated_by
    context['comment'] = action.comment
    context[
        'notify_comment'] = not resource.provider.reviews_comments_private and action.comment

    for contributor in resource.contributors.all():
        context['contributor'] = contributor
        context['is_requester'] = context['requester'] == contributor
        mails.send_mail(contributor.username, mails.WITHDRAWAL_REQUEST_GRANTED,
                        **context)
Beispiel #13
0
 def notify_submit(self, ev):
     """ Notify admins that someone is requesting access
     """
     context = self.get_context()
     context['contributors_url'] = '{}contributors/'.format(self.machineable.target.absolute_url)
     context['project_settings_url'] = '{}settings/'.format(self.machineable.target.absolute_url)
     for admin in self.machineable.target.contributors.filter(contributor__admin=True, contributor__node=self.machineable.target):
         mails.send_mail(
             admin.username,
             mails.ACCESS_REQUEST_SUBMITTED,
             admin=admin,
             mimetype='html',
             osf_contact_email=OSF_CONTACT_EMAIL,
             **context
         )
Beispiel #14
0
    def notify_submit(self, ev):
        """ Notify admins that someone is requesting access
        """
        context = self.get_context()
        context['contributors_url'] = '{}contributors/'.format(
            self.machineable.target.absolute_url)
        context['project_settings_url'] = '{}settings/'.format(
            self.machineable.target.absolute_url)

        for admin in self.machineable.target.get_users_with_perm(
                permissions.ADMIN):
            mails.send_mail(admin.username,
                            mails.ACCESS_REQUEST_SUBMITTED,
                            admin=admin,
                            osf_contact_email=OSF_CONTACT_EMAIL,
                            **context)
Beispiel #15
0
def reviews_submit_notification(self, recipients, context):
    # Avoid AppRegistryNotReady error
    from website.notifications.emails import get_user_subscriptions
    event_type = utils.find_subscription_type('global_reviews')
    for recipient in recipients:
        user_subscriptions = get_user_subscriptions(recipient, event_type)
        context['no_future_emails'] = user_subscriptions['none']
        context['is_creator'] = recipient == context['reviewable'].node.creator
        context['provider_name'] = context['reviewable'].provider.name
        mails.send_mail(
            recipient.username,
            mails.REVIEWS_SUBMISSION_CONFIRMATION,
            mimetype='html',
            user=recipient,
            **context
        )
Beispiel #16
0
def reviews_submit_notification(self, recipients, context):
    # Avoid AppRegistryNotReady error
    from website.notifications.emails import get_user_subscriptions
    from website import settings

    event_type = utils.find_subscription_type('global_reviews')
    if context['reviewable'].provider._id == 'osf':
        context['logo'] = settings.OSF_PREPRINTS_LOGO
    else:
        context['logo'] = context['reviewable'].provider._id

    for recipient in recipients:
        user_subscriptions = get_user_subscriptions(recipient, event_type)
        context['no_future_emails'] = user_subscriptions['none']
        context['is_creator'] = recipient == context['reviewable'].node.creator
        context['provider_name'] = context['reviewable'].provider.name
        mails.send_mail(recipient.username,
                        mails.REVIEWS_SUBMISSION_CONFIRMATION,
                        mimetype='html',
                        user=recipient,
                        **context)
Beispiel #17
0
    def notify_withdraw(self, ev):
        context = self.get_context()
        try:
            preprint_request_action = PreprintRequestAction.objects.get(target__id=self.machineable.id,
                                                                   from_state='pending',
                                                                   to_state='accepted',
                                                                   trigger='accept')
            context['requester'] = preprint_request_action.target.creator
        except PreprintRequestAction.DoesNotExist:
            # If there is no preprint request action, it means the withdrawal is directly initiated by admin/moderator
            context['withdrawal_submitter_is_moderator_or_admin'] = True

        for contributor in self.machineable.node.contributors.all():
            context['contributor'] = contributor
            if context.get('requester', None):
                context['is_requester'] = context['requester'].username == contributor.username
            mails.send_mail(
                contributor.username,
                mails.PREPRINT_WITHDRAWAL_REQUEST_GRANTED,
                mimetype='html',
                **context
            )
 def test_disabled_triggered_emails_not_sent_if_switch_active(self):
     with override_switch(DISABLE_ENGAGEMENT_EMAILS, active=True):
         assert mails.send_mail(to_addr='', mail=mails.WELCOME) is False
         assert mails.send_mail(to_addr='', mail=mails.WELCOME_OSF4I) is False