def perform(self): """Format and send messages to different user groups. This is similar to the FileMoved perform method. The main difference is the moved and earned user groups are added together because they both don't have a subscription to a newly copied file. """ remove_message = self.html_message + ' You do not have permission in the new component.' if self.node == self.source_node: super(AddonFileCopied, self).perform() return if self.payload['destination']['kind'] != u'folder': moved, warn, rm_users = event_utils.categorize_users(self.user, self.event_type, self.source_node, self.event_type, self.node) else: files = event_utils.get_file_subs_from_folder(self.addon, self.user, self.payload['destination']['kind'], self.payload['destination']['path'], self.payload['destination']['name']) moved, warn, rm_users = event_utils.compile_user_lists(files, self.user, self.source_node, self.node) for notification in NOTIFICATION_TYPES: if notification == 'none': continue if moved[notification] or warn[notification]: users = list(set(moved[notification]).union(set(warn[notification]))) emails.store_emails(users, notification, 'file_updated', self.user, self.node, self.timestamp, message=self.html_message, gravatar_url=self.gravatar_url, url=self.url) if rm_users[notification]: emails.store_emails(rm_users[notification], notification, 'file_updated', self.user, self.source_node, self.timestamp, message=remove_message, gravatar_url=self.gravatar_url, url=self.source_url)
def reviews_submit_notification_moderators(self, timestamp, context): # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.profile.utils import get_profile_image_url from website.notifications import emails from website import settings # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription = NotificationSubscription.load('{}_new_pending_submissions'.format(context['reviewable'].provider._id)) # Set message context['message'] = u'submitted {}.'.format(context['reviewable'].node.title) # Set url for profile image of the submitter context['profile_image_url'] = get_profile_image_url(context['referrer']) # Set submission url context['reviews_submission_url'] = '{}reviews/preprints/{}/{}'.format(settings.DOMAIN, context['reviewable'].provider._id, context['reviewable']._id) # Store emails to be sent to subscribers instantly (at a 5 min interval) emails.store_emails(provider_subscription.email_transactional.all().values_list('guids___id', flat=True), 'email_transactional', 'new_pending_submissions', context['referrer'], context['reviewable'].node, timestamp, abstract_provider=context['reviewable'].provider, **context) # Store emails to be sent to subscribers daily emails.store_emails(provider_subscription.email_digest.all().values_list('guids___id', flat=True), 'email_digest', 'new_pending_submissions', context['referrer'], context['reviewable'].node, timestamp, abstract_provider=context['reviewable'].provider, **context)
def perform(self): """Format and send messages to different user groups. This is similar to the FileMoved perform method. The main difference is the moved and earned user groups are added together because they both don't have a subscription to a newly copied file. """ remove_message = self.html_message + ' You do not have permission in the new component.' if self.node == self.source_node: super(AddonFileCopied, self).perform() return if self.payload['destination']['kind'] != u'folder': moved, warn, rm_users = event_utils.categorize_users(self.user, self.event_type, self.source_node, self.event_type, self.node) else: files = event_utils.get_file_subs_from_folder(self.addon, self.user, self.payload['destination']['kind'], self.payload['destination']['path'], self.payload['destination']['name']) moved, warn, rm_users = event_utils.compile_user_lists(files, self.user, self.source_node, self.node) for notification in NOTIFICATION_TYPES: if notification == 'none': continue if moved[notification] or warn[notification]: users = list(set(moved[notification]).union(set(warn[notification]))) emails.store_emails(users, notification, 'file_updated', self.user, self.node, self.timestamp, message=self.html_message, profile_image_url=self.profile_image_url, url=self.url) if rm_users[notification]: emails.store_emails(rm_users[notification], notification, 'file_updated', self.user, self.source_node, self.timestamp, message=remove_message, profile_image_url=self.profile_image_url, url=self.source_url)
def reviews_submit_notification_moderators(self, timestamp, context): # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.profile.utils import get_profile_image_url from website.notifications.emails import store_emails resource = context['reviewable'] provider = resource.provider # Set submission url if provider.type == 'osf.preprintprovider': context['reviews_submission_url'] = ( f'{DOMAIN}reviews/preprints/{provider._id}/{resource._id}') elif provider.type == 'osf.registrationprovider': context[ 'reviews_submission_url'] = f'{DOMAIN}{resource._id}?mode=moderator' else: raise NotImplementedError(f'unsupported provider type {provider.type}') # Set url for profile image of the submitter context['profile_image_url'] = get_profile_image_url(context['referrer']) # Set message revision_id = context.get('revision_id') if revision_id: context['message'] = f'submitted updates to "{resource.title}".' context['reviews_submission_url'] += f'&revisionId={revision_id}' else: context['message'] = f'submitted "{resource.title}".' # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription, created = NotificationSubscription.objects.get_or_create( _id=f'{provider._id}_new_pending_submissions', provider=provider) # "transactional" subscribers receive notifications "Immediately" (i.e. at 5 minute intervals) # "digest" subscribers receive emails daily recipients_per_subscription_type = { 'email_transactional': list(provider_subscription.email_transactional.all().values_list( 'guids___id', flat=True)), 'email_digest': list(provider_subscription.email_digest.all().values_list('guids___id', flat=True)) } for subscription_type, recipient_ids in recipients_per_subscription_type.items( ): if not recipient_ids: continue store_emails(recipient_ids, subscription_type, 'new_pending_submissions', context['referrer'], resource, timestamp, abstract_provider=provider, **context)
def reviews_submit_notification_moderators(self, timestamp, context): # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.profile.utils import get_profile_image_url from website.notifications.emails import store_emails resource = context['reviewable'] provider = resource.provider # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription, created = NotificationSubscription.objects.get_or_create( _id=f'{provider._id}_new_pending_submissions', provider=provider) # Set message context['message'] = f'submitted "{resource.title}".' # Set url for profile image of the submitter context['profile_image_url'] = get_profile_image_url(context['referrer']) # Set submission url if provider.type == 'osf.preprintprovider': url_segment = 'preprints' flag_suffix = '' elif provider.type == 'osf.registrationprovider': url_segment = 'registries' flag_suffix = '?mode=moderator' else: raise NotImplementedError(f'unsupported provider type {provider.type}') context[ 'reviews_submission_url'] = f'{DOMAIN}reviews/{url_segment}/{provider._id}/{resource._id}{flag_suffix}' email_transactional_ids = list( provider_subscription.email_transactional.all().values_list( 'guids___id', flat=True)) email_digest_ids = list( provider_subscription.email_digest.all().values_list('guids___id', flat=True)) # Store emails to be sent to subscribers instantly (at a 5 min interval) store_emails(email_transactional_ids, 'email_transactional', 'new_pending_submissions', context['referrer'], resource, timestamp, abstract_provider=provider, **context) # Store emails to be sent to subscribers daily store_emails(email_digest_ids, 'email_digest', 'new_pending_submissions', context['referrer'], resource, timestamp, abstract_provider=provider, **context)
def reviews_withdraw_requests_notification_moderators(self, timestamp, context): # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.profile.utils import get_profile_image_url from website.notifications.emails import store_emails resource = context['reviewable'] provider = resource.provider # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription, created = NotificationSubscription.objects.get_or_create( _id=f'{provider._id}_new_pending_withdraw_requests', provider=provider) # Set message context['message'] = f'has requested withdrawal of "{resource.title}".' # Set url for profile image of the submitter context['profile_image_url'] = get_profile_image_url(context['referrer']) # Set submission url context[ 'reviews_submission_url'] = f'{DOMAIN}reviews/registries/{provider._id}/{resource._id}' email_transactional_ids = list( provider_subscription.email_transactional.all().values_list( 'guids___id', flat=True)) email_digest_ids = list( provider_subscription.email_digest.all().values_list('guids___id', flat=True)) # Store emails to be sent to subscribers instantly (at a 5 min interval) store_emails(email_transactional_ids, 'email_transactional', 'new_pending_withdraw_requests', context['referrer'], resource, timestamp, abstract_provider=provider, template='new_pending_submissions', **context) # Store emails to be sent to subscribers daily store_emails(email_digest_ids, 'email_digest', 'new_pending_withdraw_requests', context['referrer'], resource, timestamp, abstract_provider=provider, template='new_pending_submissions', **context)
def reviews_withdrawal_requests_notification(self, timestamp, context): # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.notifications.emails import store_emails from website.profile.utils import get_profile_image_url from website import settings # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription = NotificationSubscription.load( '{}_new_pending_submissions'.format( context['reviewable'].provider._id)) preprint = context['reviewable'] preprint_word = preprint.provider.preprint_word # Set message context['message'] = u'has requested withdrawal of the {} "{}".'.format( preprint_word, preprint.title) # Set url for profile image of the submitter context['profile_image_url'] = get_profile_image_url(context['requester']) # Set submission url context['reviews_submission_url'] = '{}reviews/preprints/{}/{}'.format( settings.DOMAIN, preprint.provider._id, preprint._id) email_transactional_ids = list( provider_subscription.email_transactional.all().values_list( 'guids___id', flat=True)) email_digest_ids = list( provider_subscription.email_digest.all().values_list('guids___id', flat=True)) # Store emails to be sent to subscribers instantly (at a 5 min interval) store_emails(email_transactional_ids, 'email_transactional', 'new_pending_submissions', context['requester'], preprint, timestamp, abstract_provider=preprint.provider, **context) # Store emails to be sent to subscribers daily store_emails(email_digest_ids, 'email_digest', 'new_pending_submissions', context['requester'], preprint, timestamp, abstract_provider=preprint.provider, **context)
def reviews_submit_notification_moderators(self, timestamp, context): # imports moved here to avoid AppRegistryNotReady error from osf.models import NotificationSubscription from website.profile.utils import get_profile_image_url from website.notifications import emails from website import settings # Get NotificationSubscription instance, which contains reference to all subscribers provider_subscription = NotificationSubscription.load( '{}_new_pending_submissions'.format( context['reviewable'].provider._id)) # Set message context['message'] = u'submitted {}.'.format( context['reviewable'].node.title) # Set url for profile image of the submitter context['profile_image_url'] = get_profile_image_url(context['referrer']) # Set submission url context['reviews_submission_url'] = '{}reviews/preprints/{}/{}'.format( settings.DOMAIN, context['reviewable'].provider._id, context['reviewable']._id) # Store emails to be sent to subscribers instantly (at a 5 min interval) emails.store_emails( provider_subscription.email_transactional.all().values_list( 'guids___id', flat=True), 'email_transactional', 'new_pending_submissions', context['referrer'], context['reviewable'].node, timestamp, abstract_provider=context['reviewable'].provider, **context) # Store emails to be sent to subscribers daily emails.store_emails(provider_subscription.email_digest.all().values_list( 'guids___id', flat=True), 'email_digest', 'new_pending_submissions', context['referrer'], context['reviewable'].node, timestamp, abstract_provider=context['reviewable'].provider, **context)
def perform(self): """Format and send messages to different user groups. Users fall into three categories: moved, warned, and removed - Moved users are users with subscriptions on the new node. - Warned users are users without subscriptions on the new node, but they do have permissions - Removed users are told that they do not have permissions on the new node and their subscription has been removed. This will be **much** more useful when individual files have their own subscription. """ # Do this is the two nodes are the same, no one needs to know specifics of permissions if self.node == self.source_node: super(AddonFileMoved, self).perform() return # File if self.payload['destination']['kind'] != u'folder': moved, warn, rm_users = event_utils.categorize_users(self.user, self.event_type, self.source_node, self.event_type, self.node) warn_message = u'{} You are no longer tracking that file based on the settings you selected for the component.'.format(self.html_message) remove_message = (u'{} Your subscription has been removed' u' due to insufficient permissions in the new component.').format(self.html_message) # Folder else: # Gets all the files in a folder to look for permissions conflicts files = event_utils.get_file_subs_from_folder(self.addon, self.user, self.payload['destination']['kind'], self.payload['destination']['path'], self.payload['destination']['name']) # Bins users into different permissions moved, warn, rm_users = event_utils.compile_user_lists(files, self.user, self.source_node, self.node) # For users that don't have individual file subscription but has permission on the new node warn_message = u'{} You are no longer tracking that folder or files within based on the settings you selected for the component.'.format(self.html_message) # For users without permission on the new node remove_message = (u'{} Your subscription has been removed for the folder,' u' or a file within,' u' due to insufficient permissions in the new component.').format(self.html_message) # Move the document from one subscription to another because the old one isn't needed utils.move_subscription(rm_users, self.event_type, self.source_node, self.event_type, self.node) # Notify each user for notification in NOTIFICATION_TYPES: if notification == 'none': continue if moved[notification]: emails.store_emails(moved[notification], notification, 'file_updated', self.user, self.node, self.timestamp, message=self.html_message, gravatar_url=self.gravatar_url, url=self.url) if warn[notification]: emails.store_emails(warn[notification], notification, 'file_updated', self.user, self.node, self.timestamp, message=warn_message, gravatar_url=self.gravatar_url, url=self.url) if rm_users[notification]: emails.store_emails(rm_users[notification], notification, 'file_updated', self.user, self.source_node, self.timestamp, message=remove_message, gravatar_url=self.gravatar_url, url=self.source_url)
def perform(self): """Format and send messages to different user groups. Users fall into three categories: moved, warned, and removed - Moved users are users with subscriptions on the new node. - Warned users are users without subscriptions on the new node, but they do have permissions - Removed users are told that they do not have permissions on the new node and their subscription has been removed. This will be **much** more useful when individual files have their own subscription. """ # Do this is the two nodes are the same, no one needs to know specifics of permissions if self.node == self.source_node: super(AddonFileMoved, self).perform() return # File if self.payload['destination']['kind'] != u'folder': moved, warn, rm_users = event_utils.categorize_users(self.user, self.event_type, self.source_node, self.event_type, self.node) warn_message = u'{} You are no longer tracking that file based on the settings you selected for the component.'.format(self.html_message) remove_message = (u'{} Your subscription has been removed' u' due to insufficient permissions in the new component.').format(self.html_message) # Folder else: # Gets all the files in a folder to look for permissions conflicts files = event_utils.get_file_subs_from_folder(self.addon, self.user, self.payload['destination']['kind'], self.payload['destination']['path'], self.payload['destination']['name']) # Bins users into different permissions moved, warn, rm_users = event_utils.compile_user_lists(files, self.user, self.source_node, self.node) # For users that don't have individual file subscription but has permission on the new node warn_message = u'{} You are no longer tracking that folder or files within based on the settings you selected for the component.'.format(self.html_message) # For users without permission on the new node remove_message = (u'{} Your subscription has been removed for the folder,' u' or a file within,' u' due to insufficient permissions in the new component.').format(self.html_message) # Move the document from one subscription to another because the old one isn't needed utils.move_subscription(rm_users, self.event_type, self.source_node, self.event_type, self.node) # Notify each user for notification in NOTIFICATION_TYPES: if notification == 'none': continue if moved[notification]: emails.store_emails(moved[notification], notification, 'file_updated', self.user, self.node, self.timestamp, message=self.html_message, profile_image_url=self.profile_image_url, url=self.url) if warn[notification]: emails.store_emails(warn[notification], notification, 'file_updated', self.user, self.node, self.timestamp, message=warn_message, profile_image_url=self.profile_image_url, url=self.url) if rm_users[notification]: emails.store_emails(rm_users[notification], notification, 'file_updated', self.user, self.source_node, self.timestamp, message=remove_message, profile_image_url=self.profile_image_url, url=self.source_url)