sentry_hipchat_ac/models.py
def for_request(request, body=None):
        """Creates the context for a specific request."""
        tenant, jwt_data = Tenant.objects.for_request(request, body)
        webhook_sender_id = jwt_data.get('sub')
        sender_data = None

        if body and 'item' in body:
            if 'sender' in body['item']:
                sender_data = body['item']['sender']
            elif 'message' in body['item'] and 'from' in body['item']['message']:
                sender_data = body['item']['message']['from']

        if sender_data is None:
            if webhook_sender_id is None:
                raise BadTenantError('Cannot identify sender in tenant')
            sender_data = {'id': webhook_sender_id}

        return Context(
            tenant=tenant,
            sender=HipchatUser(
                id=sender_data.get('id'),
                name=sender_data.get('name'),
                mention_name=sender_data.get('mention_name'),
            ),
            signed_request=request.GET.get('signed_request'),
            context=jwt_data.get('context') or {},
        )
def for_request(request, body=None):
        tenant, jwt_data = Tenant.objects.for_request(request, body)
        webhook_sender_id = jwt_data.get('sub')
        sender_data = None

        if body and 'item' in body:
            if 'sender' in body['item']:
                sender_data = body['item']['sender']
            elif 'message' in body['item'] and 'from' in body['item']['message']:
                sender_data = body['item']['message']['from']

        if sender_data is None:
            if webhook_sender_id is None:
                raise BadTenantError('Cannot identify sender in tenant')
            sender_data = {'id': webhook_sender_id}

        return Context(
            tenant=tenant,
            sender=HipchatUser(
                id=sender_data.get('id'),
                name=sender_data.get('name'),
                mention_name=sender_data.get('mention_name'),
            ),
            signed_request=request.GET.get('signed_request'),
            context=jwt_data.get('context') or {},
        )
def for_request ( request , body = None ) : tenant , jwt_data = Tenant . objects . for_request ( request , body ) webhook_sender_id = jwt_data . get ( 'sub' ) sender_data = None if body and 'item' in body : if 'sender' in body [ 'item' ] : sender_data = body [ 'item' ] [ 'sender' ] elif 'message' in body [ 'item' ] and 'from' in body [ 'item' ] [ 'message' ] : sender_data = body [ 'item' ] [ 'message' ] [ 'from' ] if sender_data is None : if webhook_sender_id is None : raise BadTenantError ( 'Cannot identify sender in tenant' ) sender_data = { 'id' : webhook_sender_id } return Context ( tenant = tenant , sender = HipchatUser ( id = sender_data . get ( 'id' ) , name = sender_data . get ( 'name' ) , mention_name = sender_data . get ( 'mention_name' ) , ) , signed_request = request . GET . get ( 'signed_request' ) , context = jwt_data . get ( 'context' ) or { } , )
Creates the context for a specific request.
Creates the context for a specific request .