def api_publisher_task_id_head(id=None, auth_user=None, api_core=None, request=None):
    u"""
    Return a publication task serialized to JSON.

    The publication task attributes are appended with the Celery's ``async result`` of the task.
    """
    task = api_core.get_publisher_task(spec={u'_id': id})
    if not task:
        raise IndexError(to_bytes(u'No publication task with id {0}.'.format(id)))
    return ok_200(task, include_properties=True)
def api_publisher_task_id_get(id=None, auth_user=None, api_core=None, request=None):
    u"""
    Return a publication task serialized to JSON.

    The publication task attributes are appended with the Celery's ``async result`` of the task.

    All ``thing_id`` fields are replaced by corresponding ``thing``.
    For example ``user_id`` is replaced by ``user``'s data.
    """
    task = api_core.get_publisher_task(spec={u'_id': id}, load_fields=True)
    if not task:
        raise IndexError(to_bytes(u'No publication task with id {0}.'.format(id)))
    return ok_200(task, include_properties=True)
def api_publisher_task_id_delete(id=None, auth_user=None, api_core=None, request=None):
    u"""
    Revoke a publication task.

    This method do not delete tasks from tasks database but set ``revoked`` attribute in tasks database and broadcast
    revoke request to publication units with Celery. If the task is actually running it will be canceled.
    The media asset will be removed from the publication unit.
    """
    task = api_core.get_publisher_task(spec={u'_id': id})
    if not task:
        raise IndexError(to_bytes(u'No publication task with id {0}.'.format(id)))
    if auth_user._id != task.user_id:
        flask.abort(403, u'You are not allowed to revoke publication task with id {0}.'.format(id))
    api_core.revoke_publisher_task(task=task, callback_url=u'/publisher/revoke/callback', terminate=True, remove=False)
    return ok_200(u'The publication task "{0}" has been revoked. Corresponding media asset will be unpublished from'
                  ' here.'.format(task._id), include_properties=False)
Exemple #4
0
def view_publisher_tasks_revoke(request, id):
    u"""Revoke a publication task."""
    try:
        auth_user = request.args.get(u'ebuio_u_pk') or request.form.get(u'ebuio_u_pk')
        task = api_core.get_publisher_task(spec={u'_id': id})
        if not task:
            return {u'errors': [u'No publication task with id {0}.'.format(id)]}
        if auth_user != task.user_id:
            return {u'errors': [u'You are not allowed to revoke publication task with id {0}.'.format(id)]}
        api_core.revoke_publisher_task(task=task, callback_url=u'/publisher/revoke/callback', terminate=True,
                                       remove=False)
        return {u'infos': [u'The publication task "{0}" has been revoked. Corresponding media asset will be unpublished '
                u'from here.'.format(task._id)]}
    except Exception as e:
        logging.exception(e)
        return {u'errors': [unicode(e)]}