Beispiel #1
0
 def get_user_messages(self, user):
     token = _build_jwt(get_user_model().objects.get(pk=user.pk))
     headers = {'Authorization': 'Bearer {}'.format(token)}
     url = '{}{}{}'.format(
         settings.EXOLEVER_HOST,
         settings.SERVICE_CONVERSATIONS_HOST,
         'api/{}/messages/'.format(user.uuid),
     )
     response = requests.get(url, headers=headers)
     is_client_error = status.is_client_error(response.status_code)
     is_server_error = status.is_server_error(response.status_code)
     if not is_server_error and not is_client_error:
         return response.json()
     else:
         return []
Beispiel #2
0
def get_projects(user):
    headers = {'Authorization': 'Bearer ' + _build_jwt(user)}
    url = '{}{}{}'.format(
        settings.EXOLEVER_HOST,
        settings.SERVICE_EXO_PROJECTS_HOST,
        URL_VIEW_PROJECT)
    if settings.POPULATOR_MODE:
        return []
    try:
        response = requests.get(url, headers=headers)
        assert response.status_code == requests.codes.ok
        return response.json()['results']
    except Exception as e:
        logger.error('Can not access to exo-projects service')
        logger.error('{}'.format(e))
        return []
Beispiel #3
0
    def get_user_opportunities(self, user):
        token = _build_jwt(get_user_model().objects.get(pk=user.pk))
        headers = {'Authorization': 'Bearer {}'.format(token)}
        url = '{}{}{}'.format(
            settings.EXOLEVER_HOST,
            settings.SERVICE_EXO_OPPORTUNITIES_HOST,
            'api/opportunity/?only_published_by_you=true',
        )
        response = requests.get(url, headers=headers)

        is_client_error = status.is_client_error(response.status_code)
        is_server_error = status.is_server_error(response.status_code)
        if not is_server_error and not is_client_error:
            return response.json()
        else:
            return []
def _get_authorization(user_from):
    token = _build_jwt(user_from)
    return {'Authorization': 'Bearer ' + token}