Exemple #1
0
    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)
Exemple #2
0
    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)