Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
def get_owners(request, dc=None, all=False, order_by=('username', )):
    """
    Return QuerySet of all active users. WARNING: Use with care!
    """
    dc = dc or request.dc
    qs = User.objects.exclude(id=settings.SYSTEM_USER).filter(
        is_active=True).order_by(*order_by).distinct()

    if all or dc.access == dc.PUBLIC:
        # Public DC is available for all active users
        return qs

    # Private DC is available to only staff, DC owner and DC admins ...
    admins = User.get_super_admin_ids()
    admins.update(User.get_dc_admin_ids(dc))

    # ... and users who have access to DC:
    return qs.filter(Q(id__in=admins) | Q(roles__in=dc.roles.all()))
Beispiel #4
0
    def _announce_task(event, event_status):
        task_id = event['uuid']
        task_prefix = task_prefix_from_task_id(task_id)

        if task_prefix[2] == internal_id:  # owner_id
            return  # probably beat task

        if event.get('queue', None) == 'mgmt':
            return  # sent task on mgmt

        users = User.get_super_admin_ids()  # SuperAdmins
        users.update(User.get_dc_admin_ids(dc_id=task_prefix[4]))  # DcAdmins
        users.add(int(task_prefix[0]))  # TaskCreator
        users.add(int(task_prefix[2]))  # 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)
Beispiel #5
0
def log(msgdict):
    """
    Save msgdict into DB and cache.
    """
    # This dictionary can be store more than once
    dct = msgdict.copy()

    # DB
    TaskLogEntry.add(**msgdict)

    # Do not store PKs in cache
    dc_id = dct.pop('dc_id')
    owner_id = dct.pop('owner_id')
    del dct['user_id']
    del dct['object_pk']
    del dct['content_type']
    dct['time'] = dct['time'].isoformat()

    # Always store everything in staff cached task log
    _cache_log(_cache_log_key(settings.TASK_LOG_STAFF_ID, dc_id), dct)

    # Store owner relevant actions in owners cached task log
    if owner_id not in User.get_super_admin_ids():
        _cache_log(_cache_log_key(owner_id, dc_id), dct)