Пример #1
0
def collaborate(request, address):
    '''
    Connect to a live collaboration clone via a Websocket connection
    '''
    api = API(request)
    if api.get:
        if not request.user.is_authenticated():
            return api.respond_signin()
        else:
            # Check that the permit is correct for this address and user
            # TODO add a salt
            if compare_digest(
                str(request.GET.get('permit', '')),
                hmac.new(settings.SECRET_KEY, address + ':' + request.user.username).hexdigest()
            ):
                url = '/internal-collaboration-websocket/%s:%s' % (
                    # TODO when we have multiple collaboration servers, find the IP one for the one hostong
                    # this address
                    '10.0.1.75',
                    7315
                )
                response = HttpResponse('X-Accel-Redirect : %s' % url)
                response['X-Accel-Redirect'] = url
                return response
            else:
                raise Http404()
    return api.respond_bad()
Пример #2
0
def ping(request, address):
    '''
    Ping the component's session.

    Returns the session id since that could change
    '''
    api = API(request)
    if api.put:
        if not request.user.is_authenticated():
            return api.respond_signin()
        else:
            component = Component.get(
                id=None,
                user=request.user,
                action=READ,
                address=address
            )
            session = component.activate(
                user=request.user
            )
            session.ping()
            return api.respond({
                'session': session.id
            })
    return api.respond_bad()
Пример #3
0
def method(request, address, method):
    '''
    A general view for calling methods on components that are hosted
    in a session. Will launch a new session for a component if necessary.
    Not all component methods need an active session so views
    should be explicitly provided for those below.
    '''
    api = API(request)
    if api.put:
        if not request.user.is_authenticated():
            return api.respond_signin()
        else:
            component = Component.get(
                id=None,
                user=request.user,
                action=READ, # TODO : allow for alternative rights
                address=address
            )
            session = component.activate(
                user=request.user
            )
            status, body = session.request(
                resource=address,
                verb=request.method,
                method=method,
                data=request.body
            )
            return api.respond(
                data=body,
                raw=True,
                status=status
            )
    return api.respond_bad()
Пример #4
0
def deactivate(request, address):
    '''
    Dectivate a component by stopping the currently active session for it
    '''
    api = API(request)
    if api.put:
        if not request.user.is_authenticated():
            return api.respond_signin()
        else:
            component = Component.get(
                id=None,
                user=request.user,
                action=READ,
                address=address
            )
            session = component.deactivate(
                user=request.user
            )
            return api.respond(session)
    return api.respond_bad()
Пример #5
0
def session(request, address):
    '''
    Get the session, if any, for a component
    '''
    api = API(request)
    if api.put:
        if not request.user.is_authenticated():
            return api.respond_signin()
        else:
            component = Component.get(
                id=None,
                user=request.user,
                action=READ,
                address=address
            )
            session = component.session(
                user=request.user,
                required=False
            )
            if session and session.active:
                session.update()
            return api.respond(session)
    return api.respond_bad()