Exemplo n.º 1
0
def save_integration_tokens(user, task_id, provider):
    token_info = dict()
    if provider == GitHubProvider.id:
        social_token = get_social_token(user=user, provider=provider)
        if social_token:
            token_info = dict(token=social_token.token,
                              token_secret=social_token.token_secret,
                              token_expires_at=social_token.expires_at)
    else:
        app_integration = get_app_integration(user=user, provider=provider)
        if app_integration:
            token_info = dict(token=app_integration.token,
                              token_secret=app_integration.token_secret,
                              token_expires_at=app_integration.expires_at,
                              token_extra=app_integration.extra)

            if provider == APP_INTEGRATION_PROVIDER_SLACK:
                token_info.pop('token_secret')
                response = json.loads(app_integration.extra)
                if 'bot' in response:
                    token_info['bot_access_token'] = response['bot'].get(
                        'bot_access_token')
                    token_info['bot_user_id'] = response['bot'].get(
                        'bot_user_id')
            elif provider == APP_INTEGRATION_PROVIDER_HARVEST:
                token_info.pop('token_secret')
                token_info['refresh_token'] = app_integration.token_secret
    save_task_integration_meta(task_id, provider, token_info)
Exemplo n.º 2
0
def save_integration_tokens(user, task_id, provider):
    token_info = dict()
    if provider == GitHubProvider.id:
        social_token = get_social_token(user=user, provider=provider)
        if social_token:
            token_info = dict(
                token=social_token.token,
                token_secret=social_token.token_secret,
                token_expires_at=social_token.expires_at
            )
    else:
        app_integration = get_app_integration(user=user, provider=provider)
        if app_integration:
            token_info = dict(
                token=app_integration.token,
                token_secret=app_integration.token_secret,
                token_expires_at=app_integration.expires_at,
                token_extra=app_integration.extra
            )

            if provider == APP_INTEGRATION_PROVIDER_SLACK:
                token_info.pop('token_secret')
                response = json.loads(app_integration.extra)
                if 'bot' in response:
                    token_info['bot_access_token'] = response['bot'].get('bot_access_token')
                    token_info['bot_user_id'] = response['bot'].get('bot_user_id')
            elif provider == APP_INTEGRATION_PROVIDER_HARVEST:
                token_info.pop('token_secret')
                token_info['refresh_token'] = app_integration.token_secret
    save_task_integration_meta(task_id, provider, token_info)
Exemplo n.º 3
0
def get_integration_token(user, provider, task=None):
    if task:
        task_integration = get_task_integration(task, provider)
        if task_integration and task_integration.token:
            return GenericObject(
                **dict(token=task_integration.token,
                       token_secret=task_integration.token_secret,
                       extra=task_integration.token_extra))

    if provider == GitHubProvider.id:
        return get_social_token(user=user, provider=provider)
    else:
        return get_app_integration(user=user, provider=provider)
Exemplo n.º 4
0
def github_connect_callback(request):
    task_id = get_session_task(request)
    if task_id:
        social_token = get_social_token(user=request.user,
                                        provider=GitHubProvider.id)
        if not social_token:
            return Response({'status': 'Unauthorized'},
                            status.HTTP_401_UNAUTHORIZED)

        token_info = dict(token=social_token.token,
                          token_secret=social_token.token_secret,
                          token_expires_at=social_token.expires_at)

        save_task_integration_meta(task_id, GitHubProvider.id, token_info)

    return redirect(get_session_next_url(request, provider=GitHubProvider.id))
Exemplo n.º 5
0
def get_integration_token(user, provider, task=None):
    if task:
        task_integration = get_task_integration(task, provider)
        if task_integration and task_integration.token:
            return GenericObject(
                **dict(
                    token=task_integration.token,
                    token_secret=task_integration.token_secret,
                    extra=task_integration.token_extra
                )
            )

    if provider == GitHubProvider.id:
        return get_social_token(user=user, provider=provider)
    else:
        return get_app_integration(user=user, provider=provider)
Exemplo n.º 6
0
def github_connect_callback(request):
    task_id = get_session_task(request)
    if task_id:
        social_token = get_social_token(user=request.user, provider=GitHubProvider.id)
        if not social_token:
            return Response({'status': 'Unauthorized'}, status.HTTP_401_UNAUTHORIZED)

        token_info = dict(
            token=social_token.token,
            token_secret=social_token.token_secret,
            token_expires_at=social_token.expires_at
        )

        save_task_integration_meta(task_id, GitHubProvider.id, token_info)

    return redirect(get_session_next_url(request, provider=GitHubProvider.id))