Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
octavioamu committed Sep 7, 2021
2 parents 132069c + 7070b51 commit 78667f4
Show file tree
Hide file tree
Showing 24 changed files with 313 additions and 529 deletions.
8 changes: 8 additions & 0 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,11 @@ def notion_api_call(url='', payload=None):

# return success as dict
return response


def allow_all_origins(response):
"""Pass in a response and add header to allow all CORs requests"""

response["Access-Control-Allow-Origin"] = "*"

return response
8 changes: 4 additions & 4 deletions app/assets/v2/js/pages/change_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ $(document).ready(function() {

const denomination = $('input[name=denomination]').val();

setTimeout(() => setUsdAmount(denomination), 1000);
setTimeout(() => setUsdAmount(denomination, false), 1000);

$('input[name=hours]').keyup(() => setUsdAmount(denomination));
$('input[name=hours]').blur(() => setUsdAmount(denomination));
$('input[name=amount]').keyup(() => setUsdAmount(denomination));
$('input[name=hours]').keyup(() => setUsdAmount(denomination, false));
$('input[name=hours]').blur(() => setUsdAmount(denomination, false));
$('input[name=amount]').keyup(() => setUsdAmount(denomination, false));

$('input[name=usd_amount]').on('focusin', function() {
$('input[name=usd_amount]').attr('prev_usd_amount', $(this).val());
Expand Down
9 changes: 6 additions & 3 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,16 +668,19 @@ this.actions_page_warn_if_not_on_same_network = function() {

attach_change_element_type();

this.setUsdAmount = function(givenDenomination) {
this.setUsdAmount = function(givenDenomination, approx = true) {
const amount = $('input[name=amount]').val();
const denomination = givenDenomination || $('#token option:selected').text();

getUSDEstimate(amount, denomination, function(estimate) {
if (estimate['value']) {

const key = approx ? 'value' : 'value_unrounded';

if (estimate[key]) {
$('#usd-amount-wrapper').show();
$('#usd_amount_text').show();

$('#usd_amount').val(estimate['value']);
$('#usd_amount').val(estimate[key]);
$('#usd_amount_text').html(estimate['rate_text']);
$('#usd_amount').removeAttr('disabled');
} else {
Expand Down
9 changes: 1 addition & 8 deletions app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
Activity, BlockedURLFilter, Bounty, BountyEvent, BountyFulfillment, BountyInvites, BountySyncRequest, Coupon,
HackathonEvent, UserAction,
)
from dashboard.notifications import (
maybe_market_to_email, maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack,
notify_of_lowball_bounty,
)
from dashboard.notifications import maybe_market_to_email, maybe_market_to_github, notify_of_lowball_bounty
from dashboard.tokens import addr_to_token
from economy.utils import convert_amount
from git.utils import get_issue_details, get_url_dict, org_name
Expand Down Expand Up @@ -960,8 +957,6 @@ def process_bounty_changes(old_bounty, new_bounty):
# marketing
if event_name != 'unknown_event':
print("============ posting ==============")
did_post_to_slack = maybe_market_to_slack(new_bounty, event_name)
did_post_to_user_slack = maybe_market_to_user_slack(new_bounty, event_name)
did_post_to_github = maybe_market_to_github(new_bounty, event_name, profile_pairs)
did_post_to_email = maybe_market_to_email(new_bounty, event_name)
print("============ done posting ==============")
Expand All @@ -971,8 +966,6 @@ def process_bounty_changes(old_bounty, new_bounty):
'did_bsr': did_bsr,
'did_post_to_email': did_post_to_email,
'did_post_to_github': did_post_to_github,
'did_post_to_slack': did_post_to_slack,
'did_post_to_user_slack': did_post_to_user_slack,
'did_post_to_twitter': False,
}

Expand Down
33 changes: 33 additions & 0 deletions app/dashboard/migrations/0185_auto_20210823_2105.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.2.24 on 2021-08-23 21:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0184_hackathonevent_total_prize'),
]

operations = [
migrations.AlterField(
model_name='bounty',
name='web3_type',
field=models.CharField(choices=[('legacy_gitcoin', 'Legacy Bounty'), ('bounties_network', 'Bounties Network'), ('qr', 'QR Code'), ('web3_modal', 'Web3 Modal'), ('polkadot_ext', 'Polkadot Ext'), ('binance_ext', 'Binance Ext'), ('harmony_ext', 'Harmony Ext'), ('rsk_ext', 'RSK Ext'), ('xinfin_ext', 'Xinfin Ext'), ('nervos_ext', 'Nervos Ext'), ('algorand_ext', 'Algorand Ext'), ('sia_ext', 'Sia Ext'), ('tezos_ext', 'Tezos Ext'), ('casper_ext', 'Casper Ext'), ('fiat', 'Fiat'), ('manual', 'Manual')], default='bounties_network', max_length=50),
),
migrations.AlterField(
model_name='bountyfulfillment',
name='payout_type',
field=models.CharField(blank=True, choices=[('bounties_network', 'bounties_network'), ('qr', 'qr'), ('fiat', 'fiat'), ('web3_modal', 'web3_modal'), ('polkadot_ext', 'polkadot_ext'), ('binance_ext', 'binance_ext'), ('harmony_ext', 'harmony_ext'), ('rsk_ext', 'rsk_ext'), ('xinfin_ext', 'xinfin_ext'), ('nervos_ext', 'nervos_ext'), ('algorand_ext', 'algorand_ext'), ('sia_ext', 'sia_ext'), ('tezos_ext', 'tezos_ext'), ('casper_ext', 'casper_ext'), ('manual', 'manual')], help_text='payment type used to make the payment', max_length=20, null=True),
),
migrations.AlterField(
model_name='bountyfulfillment',
name='tenant',
field=models.CharField(blank=True, choices=[('BTC', 'BTC'), ('ETH', 'ETH'), ('ETC', 'ETC'), ('ZIL', 'ZIL'), ('CELO', 'CELO'), ('PYPL', 'PYPL'), ('POLKADOT', 'POLKADOT'), ('BINANCE', 'BINANCE'), ('HARMONY', 'HARMONY'), ('FILECOIN', 'FILECOIN'), ('RSK', 'RSK'), ('XINFIN', 'XINFIN'), ('NERVOS', 'NERVOS'), ('ALGORAND', 'ALGORAND'), ('SIA', 'SIA'), ('TEZOS', 'TEZOS'), ('CASPER', 'CASPER'), ('OTHERS', 'OTHERS')], help_text='specific tenant type under the payout_type', max_length=10, null=True),
),
migrations.AlterField(
model_name='profile',
name='trust_profile',
field=models.BooleanField(default=False, help_text='If this option is chosen, the user is able to submit a ens domain registration even if they are new to github'),
),
]
4 changes: 1 addition & 3 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
from unidecode import unidecode
from web3 import Web3

from .notifications import maybe_market_to_github, maybe_market_to_slack, maybe_market_to_user_slack
from .notifications import maybe_market_to_github
from .signals import m2m_changed_interested

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -2195,8 +2195,6 @@ def auto_user_approve(interest, bounty):
interest.acceptance_date = timezone.now()
start_work_approved(interest, bounty)
maybe_market_to_github(bounty, 'work_started', profile_pairs=bounty.profile_pairs)
maybe_market_to_slack(bounty, 'worker_approved')
maybe_market_to_user_slack(bounty, 'worker_approved')


@receiver(post_save, sender=Interest, dispatch_uid="psave_interest")
Expand Down
192 changes: 0 additions & 192 deletions app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,148 +83,6 @@ def github_org_to_twitter_tags(github_org):
return twitter_tags


def maybe_market_to_twitter(bounty, event_name):
"""Tweet the specified Bounty event.
Args:
bounty (dashboard.models.Bounty): The Bounty to be marketed.
event_name (str): The name of the event.
Returns:
bool: Whether or not the twitter notification was sent successfully.
"""
if not bounty.is_notification_eligible(var_to_check=settings.TWITTER_CONSUMER_KEY):
return False

api = twitter.Api(
consumer_key=settings.TWITTER_CONSUMER_KEY,
consumer_secret=settings.TWITTER_CONSUMER_SECRET,
access_token_key=settings.TWITTER_ACCESS_TOKEN,
access_token_secret=settings.TWITTER_ACCESS_SECRET,
)
tweet_txts = [
"Earn {} {} {} now by completing this task: \n\n{}",
"Oppy to earn {} {} {} for completing this task: \n\n{}",
"Is today the day you (a) boost your OSS rep (b) make some extra cash? 🤔 {} {} {} \n\n{}",
]
if event_name == 'remarket_bounty':
tweet_txts = tweet_txts + [
"Gitcoin open task of the day is worth {} {} {} ⚡️ \n\n{}",
"Task of the day 💰 {} {} {} ⚡️ \n\n{}",
]
elif event_name == 'new_bounty':
tweet_txts = tweet_txts + [
"Extra! Extra 🗞🗞 New Funded Issue, Read all about it 👇 {} {} {} \n\n{}",
"Hot off the blockchain! 🔥🔥🔥 There's a new task worth {} {} {} \n\n{}",
"💰 New Task Alert.. 💰 Earn {} {} {} for working on this 👇 \n\n{}",
]
elif event_name == 'increased_bounty':
tweet_txts = [
'Increased Payout on {} {} {}\n{}'
]
elif event_name == 'start_work':
tweet_txts = [
'Work started on {} {} {}\n{}'
]
elif event_name == 'stop_work':
tweet_txts = [
'Work stopped on {} {} {}\n{}'
]
elif event_name == 'work_done':
tweet_txts = [
'Work done on {} {} {}\n{}'
]
elif event_name == 'work_submitted':
tweet_txts = [
'Work submitted on {} {} {}\n{}'
]
elif event_name == 'killed_bounty':
tweet_txts = [
'Bounty killed on {} {} {}\n{}'
]
elif event_name == 'worker_rejected':
tweet_txts = [
'Worked rejected on {} {} {}\n{}'
]
elif event_name == 'worker_approved':
tweet_txts = [
'Worked approved on {} {} {}\n{}'
]

random.shuffle(tweet_txts)
tweet_txt = tweet_txts[0]
utm = ''
if bounty.metadata.get('hyper_tweet_counter', False):
utm = f'utm_source=hypercharge-auto&utm_medium=twitter&utm_campaign={bounty.title}'

url = f'{bounty.get_absolute_url()}?{utm}'
is_short = False
for shortener in ['Tinyurl', 'Adfly', 'Isgd', 'QrCx']:
try:
if not is_short:
shortener = Shortener(shortener)
response = shortener.short(url)
if response != 'Error' and 'http' in response:
url = response
is_short = True
except Exception:
pass

new_tweet = tweet_txt.format(
round(bounty.get_natural_value(), 4),
bounty.token_name,
f"({bounty.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})" if bounty.value_in_usdt_now else "",
url
)
new_tweet = new_tweet + " " + github_org_to_twitter_tags(bounty.org_name) # twitter tags
if bounty.keywords: # hashtags
for keyword in bounty.keywords.split(','):
_new_tweet = new_tweet + " #" + str(keyword).lower().strip()
if len(_new_tweet) < 140:
new_tweet = _new_tweet

try:
api.PostUpdate(new_tweet)
except Exception as e:
print(e)
return False
return True


def maybe_market_to_slack(bounty, event_name):
"""Send a Slack message for the specified Bounty.
Args:
bounty (dashboard.models.Bounty): The Bounty to be marketed.
event_name (str): The name of the event.
Returns:
bool: Whether or not the Slack notification was sent successfully.
"""
if not bounty.is_notification_eligible(var_to_check=settings.SLACK_TOKEN):
return False

msg = build_message_for_integration(bounty, event_name)
if not msg:
return False

try:
channel = 'notif-gitcoin'
sc = SlackClient(settings.SLACK_TOKEN)
sc.api_call(
"chat.postMessage",
channel=channel,
text=msg,
icon_url=settings.GITCOIN_SLACK_ICON_URL,
)
except Exception as e:
print(e)
return False
return True


def build_message_for_integration(bounty, event_name):
"""Build message to be posted to integrated service (e.g. slack).
Expand Down Expand Up @@ -257,56 +115,6 @@ def build_message_for_integration(bounty, event_name):
return msg


def maybe_market_to_user_slack(bounty, event_name):
from dashboard.tasks import maybe_market_to_user_slack
maybe_market_to_user_slack.delay(bounty.pk, event_name)


def maybe_market_to_user_slack_helper(bounty, event_name):
"""Send a Slack message to the user's slack channel for the specified Bounty.
Args:
bounty (dashboard.models.Bounty): The Bounty to be marketed.
event_name (str): The name of the event.
Returns:
bool: Whether or not the Slack notification was sent successfully.
"""
from dashboard.models import Profile
if bounty.get_natural_value() < 0.0001:
return False
if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK:
return False

msg = build_message_for_integration(bounty, event_name)
if not msg:
return False

url = bounty.github_url
sent = False
try:
repo = org_name(url) + '/' + repo_name(url)
subscribers = Profile.objects.filter(slack_repos__contains=[repo])
subscribers = subscribers & Profile.objects.exclude(slack_token='', slack_channel='')
for subscriber in subscribers:
try:
sc = SlackClient(subscriber.slack_token)
sc.api_call(
"chat.postMessage",
channel=subscriber.slack_channel,
text=msg,
icon_url=settings.GITCOIN_SLACK_ICON_URL,
)
sent = True
except Exception as e:
print(e)
except Exception as e:
print(e)

return sent


def maybe_market_tip_to_email(tip, emails):
"""Send an email for the specified Tip.
Expand Down
14 changes: 0 additions & 14 deletions app/dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,6 @@ def update_trust_bonus(self, pk):
profile.save()


@app.shared_task(bind=True)
def maybe_market_to_user_slack(self, bounty_pk, event_name, retry: bool = True) -> None:
"""
:param self:
:param bounty_pk:
:param event_name:
:return:
"""
with redis.lock("maybe_market_to_user_slack:bounty", timeout=LOCK_TIMEOUT):
bounty = Bounty.objects.get(pk=bounty_pk)
from dashboard.notifications import maybe_market_to_user_slack_helper
maybe_market_to_user_slack_helper(bounty, event_name)


@app.shared_task(bind=True, soft_time_limit=600, time_limit=660, max_retries=3)
def grant_update_email_task(self, pk, retry: bool = True) -> None:
"""
Expand Down
3 changes: 0 additions & 3 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
from web3.middleware import geth_poa_middleware

from .abi import erc20_abi
from .notifications import maybe_market_to_slack

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1054,8 +1053,6 @@ def re_market_bounty(bounty, auto_save = True):
if auto_save:
bounty.save()

maybe_market_to_slack(bounty, 'issue_remarketed')

result_msg = 'The issue will appear at the top of the issue explorer. '
further_permitted_remarket_count = settings.RE_MARKET_LIMIT - bounty.remarketed_count
if further_permitted_remarket_count >= 1:
Expand Down
Loading

0 comments on commit 78667f4

Please sign in to comment.