def notify_added_contributor(node, contributor, auth=None, throttle=None): throttle = throttle or settings.CONTRIBUTOR_ADDED_EMAIL_THROTTLE # Exclude forks and templates because the user forking/templating the project gets added # via 'add_contributor' but does not need to get notified. # Only email users for projects, or for components where they are not contributors on the parent node. if (contributor.is_registered and not node.template_node and not node.is_fork and (not node.parent_node or (node.parent_node and not node.parent_node.is_contributor(contributor)))): 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, mails.CONTRIBUTOR_ADDED, user=contributor, node=node, referrer_name=auth.user.fullname if auth else '', all_global_subscriptions_none=check_if_all_global_subscriptions_are_none(contributor) ) contributor.contributor_added_email_records[node._id]['last_sent'] = get_timestamp() contributor.save()
def notify_added_node_group_member(group, node, user, permission, auth, throttle=None): throttle = throttle or settings.GROUP_CONNECTED_EMAIL_THROTTLE node_group_record = user.group_connected_email_records.get(group._id, {}) if node_group_record: timestamp = node_group_record.get('last_sent', None) if timestamp: if not throttle_period_expired(timestamp, throttle): return else: user.group_connected_email_records[group._id] = {} if (not auth or auth.user != user) and user.is_registered: email_template = mails.GROUP_ADDED_TO_NODE mails.send_mail( to_addr=user.username, mail=email_template, mimetype='html', user=user, node=node, all_global_subscriptions_none=check_if_all_global_subscriptions_are_none(user), group_name=group.name, permission=permission, referrer_name=auth.user.fullname if auth else '', osf_contact_email=settings.OSF_CONTACT_EMAIL, ) user.group_connected_email_records[group._id]['last_sent'] = get_timestamp() user.save()
def notify_added_contributor(node, contributor, auth=None, throttle=None, email_template='default'): throttle = throttle or settings.CONTRIBUTOR_ADDED_EMAIL_THROTTLE # Exclude forks and templates because the user forking/templating the project gets added # via 'add_contributor' but does not need to get notified. # Only email users for projects, or for components where they are not contributors on the parent node. if (contributor.is_registered and not node.template_node and not node.is_fork and (not node.parent_node or (node.parent_node and not node.parent_node.is_contributor(contributor)))): email_template = getattr(mails, 'CONTRIBUTOR_ADDED_{}'.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, user=contributor, node=node, referrer_name=auth.user.fullname if auth else '', all_global_subscriptions_none=check_if_all_global_subscriptions_are_none(contributor) ) 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'): if email_template == 'false': 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 \ (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.is_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 ) 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'): if email_template == 'false': 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 not node.parent_node or node.parent_node and not node.parent_node.is_contributor(contributor)): preprint_provider = 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.name) elif node.is_preprint: email_template = getattr( mails, 'CONTRIBUTOR_ADDED_PREPRINT_NODE_FROM_OSF'.format( email_template.upper())) 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, 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) 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()
def notify_added_contributor(node, contributor, auth=None, throttle=None, email_template='default'): if email_template == 'false': 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 not node.parent_node or node.parent_node and not node.parent_node.is_contributor(contributor)): preprint_provider = 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.name) 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, 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 ) 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)