Example #1
0
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)
Example #2
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)]}