def notify_added_contributor(node, contributor, auth=None, throttle=None, email_template='default', *args, **kwargs): if email_template == 'false': return if hasattr(node, 'is_published') and not getattr(node, 'is_published'): return throttle = throttle or settings.CONTRIBUTOR_ADDED_EMAIL_THROTTLE # Email users for projects, or for components where they are not contributors on the parent node. if contributor.is_registered and ( isinstance(node, Preprint) or (not node.parent_node or (node.parent_node and not node.parent_node.is_contributor(contributor)))): mimetype = 'html' preprint_provider = None logo = None if email_template == 'preprint': email_template, preprint_provider = find_preprint_provider(node) if not email_template or not preprint_provider: return email_template = getattr(mails, 'CONTRIBUTOR_ADDED_PREPRINT')( email_template, preprint_provider) if preprint_provider._id == 'osf': logo = settings.OSF_PREPRINTS_LOGO else: logo = preprint_provider._id elif email_template == 'access_request': mimetype = 'html' email_template = getattr( mails, 'CONTRIBUTOR_ADDED_ACCESS_REQUEST'.format( email_template.upper())) elif node.has_linked_published_preprints: # Project holds supplemental materials for a published preprint email_template = getattr( mails, 'CONTRIBUTOR_ADDED_PREPRINT_NODE_FROM_OSF'.format( email_template.upper())) logo = settings.OSF_PREPRINTS_LOGO else: email_template = getattr( mails, 'CONTRIBUTOR_ADDED_DEFAULT'.format(email_template.upper())) contributor_record = contributor.contributor_added_email_records.get( node._id, {}) if contributor_record: timestamp = contributor_record.get('last_sent', None) if timestamp: if not throttle_period_expired(timestamp, throttle): return else: contributor.contributor_added_email_records[node._id] = {} mails.send_mail( contributor.username, email_template, mimetype=mimetype, user=contributor, node=node, referrer_name=auth.user.fullname if auth else '', all_global_subscriptions_none= check_if_all_global_subscriptions_are_none(contributor), branded_service=preprint_provider, can_change_preferences=False, logo=logo if logo else settings.OSF_LOGO, osf_contact_email=settings.OSF_CONTACT_EMAIL, published_preprints=[] if isinstance( node, Preprint) else serialize_preprints(node, user=None)) contributor.contributor_added_email_records[ node._id]['last_sent'] = get_timestamp() contributor.save() elif not contributor.is_registered: unreg_contributor_added.send(node, contributor=contributor, auth=auth, email_template=email_template)
def notify_added_contributor(node, contributor, auth=None, throttle=None, email_template='default', *args, **kwargs): if email_template == 'false': return if hasattr(node, 'is_published') and not getattr(node, 'is_published'): return throttle = throttle or settings.CONTRIBUTOR_ADDED_EMAIL_THROTTLE # Email users for projects, or for components where they are not contributors on the parent node. if contributor.is_registered and (isinstance(node, Preprint) or (not node.parent_node or (node.parent_node and not node.parent_node.is_contributor(contributor)))): mimetype = 'html' preprint_provider = None logo = None if email_template == 'preprint': email_template, preprint_provider = find_preprint_provider(node) if not email_template or not preprint_provider: return email_template = getattr(mails, 'CONTRIBUTOR_ADDED_PREPRINT')(email_template, preprint_provider) if preprint_provider._id == 'osf': logo = settings.OSF_PREPRINTS_LOGO else: logo = preprint_provider._id elif email_template == 'access_request': mimetype = 'html' email_template = getattr(mails, 'CONTRIBUTOR_ADDED_ACCESS_REQUEST'.format(email_template.upper())) elif node.has_linked_published_preprints: # Project holds supplemental materials for a published preprint email_template = getattr(mails, 'CONTRIBUTOR_ADDED_PREPRINT_NODE_FROM_OSF'.format(email_template.upper())) logo = settings.OSF_PREPRINTS_LOGO else: email_template = getattr(mails, 'CONTRIBUTOR_ADDED_DEFAULT'.format(email_template.upper())) contributor_record = contributor.contributor_added_email_records.get(node._id, {}) if contributor_record: timestamp = contributor_record.get('last_sent', None) if timestamp: if not throttle_period_expired(timestamp, throttle): return else: contributor.contributor_added_email_records[node._id] = {} mails.send_mail( contributor.username, email_template, mimetype=mimetype, user=contributor, node=node, referrer_name=auth.user.fullname if auth else '', all_global_subscriptions_none=check_if_all_global_subscriptions_are_none(contributor), branded_service=preprint_provider, can_change_preferences=False, logo=logo if logo else settings.OSF_LOGO, osf_contact_email=settings.OSF_CONTACT_EMAIL, published_preprints=[] if isinstance(node, Preprint) else serialize_preprints(node, user=None) ) contributor.contributor_added_email_records[node._id]['last_sent'] = get_timestamp() contributor.save() elif not contributor.is_registered: unreg_contributor_added.send(node, contributor=contributor, auth=auth, email_template=email_template)
def notify_added_contributor(node, contributor, auth=None, email_template='default', throttle=None, *args, **kwargs): logo = settings.OSF_LOGO if check_email_throttle(node, contributor, throttle=throttle): return if email_template == 'false': return if not getattr(node, 'is_published', True): return if not contributor.is_registered: unreg_contributor_added.send( node, contributor=contributor, auth=auth, email_template=email_template ) return # Email users for projects, or for components where they are not contributors on the parent node. contrib_on_parent_node = isinstance(node, (Preprint, DraftRegistration)) or \ (not node.parent_node or (node.parent_node and not node.parent_node.is_contributor(contributor))) if contrib_on_parent_node: if email_template == 'preprint': if node.provider.is_default: email_template = mails.CONTRIBUTOR_ADDED_OSF_PREPRINT logo = settings.OSF_PREPRINTS_LOGO else: email_template = mails.CONTRIBUTOR_ADDED_PREPRINT(node.provider) logo = node.provider._id elif email_template == 'draft_registration': email_template = mails.CONTRIBUTOR_ADDED_DRAFT_REGISTRATION elif email_template == 'access_request': email_template = mails.CONTRIBUTOR_ADDED_ACCESS_REQUEST elif node.has_linked_published_preprints: # Project holds supplemental materials for a published preprint email_template = mails.CONTRIBUTOR_ADDED_PREPRINT_NODE_FROM_OSF logo = settings.OSF_PREPRINTS_LOGO else: email_template = mails.CONTRIBUTOR_ADDED_DEFAULT mails.send_mail( contributor.username, email_template, user=contributor, node=node, referrer_name=auth.user.fullname if auth else '', is_initiator=getattr(auth, 'user', False) == contributor, all_global_subscriptions_none=check_if_all_global_subscriptions_are_none(contributor), branded_service=node.provider, can_change_preferences=False, logo=logo, osf_contact_email=settings.OSF_CONTACT_EMAIL, published_preprints=[] if isinstance(node, (Preprint, DraftRegistration)) else serialize_preprints(node, user=None) ) contributor.contributor_added_email_records[node._id]['last_sent'] = get_timestamp() contributor.save()