Skip to content

Commit

Permalink
GITC-128: remove unused views (#9246)
Browse files Browse the repository at this point in the history
* clean dashboard views

* clean retail + tdi views
  • Loading branch information
chibie authored Jul 2, 2021
1 parent 5062a68 commit 8c1e2cb
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 168 deletions.
2 changes: 1 addition & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from decimal import Decimal
from functools import reduce
from logging import error
from unidecode import unidecode
from urllib.parse import urlsplit

from django.conf import settings
Expand Down Expand Up @@ -74,6 +73,7 @@
from marketing.models import EmailSupressionList, LeaderboardRank
from rest_framework import serializers
from townsquare.models import Offer, PinnedPost
from unidecode import unidecode
from web3 import Web3

from .notifications import maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/templatetags/slug.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django import template
from unidecode import unidecode
from django.utils.text import slugify

from unidecode import unidecode

register = template.Library()

@register.filter
Expand Down
98 changes: 1 addition & 97 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from copy import deepcopy
from datetime import datetime, timedelta
from decimal import Decimal
from unidecode import unidecode

from django.conf import settings
from django.contrib import messages
Expand Down Expand Up @@ -125,6 +124,7 @@
from retail.utils import programming_languages, programming_languages_full
from townsquare.models import Comment, PinnedPost
from townsquare.views import get_following_tribes, get_tags
from unidecode import unidecode
from web3 import HTTPProvider, Web3

from .export import (
Expand Down Expand Up @@ -318,11 +318,6 @@ def gh_login(request):

return redirect(redirect_url, backend='github')

@csrf_exempt
def gh_org_login(request):
"""Attempt to redirect the user to Github for authentication."""
return redirect('social:begin', backend='gh-custom')


def get_interest_modal(request):
bounty_id = request.GET.get('pk')
Expand Down Expand Up @@ -1042,21 +1037,6 @@ def set_project_notes(request):
return JsonResponse({})


@require_GET
def users_autocomplete(request):
max_items = 5
q = request.GET.get('q')
if q:
from haystack.query import SQ, SearchQuerySet
sqs = SearchQuerySet().autocomplete((SQ(first_name_auto=q) | SQ(last_name_auto=q) | SQ(handle_auto=q)))
results = [str(result.object) for result in sqs[:max_items]]
else:
results = []

return JsonResponse({
'results': results
})

@csrf_exempt
def output_users_to_csv(request):

Expand Down Expand Up @@ -4274,82 +4254,6 @@ def labs(request):
return TemplateResponse(request, 'labs.html', context)


@csrf_exempt
@ratelimit(key='ip', rate='5/m', method=ratelimit.UNSAFE, block=True)
def redeem_coin(request, shortcode):
if request.body:
status = 'OK'

body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
address = body['address']

try:
coin = CoinRedemption.objects.get(shortcode=shortcode)
address = Web3.toChecksumAddress(address)

if hasattr(coin, 'coinredemptionrequest'):
status = 'error'
message = 'Bad request'
else:
abi = json.loads('[{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"payable":false,"stateMutability":"nonpayable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[],"name":"MintFinished","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]')

# Instantiate Colorado Coin contract
contract = w3.eth.contract(coin.contract_address, abi=abi)

tx = contract.functions.transfer(address, coin.amount * 10**18).buildTransaction({
'nonce': w3.eth.getTransactionCount(settings.COLO_ACCOUNT_ADDRESS),
'gas': 100000,
'gasPrice': recommend_min_gas_price_to_confirm_in_time(5) * 10**9
})

signed = w3.eth.account.signTransaction(tx, settings.COLO_ACCOUNT_PRIVATE_KEY)
transaction_id = w3.eth.sendRawTransaction(signed.rawTransaction).hex()

CoinRedemptionRequest.objects.create(
coin_redemption=coin,
ip=get_ip(request),
sent_on=timezone.now(),
txid=transaction_id,
txaddress=address
)

message = transaction_id
except CoinRedemption.DoesNotExist:
status = 'error'
message = _('Bad request')
except Exception as e:
status = 'error'
message = str(e)

# http response
response = {
'status': status,
'message': message,
}

return JsonResponse(response)

try:
coin = CoinRedemption.objects.get(shortcode=shortcode)

params = {
'class': 'redeem',
'title': _('Coin Redemption'),
'coin_status': _('PENDING')
}

try:
coin_redeem_request = CoinRedemptionRequest.objects.get(coin_redemption=coin)
params['colo_txid'] = coin_redeem_request.txid
except CoinRedemptionRequest.DoesNotExist:
params['coin_status'] = _('INITIAL')

return TemplateResponse(request, 'yge/redeem_coin.html', params)
except CoinRedemption.DoesNotExist:
raise Http404


@login_required
def new_bounty(request):
"""Create a new bounty."""
Expand Down
4 changes: 0 additions & 4 deletions app/retail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,10 +1033,6 @@ def create_status_update(request):
return JsonResponse(response)


def grant_redir(request):
return redirect('/grants/')


def help(request):
return redirect('/support/')

Expand Down
65 changes: 0 additions & 65 deletions app/tdi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,71 +48,6 @@ def ratelimited(request, ratelimited=False):
return HttpResponseForbidden("You're ratelimited - Please try again soon", 403)


@ratelimit(key='ip', rate='5/m', method=ratelimit.UNSAFE, block=True)
def whitepaper_new(request, ratelimited=False):

context = {
'active': 'whitepaper',
'title': _('Whitepaper'),
'minihero': _('Whitepaper'),
'suppress_logo': True,
}
if not request.POST.get('submit', False):
return TemplateResponse(request, 'whitepaper_new.html', context)

if ratelimited:
context['msg'] = _("You're ratelimited. Please contact [email protected]")
return TemplateResponse(request, 'whitepaper_accesscode.html', context)

context['role'] = request.POST.getlist('role')
context['email'] = request.POST.get('email')
context['comments'] = request.POST.get('comments')
context['success'] = True
ip = get_ip(request)
body = gettext("""
Email: {} \n
Role: {}\n
Comments: {}\n
IP: {}\n
https://gitcoin.co/_administration/tdi/whitepaperaccessrequest/
""").format(context['email'], context['role'], context['comments'], ip)
send_mail(
settings.CONTACT_EMAIL,
settings.CONTACT_EMAIL,
_("New Whitepaper Request"),
str(body),
categories=['admin', 'whitepaper_request'],
)

WhitepaperAccessRequest.objects.create(
email=context['email'],
role=context['role'],
comments=context['comments'],
ip=ip,
)

for code in AccessCodes.objects.all():
print(code)

invite_to_slack(context['email'])

valid_email = True
try:
validate_email(request.POST.get('email', False))
except ValidationError:
valid_email = False

if not request.POST.get('email', False) or not valid_email:
context['msg'] = _("Invalid Email. Please contact [email protected]")
context['success'] = False
return TemplateResponse(request, 'whitepaper_new.html', context)

context['msg'] = _("Your request has been sent. <a href=/slack>Meantime, why don't you check out the slack channel?</a>")
return TemplateResponse(request, 'whitepaper_new.html', context)


@ratelimit(key='ip', rate='5/m', method=ratelimit.UNSAFE, block=True)
def whitepaper_access(request, ratelimited=False):

Expand Down

0 comments on commit 8c1e2cb

Please sign in to comment.