Пример #1
0
    def put(self, collection_id):
        """Unpublishes the given collection."""
        collection = collection_services.get_collection_by_id(collection_id)
        version = self.payload.get('version')
        _require_valid_version(version, collection.version)

        rights_manager.unpublish_collection(self.user, collection_id)
        search_services.delete_collections_from_search_index([collection_id])

        collection_rights = rights_manager.get_collection_rights(collection_id,
                                                                 strict=False)

        self.values.update({
            'can_edit':
            True,
            'can_unpublish':
            rights_manager.check_can_unpublish_activity(
                self.user, collection_rights),
            'collection_id':
            collection.id,
            'is_private':
            rights_manager.is_collection_private(collection_id),
            'owner_names':
            rights_manager.get_collection_owner_names(collection_id)
        })
        self.render_json(self.values)
Пример #2
0
    def test_delete_collections_from_search_index(self):
        def _mock_delete_docs(ids, index):
            """Mocks delete_documents_from_index()."""
            self.assertEqual(ids, [self.COLLECTION_ID])
            self.assertEqual(index, search_services.SEARCH_INDEX_COLLECTIONS)

        delete_docs_counter = test_utils.CallCounter(_mock_delete_docs)

        delete_docs_swap = self.swap(gae_search_services,
                                     'delete_documents_from_index',
                                     delete_docs_counter)

        with delete_docs_swap:
            search_services.delete_collections_from_search_index(
                [self.COLLECTION_ID])

        self.assertEqual(delete_docs_counter.times_called, 1)
Пример #3
0
    def test_delete_collections_from_search_index(self) -> None:
        def _mock_delete_docs(ids: List[str], index: str) -> None:
            """Mocks delete_documents_from_index()."""
            self.assertEqual(ids, [self.COLLECTION_ID])
            self.assertEqual(index, search_services.SEARCH_INDEX_COLLECTIONS)

        delete_docs_counter = test_utils.CallCounter(
            _mock_delete_docs)  # type: ignore[no-untyped-call]

        delete_docs_swap = self.swap(gae_search_services,
                                     'delete_documents_from_index',
                                     delete_docs_counter)

        with delete_docs_swap:
            search_services.delete_collections_from_search_index(
                [self.COLLECTION_ID])

        self.assertEqual(delete_docs_counter.times_called, 1)
Пример #4
0
def delete_collection(committer_id, collection_id, force_deletion=False):
    """Deletes the collection with the given collection_id.

    IMPORTANT: Callers of this function should ensure that committer_id has
    permissions to delete this collection, prior to calling this function.

    Args:
        committer_id: str. ID of the committer.
        collection_id: str. ID of the collection to be deleted.
        force_deletion: bool. If true, the collection and its history are fully
            deleted and are unrecoverable. Otherwise, the collection and all
            its history are marked as deleted, but the corresponding models are
            still retained in the datastore. This last option is the preferred
            one.
    """
    collection_rights_model = collection_models.CollectionRightsModel.get(
        collection_id)
    collection_rights_model.delete(committer_id,
                                   '',
                                   force_deletion=force_deletion)

    collection_model = collection_models.CollectionModel.get(collection_id)
    collection_model.delete(committer_id,
                            feconf.COMMIT_MESSAGE_COLLECTION_DELETED,
                            force_deletion=force_deletion)

    # This must come after the collection is retrieved. Otherwise the memcache
    # key will be reinstated.
    collection_memcache_key = _get_collection_memcache_key(collection_id)
    memcache_services.delete(collection_memcache_key)

    # Delete the collection from search.
    search_services.delete_collections_from_search_index([collection_id])

    # Delete the summary of the collection (regardless of whether
    # force_deletion is True or not).
    delete_collection_summary(collection_id)

    # Remove the collection from the featured activity list, if necessary.
    activity_services.remove_featured_activity(
        constants.ACTIVITY_TYPE_COLLECTION, collection_id)
Пример #5
0
def delete_collections(committer_id, collection_ids, force_deletion=False):
    """Deletes the collections with the given collection_ids.

    IMPORTANT: Callers of this function should ensure that committer_id has
    permissions to delete this collection, prior to calling this function.

    Args:
        committer_id: str. ID of the committer.
        collection_ids: list(str). IDs of the collections to be deleted.
        force_deletion: bool. If true, the collections and its histories are
            fully deleted and are unrecoverable. Otherwise, the collections and
            all its histories are marked as deleted, but the corresponding
            models are still retained in the datastore.
    """
    collection_models.CollectionRightsModel.delete_multi(
        collection_ids, committer_id, '', force_deletion=force_deletion)
    collection_models.CollectionModel.delete_multi(
        collection_ids,
        committer_id,
        feconf.COMMIT_MESSAGE_EXPLORATION_DELETED,
        force_deletion=force_deletion)

    # This must come after the collection is retrieved. Otherwise the memcache
    # key will be reinstated.
    caching_services.delete_multi(caching_services.CACHE_NAMESPACE_COLLECTION,
                                  None, collection_ids)

    # Delete the collection from search.
    search_services.delete_collections_from_search_index(collection_ids)

    # Delete the summary of the collection (regardless of whether
    # force_deletion is True or not).
    delete_collection_summaries(collection_ids)

    # Remove the collection from the featured activity list, if necessary.
    activity_services.remove_featured_activities(
        constants.ACTIVITY_TYPE_COLLECTION, collection_ids)