Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows bounty URLs to be blocked #5430

Merged
merged 11 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app/redis_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings

from redis import Redis


Expand Down
2 changes: 1 addition & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import avatar.views
import bounty_requests.views
import credits.views
import chat.views
import credits.views
import dashboard.embed
import dashboard.gas_views
import dashboard.helpers
Expand Down
9 changes: 9 additions & 0 deletions app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,15 @@ $('#sync-issue').on('click', function(event) {
});

$('#issueURL').focusout(function() {
for (let i = 0; i <= document.blocked_urls.length; i++) {
let this_url_filter = document.blocked_urls[i];

if ($('input[name=issueURL]').val().toLowerCase().indexOf(this_url_filter.toLowerCase()) != -1) {
_alert('This repo is not bountyable at the request of the maintainer.');
$('input[name=issueURL]').val('');
return false;
}
}
if (isPrivateRepo) {
setPrivateForm();
var validated = $('input[name=issueURL]').val() == '' || !validURL($('input[name=issueURL]').val());
Expand Down
5 changes: 3 additions & 2 deletions app/chat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@


from django.conf import settings
from django.templatetags.static import static
from django.template.response import TemplateResponse
from django.templatetags.static import static
from django.utils.translation import gettext_lazy as _
import requests
from django.views.decorators.clickjacking import xframe_options_exempt

import requests


def embed(request):
"""Handle the chat embed view."""
Expand Down
9 changes: 5 additions & 4 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from django.utils.safestring import mark_safe

from .models import (
Activity, BlockedUser, Bounty, BountyFulfillment, BountyInvites, BountySyncRequest, CoinRedemption,
CoinRedemptionRequest, Coupon, Earning, FeedbackEntry, HackathonEvent, HackathonProject, HackathonRegistration,
HackathonSponsor, Interest, LabsResearch, PortfolioItem, Profile, ProfileView, RefundFeeRequest, SearchHistory,
Sponsor, Tip, TokenApproval, Tool, ToolVote, UserAction, UserVerificationModel,
Activity, BlockedURLFilter, BlockedUser, Bounty, BountyFulfillment, BountyInvites, BountySyncRequest,
CoinRedemption, CoinRedemptionRequest, Coupon, Earning, FeedbackEntry, HackathonEvent, HackathonProject,
HackathonRegistration, HackathonSponsor, Interest, LabsResearch, PortfolioItem, Profile, ProfileView,
RefundFeeRequest, SearchHistory, Sponsor, Tip, TokenApproval, Tool, ToolVote, UserAction, UserVerificationModel,
)


Expand Down Expand Up @@ -398,6 +398,7 @@ def sponsor(self, obj):
admin.site.register(UserAction, UserActionAdmin)
admin.site.register(Interest, InterestAdmin)
admin.site.register(Profile, ProfileAdmin)
admin.site.register(BlockedURLFilter, GeneralAdmin)
admin.site.register(Bounty, BountyAdmin)
admin.site.register(BountyFulfillment, BountyFulfillmentAdmin)
admin.site.register(BountySyncRequest, GeneralAdmin)
Expand Down
16 changes: 14 additions & 2 deletions app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

from app.utils import get_semaphore, sync_profile
from dashboard.models import (
Activity, Bounty, BountyDocuments, BountyFulfillment, BountyInvites, BountySyncRequest, Coupon, HackathonEvent,
UserAction,
Activity, BlockedURLFilter, Bounty, BountyDocuments, 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_discord,
Expand Down Expand Up @@ -247,6 +247,12 @@ class UnsupportedSchemaException(Exception):
pass


class UnsupportedRepoException(Exception):
"""Define unsupported repo exception handling."""

pass


def bounty_did_change(bounty_id, new_bounty_details):
"""Determine whether or not the Bounty has changed.

Expand Down Expand Up @@ -855,6 +861,12 @@ def process_bounty_changes(old_bounty, new_bounty):
"""
from dashboard.utils import build_profile_pairs
profile_pairs = None

# check for maintainer blocks
is_blocked = any([(ele.lower() in new_bounty.github_url.lower()) for ele in BlockedURLFilter.objects.values_list('expression', flat=True)])
if is_blocked:
raise UnsupportedRepoException("This repo is not bountyable at the request of the maintainer.")

# process bounty sync requests
did_bsr = False
for bsr in BountySyncRequest.objects.filter(processed=False, github_url=new_bounty.github_url).nocache():
Expand Down
27 changes: 27 additions & 0 deletions app/dashboard/migrations/0064_blockedurlfilter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 2.2.4 on 2019-11-20 15:37

from django.db import migrations, models
import economy.models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0063_bounty_state'),
]

operations = [
migrations.CreateModel(
name='BlockedURLFilter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('expression', models.CharField(help_text='the expression to search for in order to block that github url (or website)', max_length=255)),
('comment', models.TextField(blank=True)),
],
options={
'abstract': False,
},
),
]
8 changes: 8 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,14 @@ def __str__(self):
return self.name


class BlockedURLFilter(SuperModel):
expression = models.CharField(max_length=255, help_text='the expression to search for in order to block that github url (or website)')
comment = models.TextField(blank=True)

def __str__(self):
return self.expression


class HackathonRegistration(SuperModel):
"""Defines the Hackthon profiles registrations"""
name = models.CharField(max_length=255, help_text='Hackathon slug')
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.conf import settings

from app.redis_service import RedisService
from celery import app
from celery.utils.log import get_task_logger
from app.redis_service import RedisService
from dashboard.models import Profile
from marketing.mails import send_mail, func_name
from marketing.mails import func_name, send_mail
from retail.emails import render_share_bounty

logger = get_task_logger(__name__)
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/templates/bounty/fund.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ <h3 class="mt-3 mb-4 font-title-lg font-weight-semibold">

<script>
document.FEE_PERCENTAGE = {{ FEE_PERCENTAGE }};
document.blocked_urls = {{blocked_urls|safe}};
{% if expired_coupon %}
_alert({ message: 'This coupon has expired.' }, 'error');
{% endif %}
Expand Down
10 changes: 5 additions & 5 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@

from .helpers import get_bounty_data_for_activity, handle_bounty_views, load_files_in_directory
from .models import (
Activity, Bounty, BountyDocuments, BountyFulfillment, BountyInvites, CoinRedemption, CoinRedemptionRequest, Coupon,
Earning, FeedbackEntry, HackathonEvent, HackathonProject, HackathonRegistration, HackathonSponsor, Interest,
LabsResearch, PortfolioItem, Profile, ProfileSerializer, ProfileView, RefundFeeRequest, SearchHistory, Sponsor,
Subscription, Tool, ToolVote, UserAction, UserVerificationModel,
Activity, BlockedURLFilter, Bounty, BountyDocuments, BountyFulfillment, BountyInvites, CoinRedemption,
CoinRedemptionRequest, Coupon, Earning, FeedbackEntry, HackathonEvent, HackathonProject, HackathonRegistration,
HackathonSponsor, Interest, LabsResearch, PortfolioItem, Profile, ProfileSerializer, ProfileView, RefundFeeRequest,
SearchHistory, Sponsor, Subscription, Tool, ToolVote, UserAction, UserVerificationModel,
)
from .notifications import (
maybe_market_tip_to_email, maybe_market_tip_to_github, maybe_market_tip_to_slack, maybe_market_to_email,
Expand Down Expand Up @@ -3137,7 +3137,7 @@ def new_bounty(request):
title=_('Create Funded Issue'),
update=bounty_params,
)

params['blocked_urls'] = json.dumps(list(BlockedURLFilter.objects.all().values_list('expression', flat=True)))
params['FEE_PERCENTAGE'] = request.user.profile.fee_percentage if request.user.is_authenticated else 10

coupon_code = request.GET.get('coupon', False)
Expand Down
3 changes: 2 additions & 1 deletion app/taskapp/celery.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os

from django.apps import AppConfig, apps

from celery import Celery
from celery.signals import setup_logging
from django.apps import AppConfig, apps

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

Expand Down