Пример #1
0
def _unpublish_activity(committer, activity_id, activity_type):
    """Unpublishes the given activity.

    Args:
        committer: UserActionsInfo. UserActionsInfo object for the committer.
        activity_id: str. ID of the activity.
        activity_type: str. The type of activity. Possible values:
            constants.ACTIVITY_TYPE_EXPLORATION,
            constants.ACTIVITY_TYPE_COLLECTION.

    Raises:
        Exception. The committer does not have rights to unpublish the
            activity.
    """
    committer_id = committer.user_id
    activity_rights = _get_activity_rights(activity_type, activity_id)

    if not check_can_unpublish_activity(committer, activity_rights):
        logging.error('User %s tried to unpublish %s %s but was refused '
                      'permission.' %
                      (committer_id, activity_type, activity_id))
        raise Exception('This %s cannot be unpublished.' % activity_type)

    _change_activity_status(committer_id, activity_id, activity_type,
                            rights_domain.ACTIVITY_STATUS_PRIVATE,
                            '%s unpublished.' % activity_type)

    activity_services.remove_featured_activity(activity_type, activity_id)
Пример #2
0
def _unpublish_activity(committer_id, activity_id, activity_type):
    if not Actor(committer_id).can_unpublish(activity_type, activity_id):
        logging.error(
            'User %s tried to unpublish %s %s but was refused '
            'permission.' % (committer_id, activity_type, activity_id))
        raise Exception('This %s cannot be unpublished.' % activity_type)

    _change_activity_status(
        committer_id, activity_id, activity_type, ACTIVITY_STATUS_PRIVATE,
        '%s unpublished.' % activity_type)

    activity_services.remove_featured_activity(activity_type, activity_id)
Пример #3
0
def _unpublish_activity(committer_id, activity_id, activity_type):
    if not Actor(committer_id).can_unpublish(activity_type, activity_id):
        logging.error(
            'User %s tried to unpublish %s %s but was refused '
            'permission.' % (committer_id, activity_type, activity_id))
        raise Exception('This %s cannot be unpublished.' % activity_type)

    _change_activity_status(
        committer_id, activity_id, activity_type, ACTIVITY_STATUS_PRIVATE,
        '%s unpublished.' % activity_type)

    activity_services.remove_featured_activity(activity_type, activity_id)
Пример #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_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.

    If force_deletion is 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.
    delete_documents_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(
        feconf.ACTIVITY_TYPE_COLLECTION, collection_id)