Skip to content

Commit

Permalink
Backend for private repo
Browse files Browse the repository at this point in the history
- Adds repo type field to the model
- Adds signed and unsigned NDA fields to the models
- Adds DRF backend for repo type field
- Adds filter for issue explorer
  • Loading branch information
SaptakS committed Feb 14, 2019
1 parent 2a42ed0 commit 0a28d58
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 8 deletions.
9 changes: 8 additions & 1 deletion app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import requests
from avatar.models import SocialAvatar
from avatar.utils import get_user_github_avatar_image
from dashboard.models import Profile
from geoip2.errors import AddressNotFoundError
from git.utils import _AUTH, HEADERS, get_user
from ipware.ip import get_real_ip
Expand Down Expand Up @@ -161,6 +160,7 @@ def setup_lang(request, user):
DoesNotExist: The exception is raised if no profile is found for the specified handle.
"""
from dashboard.models import Profile
profile = None
if user.is_authenticated and hasattr(user, 'profile'):
profile = user.profile
Expand All @@ -174,7 +174,14 @@ def setup_lang(request, user):
request.session.modified = True


def get_upload_filename(instance, filename):
salt = token_hex(16)
file_path = os.path.basename(filename)
return f"docs/{getattr(instance, '_path', '')}/{salt}/{file_path}"


def sync_profile(handle, user=None, hide_profile=True):
from dashboard.models import Profile
handle = handle.strip().replace('@', '')
data = get_user(handle)
email = ''
Expand Down
4 changes: 3 additions & 1 deletion app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ $(document).ready(function() {
estimatedHours: data.hours,
fundingOrganisation: data.fundingOrganisation,
is_featured: data.featuredBounty,
repo_type: data.repo_type,
reservedFor: reservedFor ? reservedFor.text : '',
tokenName
};
Expand Down Expand Up @@ -285,7 +286,8 @@ $(document).ready(function() {
jobDescription: data.jobDescription
},
funding_organisation: metadata.fundingOrganisation,
is_featured: metadata.featuredBounty,
is_featured: metadata.is_featured,
repo_type: metadata.repo_type,
featuring_date: metadata.featuredBounty && new Date().getTime() / 1000 || 0,
privacy_preferences: privacy_preferences,
funders: [],
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def create_new_bounty(old_bounties, bounty_payload, bounty_details, bounty_id):
'featuring_date': timezone.make_aware(
timezone.datetime.fromtimestamp(metadata.get('featuring_date')),
timezone=UTC),
'repo_type': metadata.get('repo_type', None),
'bounty_owner_github_username': bounty_issuer.get('githubUsername', ''),
'bounty_owner_address': bounty_issuer.get('address', ''),
'bounty_owner_email': bounty_issuer.get('email', ''),
Expand All @@ -446,7 +447,7 @@ def create_new_bounty(old_bounties, bounty_payload, bounty_details, bounty_id):
'bounty_owner_github_username', 'bounty_owner_address', 'bounty_owner_email', 'bounty_owner_name',
'github_comments', 'override_status', 'last_comment_date', 'snooze_warnings_for_days',
'admin_override_and_hide', 'admin_override_suspend_auto_approval', 'admin_mark_as_remarket_ready',
'funding_organisation', 'bounty_reserved_for_user', 'is_featured', 'featuring_date',
'funding_organisation', 'bounty_reserved_for_user', 'is_featured', 'featuring_date', 'repo_type',
],
)
if latest_old_bounty_dict['bounty_reserved_for_user']:
Expand Down
34 changes: 34 additions & 0 deletions app/dashboard/migrations/0014_auto_20190214_0916.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 2.1.5 on 2019-02-14 09:16

import app.utils
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0013_bounty_featuring_date'),
]

operations = [
migrations.AddField(
model_name='bounty',
name='repo_type',
field=models.CharField(choices=[('public', 'public'), ('private', 'private')], default='public', max_length=50),
),
migrations.AddField(
model_name='bounty',
name='unsigned_nda',
field=models.FileField(blank=True, help_text='NDA for private repos.', null=True, upload_to=app.utils.get_upload_filename),
),
migrations.AddField(
model_name='interest',
name='nda_signed',
field=models.FileField(blank=True, help_text='NDA signed by applicant.', null=True, upload_to=app.utils.get_upload_filename),
),
migrations.AlterField(
model_name='profile',
name='resume',
field=models.FileField(blank=True, help_text='The profile resume.', null=True, upload_to=app.utils.get_upload_filename),
),
]
11 changes: 9 additions & 2 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

import pytz
import requests
from avatar.utils import get_upload_filename
from app.utils import get_upload_filename
from dashboard.tokens import addr_to_token
from economy.models import ConversionRate, SuperModel
from economy.utils import ConversionRateNotFoundError, convert_amount, convert_token_to_usdt
Expand Down Expand Up @@ -175,6 +175,10 @@ class Bounty(SuperModel):
('permissionless', 'permissionless'),
('approval', 'approval'),
]
REPO_TYPES = [
('public', 'public'),
('private', 'private'),
]
PROJECT_TYPES = [
('traditional', 'traditional'),
('contest', 'contest'),
Expand Down Expand Up @@ -268,10 +272,12 @@ class Bounty(SuperModel):
canceled_bounty_reason = models.TextField(default='', blank=True, verbose_name=_('Cancelation reason'))
project_type = models.CharField(max_length=50, choices=PROJECT_TYPES, default='traditional')
permission_type = models.CharField(max_length=50, choices=PERMISSION_TYPES, default='permissionless')
repo_type = models.CharField(max_length=50, choices=REPO_TYPES, default='public')
snooze_warnings_for_days = models.IntegerField(default=0)
is_featured = models.BooleanField(
default=False, help_text=_('Whether this bounty is featured'))
featuring_date = models.DateTimeField(blank=True, null=True)
unsigned_nda = models.FileField(upload_to=get_upload_filename, null=True, blank=True, help_text=_('NDA for private repos.'))

token_value_time_peg = models.DateTimeField(blank=True, null=True)
token_value_in_usdt = models.DecimalField(default=0, decimal_places=2, max_digits=50, blank=True, null=True)
Expand Down Expand Up @@ -1455,6 +1461,7 @@ class Interest(models.Model):
max_length=7,
help_text=_('Whether or not the interest requires review'),
verbose_name=_('Needs Review'))
nda_signed = models.FileField(upload_to=get_upload_filename, null=True, blank=True, help_text=_('NDA signed by applicant.'))

# Interest QuerySet Manager
objects = InterestQuerySet.as_manager()
Expand Down Expand Up @@ -1746,7 +1753,7 @@ class Profile(SuperModel):
job_salary = models.DecimalField(default=1, decimal_places=2, max_digits=50)
job_location = JSONField(default=dict)
linkedin_url = models.CharField(max_length=255, default='', blank=True, null=True)
resume = models.FileField(upload_to=get_upload_filename, null=True, blank=True, help_text=_('The avatar SVG.'))
resume = models.FileField(upload_to=get_upload_filename, null=True, blank=True, help_text=_('The profile resume.'))

objects = ProfileQuerySet.as_manager()

Expand Down
7 changes: 6 additions & 1 deletion app/dashboard/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Meta:
'fulfillment_submitted_on', 'fulfillment_started_on', 'canceled_on', 'canceled_bounty_reason',
'action_urls', 'project_type', 'permission_type', 'attached_job_description', 'needs_review',
'github_issue_state', 'is_issue_closed', 'additional_funding_summary', 'funding_organisation', 'paid',
'admin_override_suspend_auto_approval', 'reserved_for_user_handle', 'is_featured', 'featuring_date',
'admin_override_suspend_auto_approval', 'reserved_for_user_handle', 'is_featured', 'featuring_date', 'repo_type',
)

def create(self, validated_data):
Expand Down Expand Up @@ -256,6 +256,11 @@ def get_queryset(self):
queryset = queryset.filter(
is_featured=self.request.query_params.get('is_featured'),
)

if 'repo_type' in param_keys:
queryset = queryset.filter(
repo_type=self.request.query_params.get('repo_type'),
)

# order
order_by = self.request.query_params.get('order_by')
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/templates/bounty/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ <h1 class="text-center title">{% trans "Fund Issue" %}</h1>
<div>
Github Repo Type
<div class="form__radio option">
<input name="repo_type" id="public_repo" type="radio" value="Public repo" checked />
<input name="repo_type" id="public_repo" type="radio" value="public" checked />
<label class="filter-label" for=public_repo><i class="fas fa-book"></i> {% trans "Public" %}</label>
</div>

<div class="form__radio option">
<input name="repo_type" id="private_repo" type="radio" value="Private repo" />
<input name="repo_type" id="private_repo" type="radio" value="private" />
<label class="filter-label" for=private_repo><i class="fas fa-lock"></i> {% trans "Private" %}</label>
</div>

Expand Down

0 comments on commit 0a28d58

Please sign in to comment.