Exemplo n.º 1
0
 def delete(self, request, *args, **kwargs):
     node = self.get_object()
     update_node_share(node)
     update_admin_log(user_id=self.request.user.id,
                      object_id=node._id,
                      object_repr='Node',
                      message='Node Reindexed (SHARE): {}'.format(node._id),
                      action_flag=REINDEX_SHARE)
     return redirect(reverse_node(self.kwargs.get('guid')))
Exemplo n.º 2
0
 def delete(self, request, *args, **kwargs):
     node = self.get_object()
     update_node_share(node)
     update_admin_log(
         user_id=self.request.user.id,
         object_id=node._id,
         object_repr='Node',
         message='Node Reindexed (SHARE): {}'.format(node._id),
         action_flag=REINDEX_SHARE
     )
     return redirect(reverse_node(self.kwargs.get('guid')))
def migrate(dry_run):
    assert settings.SHARE_URL, 'SHARE_URL must be set to migrate.'
    assert settings.SHARE_API_TOKEN, 'SHARE_API_TOKEN must be set to migrate.'
    registrations = Registration.objects.filter(is_deleted=False, is_public=True)
    registrations_count = registrations.count()
    count = 0

    logger.info('Preparing to migrate {} registrations.'.format(registrations_count))
    for registration in registrations.iterator():
        count += 1
        logger.info('{}/{} - {}'.format(count, registrations_count, registration._id))
        if not dry_run:
            update_node_share(registration)
        logger.info('Registration {} was sent to SHARE.'.format(registration._id))
Exemplo n.º 4
0
def migrate(registrations):
    assert settings.SHARE_URL, 'SHARE_URL must be set to migrate.'
    assert settings.SHARE_API_TOKEN, 'SHARE_API_TOKEN must be set to migrate.'
    registrations_count = len(registrations)

    count = 0

    logger.info('Preparing to migrate {} registrations.'.format(registrations_count))
    for registration_id in registrations:
        count += 1
        logger.info('{}/{} - {}'.format(count, registrations_count, registration_id))
        registration = AbstractNode.load(registration_id)
        assert registration.type == 'osf.registration'
        update_node_share(registration)
        logger.info('Registration {} was sent to SHARE.'.format(registration_id))
def remove_search_index(dry_run=True):
    tag_query = Q()
    title_query = Q()
    for tag in DO_NOT_INDEX_LIST['tags']:
        tag_query |= Q(tags__name = tag)

    for title in DO_NOT_INDEX_LIST['titles']:
        title_query |= Q(title__contains = title)

    increment = 20
    nodes = paginated(AbstractNode, query=Q(is_public=True) & (tag_query | title_query), increment=increment, each=True)
    if dry_run:
        logger.warn('Dry run mode.')
        for node in nodes:
            logger.info('Removing {} with title \'{}\' from search index and SHARE.'.format(node._id, node.title))
    else:
        for node in nodes:
            update_node(node, bulk=False, async=True)
            update_node_share(node)
Exemplo n.º 6
0
    def _on_complete(self, user):
        Registration = apps.get_model('osf.Registration')
        NodeLog = apps.get_model('osf.NodeLog')

        self.date_retracted = timezone.now()
        self.save()

        parent_registration = Registration.find_one(Q('retraction', 'eq',
                                                      self))
        parent_registration.registered_from.add_log(
            action=NodeLog.RETRACTION_APPROVED,
            params={
                'node': parent_registration.registered_from._id,
                'retraction_id': self._id,
                'registration': parent_registration._id
            },
            auth=Auth(self.initiated_by),
        )
        # Remove any embargoes associated with the registration
        if parent_registration.embargo_end_date or parent_registration.is_pending_embargo:
            parent_registration.embargo.state = self.REJECTED
            parent_registration.registered_from.add_log(
                action=NodeLog.EMBARGO_CANCELLED,
                params={
                    'node': parent_registration.registered_from._id,
                    'registration': parent_registration._id,
                    'embargo_id': parent_registration.embargo._id,
                },
                auth=Auth(self.initiated_by),
            )
            parent_registration.embargo.save()
        # Ensure retracted registration is public
        # Pass auth=None because the registration initiator may not be
        # an admin on components (component admins had the opportunity
        # to disapprove the retraction by this point)
        for node in parent_registration.node_and_primary_descendants():
            node.set_privacy('public', auth=None, save=True, log=False)
            node.update_search()
        # force a save before sending data to share or retraction will not be updated
        self.save()
        project_tasks.update_node_share(parent_registration)
Exemplo n.º 7
0
    def _on_complete(self, user):
        Registration = apps.get_model('osf.Registration')
        NodeLog = apps.get_model('osf.NodeLog')

        self.date_retracted = timezone.now()
        self.save()

        parent_registration = Registration.objects.get(retraction=self)
        parent_registration.registered_from.add_log(
            action=NodeLog.RETRACTION_APPROVED,
            params={
                'node': parent_registration.registered_from._id,
                'retraction_id': self._id,
                'registration': parent_registration._id
            },
            auth=Auth(self.initiated_by),
        )
        # Remove any embargoes associated with the registration
        if parent_registration.embargo_end_date or parent_registration.is_pending_embargo:
            parent_registration.embargo.state = self.REJECTED
            parent_registration.registered_from.add_log(
                action=NodeLog.EMBARGO_CANCELLED,
                params={
                    'node': parent_registration.registered_from._id,
                    'registration': parent_registration._id,
                    'embargo_id': parent_registration.embargo._id,
                },
                auth=Auth(self.initiated_by),
            )
            parent_registration.embargo.save()
        # Ensure retracted registration is public
        # Pass auth=None because the registration initiator may not be
        # an admin on components (component admins had the opportunity
        # to disapprove the retraction by this point)
        for node in parent_registration.node_and_primary_descendants():
            node.set_privacy('public', auth=None, save=True, log=False)
            node.update_search()
        # force a save before sending data to share or retraction will not be updated
        self.save()
        project_tasks.update_node_share(parent_registration)