def bounty_details(request, ghuser='', ghrepo='', ghissue=0): """Display the bounty details.""" _access_token = request.session.get('access_token') profile_id = request.session.get('profile_id') issueURL = 'https://github.com/' + ghuser + '/' + ghrepo + '/issues/' + ghissue if ghissue else request.GET.get( 'url') # try the /pulls url if it doesnt exist in /issues try: assert Bounty.objects.current().filter(github_url=issueURL).exists() except: issueURL = 'https://github.com/' + ghuser + '/' + ghrepo + '/pull/' + ghissue if ghissue else request.GET.get( 'url') print(issueURL) pass bounty_url = issueURL params = { 'issueURL': issueURL, 'title': 'Issue Details', 'card_title': 'Funded Issue Details | Gitcoin', 'avatar_url': static('v2/images/helmet.png'), 'active': 'bounty_details', 'is_github_token_valid': is_github_token_valid(_access_token), 'github_auth_url': get_auth_url(request.path), 'profile_interested': False, "newsletter_headline": "Be the first to know about new funded issues." } if bounty_url: try: bounties = Bounty.objects.current().filter(github_url=bounty_url) if bounties: bounty = bounties.order_by('pk').first() # Currently its not finding anyting in the database if bounty.title and bounty.org_name: params[ 'card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin' params['title'] = params['card_title'] params['card_desc'] = ellipses( bounty.issue_description_text, 255) params['bounty_pk'] = bounty.pk params[ 'interested_profiles'] = bounty.interested.select_related( 'profile').all() params['avatar_url'] = bounty.local_avatar_url if profile_id: profile_ids = list( params['interested_profiles'].values_list('profile_id', flat=True)) params['profile_interested'] = request.session.get( 'profile_id') in profile_ids except Bounty.DoesNotExist: pass except Exception as e: print(e) logging.error(e) return TemplateResponse(request, 'bounty_details.html', params)
def github_authentication(request): """Handle Github authentication.""" redirect_uri = request.GET.get('redirect_uri', '/') if not request.session.get('access_token'): return redirect(get_auth_url(redirect_uri)) response = redirect(redirect_uri) response.set_cookie('last_github_auth_mutation', int(time.time())) return response
def github_authentication(request): """Handle Github authentication.""" redirect_uri = request.GET.get('redirect_uri', '/') if not request.session.get('access_token'): return redirect(get_auth_url(redirect_uri)) response = redirect(redirect_uri) response.set_cookie('last_github_auth_mutation', int(time.time())) return response
def test_get_auth_url(self): """Test the github utility get_auth_url method.""" redirect = '/funding/new' github_callback = reverse('github:github_callback') redirect_params = {'redirect_uri': BASE_URI + redirect} redirect_uri = urlencode(redirect_params, quote_via=quote_plus) params = { 'client_id': settings.GITHUB_CLIENT_ID, 'scope': settings.GITHUB_SCOPE, 'redirect_uri': f'{BASE_URI}{github_callback}?{redirect_uri}' } auth_url = urlencode(params, quote_via=quote_plus) assert get_auth_url(redirect) == f'{settings.GITHUB_AUTH_BASE_URL}?{auth_url}'
def bounty_details(request): """Display the bounty details.""" _access_token = request.session.get('access_token') profile_id = request.session.get('profile_id') bounty_url = request.GET.get('url') params = { 'issueURL': request.GET.get('issue_'), 'title': 'Issue Details', 'card_title': 'Funded Issue Details | Gitcoin', 'avatar_url': 'https://gitcoin.co/static/v2/images/helmet.png', 'active': 'bounty_details', 'is_github_token_valid': is_github_token_valid(_access_token), 'github_auth_url': get_auth_url(request.path), 'profile_interested': False, "newsletter_headline": "Be the first to know about new funded issues." } if bounty_url: try: bounties = Bounty.objects.current().filter(github_url=bounty_url) if bounties: bounty = bounties.order_by('pk').first() # Currently its not finding anyting in the database if bounty.title and bounty.org_name: params[ 'card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin' params['title'] = params['card_title'] params['card_desc'] = ellipses( bounty.issue_description_text, 255) params['bounty_pk'] = bounty.pk params[ 'interested_profiles'] = bounty.interested.select_related( 'profile').all() params['avatar_url'] = bounty.local_avatar_url params[ 'is_legacy'] = bounty.is_legacy # TODO: Remove this following legacy contract sunset. if profile_id: profile_ids = list( params['interested_profiles'].values_list('profile_id', flat=True)) params['profile_interested'] = request.session.get( 'profile_id') in profile_ids except Bounty.DoesNotExist: pass except Exception as e: print(e) logging.error(e) return TemplateResponse(request, 'bounty_details.html', params)
def github_authentication(request): """Handle Github authentication.""" redirect_uri = request.GET.get('redirect_uri', '/') if not request.session.get('access_token'): return redirect(get_auth_url(redirect_uri)) # Alert local developer that Github integration needs configured. if settings.DEBUG and (not settings.GITHUB_CLIENT_ID or settings.GITHUB_CLIENT_ID == 'TODO'): logging.info('GITHUB_CLIENT_ID is not set. Github integration is disabled!') response = redirect(redirect_uri) response.set_cookie('last_github_auth_mutation', int(time.time())) return response
def test_get_auth_url(self): """Test the github utility get_auth_url method.""" redirect = '/funding/new' github_callback = reverse('github:github_callback') redirect_params = {'redirect_uri': BASE_URI + redirect} redirect_uri = urlencode(redirect_params, quote_via=quote_plus) params = { 'client_id': settings.GITHUB_CLIENT_ID, 'scope': settings.GITHUB_SCOPE, 'redirect_uri': f'{BASE_URI}{github_callback}?{redirect_uri}' } auth_url = urlencode(params, quote_via=quote_plus) assert get_auth_url( redirect) == f'{settings.GITHUB_AUTH_BASE_URL}?{auth_url}'
def bounty_details(request, ghuser='', ghrepo='', ghissue=0, stdbounties_id=None): """Display the bounty details. Args: ghuser (str): The Github user. Defaults to an empty string. ghrepo (str): The Github repository. Defaults to an empty string. ghissue (int): The Github issue number. Defaults to: 0. Raises: Exception: The exception is raised for any exceptions in the main query block. Returns: django.template.response.TemplateResponse: The Bounty details template response. """ is_user_authenticated = request.user.is_authenticated if is_user_authenticated and hasattr(request.user, 'profile'): _access_token = request.user.profile.get_access_token() else: _access_token = request.session.get('access_token') issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/issues/' + ghissue if ghissue else request.GET.get( 'url') # try the /pulls url if it doesnt exist in /issues try: assert Bounty.objects.current().filter(github_url=issue_url).exists() except Exception: issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/pull/' + ghissue if ghissue else request.GET.get( 'url') print(issue_url) params = { 'issueURL': issue_url, 'title': _('Issue Details'), 'card_title': _('Funded Issue Details | Gitcoin'), 'avatar_url': static('v2/images/helmet.png'), 'active': 'bounty_details', 'is_github_token_valid': is_github_token_valid(_access_token), 'github_auth_url': get_auth_url(request.path), "newsletter_headline": _("Be the first to know about new funded issues."), 'is_staff': request.user.is_staff, } if issue_url: try: bounties = Bounty.objects.current().filter(github_url=issue_url) if stdbounties_id: bounties.filter(standard_bounties_id=stdbounties_id) if bounties: bounty = bounties.order_by('-pk').first() if bounties.count() > 1 and bounties.filter( network='mainnet').count() > 1: bounty = bounties.filter( network='mainnet').order_by('-pk').first() # Currently its not finding anyting in the database if bounty.title and bounty.org_name: params[ 'card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin' params['title'] = params['card_title'] params['card_desc'] = ellipses( bounty.issue_description_text, 255) params['bounty_pk'] = bounty.pk params['network'] = bounty.network params['stdbounties_id'] = bounty.standard_bounties_id params[ 'interested_profiles'] = bounty.interested.select_related( 'profile').all() params['avatar_url'] = bounty.get_avatar_url(True) snooze_days = int(request.GET.get('snooze', 0)) if snooze_days: is_funder = bounty.is_funder(request.user.username.lower()) is_staff = request.user.is_staff if is_funder or is_staff: bounty.snooze_warnings_for_days = snooze_days bounty.save() messages.success( request, _(f'Warning messages have been snoozed for {snooze_days} days' )) else: messages.warning( request, _('Only the funder of this bounty may snooze warnings.' )) except Bounty.DoesNotExist: pass except Exception as e: print(e) logging.error(e) return TemplateResponse(request, 'bounty_details.html', params)
def bounty_details(request, ghuser='', ghrepo='', ghissue=0): """Display the bounty details. Args: ghuser (str): The Github user. Defaults to an empty string. ghrepo (str): The Github repository. Defaults to an empty string. ghissue (int): The Github issue number. Defaults to: 0. Raises: Exception: The exception is raised for any exceptions in the main query block. Returns: django.template.response.TemplateResponse: The Bounty details template response. """ is_user_authenticated = request.user.is_authenticated if is_user_authenticated and hasattr(request.user, 'profile'): _access_token = request.user.profile.get_access_token() else: _access_token = request.session.get('access_token') issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/issues/' + ghissue if ghissue else request.GET.get('url') # try the /pulls url if it doesnt exist in /issues try: assert Bounty.objects.current().filter(github_url=issue_url).exists() except Exception: issue_url = 'https://github.com/' + ghuser + '/' + ghrepo + '/pull/' + ghissue if ghissue else request.GET.get('url') print(issue_url) params = { 'issueURL': issue_url, 'title': _('Issue Details'), 'card_title': _('Funded Issue Details | Gitcoin'), 'avatar_url': static('v2/images/helmet.png'), 'active': 'bounty_details', 'is_github_token_valid': is_github_token_valid(_access_token), 'github_auth_url': get_auth_url(request.path), "newsletter_headline": _("Be the first to know about new funded issues."), } if issue_url: try: bounties = Bounty.objects.current().filter(github_url=issue_url) if bounties: bounty = bounties.order_by('pk').first() # Currently its not finding anyting in the database if bounty.title and bounty.org_name: params['card_title'] = f'{bounty.title} | {bounty.org_name} Funded Issue Detail | Gitcoin' params['title'] = params['card_title'] params['card_desc'] = ellipses(bounty.issue_description_text, 255) params['bounty_pk'] = bounty.pk params['interested_profiles'] = bounty.interested.select_related('profile').all() params['avatar_url'] = bounty.local_avatar_url except Bounty.DoesNotExist: pass except Exception as e: print(e) logging.error(e) return TemplateResponse(request, 'bounty_details.html', params)