Exemplo n.º 1
0
def purge_organizations(self):
    for organization in Organization.objects(deleted__ne=None):
        log.info(f'Purging organization {organization}')
        # Remove followers
        Follow.objects(following=organization).delete()
        # Remove activity
        Activity.objects(related_to=organization).delete()
        Activity.objects(organization=organization).delete()
        # Remove transfers
        Transfer.objects(recipient=organization).delete()
        Transfer.objects(owner=organization).delete()
        # Store datasets for later reindexation
        d_ids = [d.id for d in Dataset.objects(organization=organization)]
        # Remove organization's logo in all sizes
        if organization.logo.filename is not None:
            storage = storages.avatars
            storage.delete(organization.logo.filename)
            storage.delete(organization.logo.original)
            for key, value in organization.logo.thumbnails.items():
                storage.delete(value)
        # Remove
        organization.delete()
        # Reindex the datasets that were linked to the organization
        for id in d_ids:
            reindex(Dataset.__name__, str(id))
Exemplo n.º 2
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info(f'Purging dataset {dataset}')
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove issues
        Issue.objects(subject=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove HarvestItem references
        HarvestJob.objects(items__dataset=dataset).update(
            set__items__S__dataset=None)
        # Remove each dataset's resource's file
        storage = storages.resources
        for resource in dataset.resources:
            if resource.fs_filename is not None:
                storage.delete(resource.fs_filename)
        # Remove each dataset related community resource and it's file
        community_resources = CommunityResource.objects(dataset=dataset)
        for community_resource in community_resources:
            if community_resource.fs_filename is not None:
                storage.delete(community_resource.fs_filename)
            community_resource.delete()
        # Remove dataset
        dataset.delete()
Exemplo n.º 3
0
def purge_organizations():
    for organization in Organization.objects(deleted__ne=None):
        log.info('Purging organization "{0}"'.format(organization))
        # Remove followers
        FollowOrg.objects(following=organization).delete()
        # Remove activity
        Activity.objects(related_to=organization).delete()
        Activity.objects(organization=organization).delete()
        # Remove metrics
        Metrics.objects(object_id=organization.id).delete()
        organization.delete()
Exemplo n.º 4
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info('Purging reuse "{0}"'.format(reuse))
        # Remove followers
        FollowReuse.objects(following=reuse).delete()
        # Remove issues
        ReuseIssue.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        # Remove metrics
        Metrics.objects(object_id=reuse.id).delete()
        reuse.delete()
Exemplo n.º 5
0
def purge_datasets():
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        FollowDataset.objects(following=dataset).delete()
        # Remove issues
        DatasetIssue.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove metrics
        Metrics.objects(object_id=dataset.id).delete()
        dataset.delete()
Exemplo n.º 6
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info('Purging reuse "{0}"'.format(reuse))
        # Remove followers
        Follow.objects(following=reuse).delete()
        # Remove issues
        Issue.objects(subject=reuse).delete()
        # Remove discussions
        Discussion.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        reuse.delete()
Exemplo n.º 7
0
def purge_organizations(self):
    for organization in Organization.objects(deleted__ne=None):
        log.info('Purging organization "{0}"'.format(organization))
        # Remove followers
        FollowOrg.objects(following=organization).delete()
        # Remove activity
        Activity.objects(related_to=organization).delete()
        Activity.objects(organization=organization).delete()
        # Remove metrics
        Metrics.objects(object_id=organization.id).delete()
        # Remove
        organization.delete()
Exemplo n.º 8
0
    def test_class_shortcut(self):
        '''It should emit a signal on new activity'''
        self.emitted = False
        self.login()
        with self.app.app_context():
            login_user(self.user)
            with FakeActivity.on_new.connected_to(self.check_emitted):
                FakeActivity.emit(self.fake)

        self.assertTrue(self.emitted)

        self.assertEqual(Activity.objects(related_to=self.fake).count(), 1)
        self.assertEqual(Activity.objects(actor=self.user).count(), 1)
Exemplo n.º 9
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        FollowDataset.objects(following=dataset).delete()
        # Remove issues
        DatasetIssue.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove metrics
        Metrics.objects(object_id=dataset.id).delete()
        # Remove
        dataset.delete()
Exemplo n.º 10
0
    def test_class_shortcut(self):
        '''It should emit a signal on new activity'''
        self.emitted = False
        self.login()
        with self.app.app_context():
            login_user(self.user)
            with FakeActivity.on_new.connected_to(self.check_emitted):
                FakeActivity.emit(self.fake)

        self.assertTrue(self.emitted)

        self.assertEqual(Activity.objects(related_to=self.fake).count(), 1)
        self.assertEqual(Activity.objects(actor=self.user).count(), 1)
Exemplo n.º 11
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info('Purging reuse "{0}"'.format(reuse))
        # Remove followers
        Follow.objects(following=reuse).delete()
        # Remove issues
        Issue.objects(subject=reuse).delete()
        # Remove discussions
        Discussion.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        # Remove metrics
        Metrics.objects(object_id=reuse.id).delete()
        reuse.delete()
Exemplo n.º 12
0
def purge_organizations(self):
    for organization in Organization.objects(deleted__ne=None):
        log.info('Purging organization "{0}"'.format(organization))
        # Remove followers
        Follow.objects(following=organization).delete()
        # Remove activity
        Activity.objects(related_to=organization).delete()
        Activity.objects(organization=organization).delete()
        # Store datasets for later reindexation
        d_ids = [d.id for d in Dataset.objects(organization=organization)]
        # Remove
        organization.delete()
        # Reindex the datasets that were linked to the organization
        for id in d_ids:
            reindex(Dataset.__name__, str(id))
Exemplo n.º 13
0
    def test_create_and_retrieve_for_user(self):
        FakeActivity.objects.create(actor=self.user, related_to=self.fake)

        activities = Activity.objects(actor=self.user)

        self.assertEqual(len(activities), 1)
        self.assertIsInstance(activities[0], FakeActivity)
Exemplo n.º 14
0
    def test_create_and_retrieve_for_user(self):
        FakeActivity.objects.create(actor=self.user, related_to=self.fake)

        activities = Activity.objects(actor=self.user)

        self.assertEqual(len(activities), 1)
        self.assertIsInstance(activities[0], FakeActivity)
Exemplo n.º 15
0
 def get_context(self):
     if current_user.is_anonymous or not current_user.sysadmin:
         if not self.user.active:
             abort(410, 'User is not active')
     context = super(UserActivityView, self).get_context()
     context['activities'] = (Activity.objects(actor=self.object)
                                      .order_by('-created_at').limit(15))
     return context
Exemplo n.º 16
0
    def test_create_and_retrieve_for_org(self):
        org = OrganizationFactory()
        FakeActivity.objects.create(actor=self.user, related_to=self.fake, organization=org)

        activities = Activity.objects(organization=org)

        self.assertEqual(len(activities), 1)
        self.assertIsInstance(activities[0], FakeActivity)
Exemplo n.º 17
0
 def get_context(self):
     if current_user.is_anonymous or not current_user.sysadmin:
         if not self.user.active:
             abort(410, 'User is not active')
     context = super(UserActivityView, self).get_context()
     context['activities'] = (Activity.objects(
         actor=self.object).order_by('-created_at').limit(15))
     return context
Exemplo n.º 18
0
    def test_create_and_retrieve_for_org(self):
        org = OrganizationFactory()
        FakeActivity.objects.create(actor=self.user,
                                    related_to=self.fake,
                                    organization=org)

        activities = Activity.objects(organization=org)

        self.assertEqual(len(activities), 1)
        self.assertIsInstance(activities[0], FakeActivity)
Exemplo n.º 19
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info(f'Purging reuse {reuse}')
        # Remove followers
        Follow.objects(following=reuse).delete()
        # Remove discussions
        Discussion.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        # Remove transfers
        Transfer.objects(subject=reuse).delete()
        # Remove reuse's logo in all sizes
        if reuse.image.filename is not None:
            storage = storages.images
            storage.delete(reuse.image.filename)
            storage.delete(reuse.image.original)
            for key, value in reuse.image.thumbnails.items():
                storage.delete(value)
        reuse.delete()
Exemplo n.º 20
0
    def test_create_and_retrieve_for_related(self):
        org = OrganizationFactory()
        FakeActivity.objects.create(actor=self.user, related_to=self.fake, organization=org)
        FakeActivity.objects.create(actor=UserFactory(), related_to=self.fake)

        activities = Activity.objects(related_to=self.fake)

        self.assertEqual(len(activities), 2)
        for activity in activities:
            self.assertIsInstance(activity, FakeActivity)
Exemplo n.º 21
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        FollowDataset.objects(following=dataset).delete()
        # Remove issues
        DatasetIssue.objects(subject=dataset).delete()
        # Remove discussions
        DatasetDiscussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove metrics
        Metrics.objects(object_id=dataset.id).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove
        dataset.delete()
Exemplo n.º 22
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        FollowDataset.objects(following=dataset).delete()
        # Remove issues
        DatasetIssue.objects(subject=dataset).delete()
        # Remove discussions
        DatasetDiscussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove metrics
        Metrics.objects(object_id=dataset.id).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove
        dataset.delete()
Exemplo n.º 23
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove issues
        Issue.objects(subject=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove HarvestItem references
        HarvestJob.objects(items__dataset=dataset).update(
            set__items__S__dataset=None)
        # Remove
        dataset.delete()
Exemplo n.º 24
0
    def test_create_and_retrieve_for_related(self):
        org = OrganizationFactory()
        FakeActivity.objects.create(actor=self.user,
                                    related_to=self.fake,
                                    organization=org)
        FakeActivity.objects.create(actor=UserFactory(), related_to=self.fake)

        activities = Activity.objects(related_to=self.fake)

        self.assertEqual(len(activities), 2)
        for activity in activities:
            self.assertIsInstance(activity, FakeActivity)
Exemplo n.º 25
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info(f'Purging dataset {dataset}')
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove HarvestItem references
        HarvestJob.objects(items__dataset=dataset).update(
            set__items__S__dataset=None)
        # Remove associated Transfers
        Transfer.objects(subject=dataset).delete()
        # Remove each dataset's resource's file
        storage = storages.resources
        for resource in dataset.resources:
            if resource.fs_filename is not None:
                storage.delete(resource.fs_filename)
            # Not removing the resource from dataset.resources
            # with `dataset.remove_resource` as removing elements
            # from a list while iterating causes random effects.
            Dataset.on_resource_removed.send(Dataset,
                                             document=dataset,
                                             resource_id=resource.id)
        # Remove each dataset related community resource and it's file
        community_resources = CommunityResource.objects(dataset=dataset)
        for community_resource in community_resources:
            if community_resource.fs_filename is not None:
                storage.delete(community_resource.fs_filename)
            community_resource.delete()
        # Remove dataset
        dataset.delete()
Exemplo n.º 26
0
 def get_context(self):
     context = super(UserActivityView, self).get_context()
     context['activities'] = (Activity.objects(actor=self.object)
                                      .order_by('-created_at').limit(15))
     return context
Exemplo n.º 27
0
 def get_context(self):
     context = super(UserActivityView, self).get_context()
     context['activities'] = (Activity.objects(
         actor=self.object).order_by('-created_at').limit(15))
     return context
Exemplo n.º 28
0
 def get_context(self):
     context = super(UserActivityView, self).get_context()
     context["activities"] = Activity.objects(actor=self.object).order_by("-created_at").limit(15)
     return context