def has_permission(self, request, view, args, kwargs): task_id = kwargs.get('task_id', None) if not task_id or not is_valid_task_id(task_id): return False user_id, owner_id, dc_id = user_owner_dc_ids_from_task_id(task_id) if not user_id or not owner_id: return False try: dc_id = int(dc_id) except ValueError: return False try: dc = Dc.objects.get_by_id(dc_id) except Dc.DoesNotExist: return False if request.user.is_admin(request, dc=dc): return True return user_id == str(request.user.id)
def _announce_task(event, event_status): task_id = event['uuid'] user_id, owner_id, dc_id = user_owner_dc_ids_from_task_id(task_id) if owner_id == internal_id: return # probably beat task if event.get('queue', None) == 'mgmt': return # sent task on mgmt if event.get('direct', None): # Send signal to ObjectOwner only users = (int(owner_id), ) else: # Send signal to all affected users users = User.get_super_admin_ids() # SuperAdmins users.update(User.get_dc_admin_ids(dc_id=dc_id)) # DcAdmins users.add(int(user_id)) # TaskCreator users.add(int(owner_id)) # ObjectOwner debug('Sending signal for %s task %s to %s', event_status, task_id, users) # Signal! for i in users: new_task = signal('task-for-%s' % i) new_task.send(event, task_id=task_id, event_status=event_status)
def _announce_task(event, event_status): task_id = event['uuid'] user_id, owner_id, dc_id = user_owner_dc_ids_from_task_id(task_id) if owner_id == internal_id: return # probably beat task if event.get('queue', None) == 'mgmt': return # sent task on mgmt if event.get('direct', None): # Send signal to ObjectOwner only users = (int(owner_id),) elif event.get('broadcast', None): # Send signal to all active socket.io sessions from sio.namespaces import ACTIVE_USERS users = set(session[0] for session in itervalues(ACTIVE_USERS)) else: # Send signal to all affected users users = User.get_super_admin_ids() # SuperAdmins users.update(User.get_dc_admin_ids(dc_id=dc_id)) # DcAdmins users.add(int(user_id)) # TaskCreator users.add(int(owner_id)) # ObjectOwner debug('Sending signal for %s task %s to %s', event_status, task_id, users) # Signal! for i in users: new_task = signal('task-for-%s' % i) new_task.send(event, task_id=task_id, event_status=event_status)
def task_details(request, task_id=None, data=None): """ Show (:http:get:`GET </task/(task_id)>`) task details of a pending task or delete (:http:delete:`DELETE </task/(task_id)>`) a started task. .. http:get:: /task/(task_id) :DC-bound?: * |dc-yes| :Permissions: * |UserTask| :Asynchronous?: * |async-no| :status 200: Object with task details :status 403: Forbidden :status 404: Task does not exist .. http:delete:: /task/(task_id) :DC-bound?: * |dc-yes| :Permissions: * |SuperAdmin| :Asynchronous?: * |async-no| :arg data.force: Force task deletion. EXPERIMENTAL feature. USE WITH CAUTION! (default: false) :type data.force: boolean :status 200: Delete pending :status 403: Forbidden :status 404: Task does not exist :status 406: Task cannot be deleted """ user_id, owner_id, dc_id = user_owner_dc_ids_from_task_id(task_id) res = UserTasks(owner_id).get(task_id) if not res or int(dc_id) != request.dc.id: return TaskFailureResponse(request, 'Task does not exist', status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': apiview = res.get('apiview', {}) apiview['task_id'] = task_id return TaskSuccessResponse(request, apiview) elif request.method == 'DELETE': force = ForceSerializer(data=data, default=False).is_true() tid, err = delete_task(task_id, force=force) if err: return TaskFailureResponse(request, err, status=status.HTTP_406_NOT_ACCEPTABLE) else: return TaskSuccessResponse(request, 'Delete pending')