Skip to content

Commit fbf5af8

Browse files
authored
fix for regression around bounty mentor payloads (#7284)
* fix for regression around bounty mentor payloads * remove offending payload requirement and check * remove stale code * remove the manage-sponsor tab from the integrated hackathon view, fix check for is sponsor member in bounty_mentors request * remove check for can manage as its being moved to sponsor area * rename manage-sponsor component to manage mentors, migrate the component to the sponsor dashboard * fix for correct sponsor group
1 parent 9a63343 commit fbf5af8

5 files changed

Lines changed: 82 additions & 78 deletions

File tree

app/assets/v2/js/pages/dashboard-sponsors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
case 1:
120120
newPathName = 'stats';
121121
break;
122+
case 2:
123+
newPathName = 'mentors';
124+
break;
122125
}
123126
let newUrl = `/hackathon/dashboard/${vm.hackathonObj['slug']}/${newPathName}`;
124127

app/assets/v2/js/vue-components.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,23 +203,21 @@ Vue.component('tribes-settings', {
203203
methods: {}
204204
});
205205

206-
Vue.component('manage-sponsor', {
207-
props: ['hackathon_id'],
206+
Vue.component('manage-mentors', {
207+
props: [ 'hackathon_id', 'org_name' ],
208208
methods: {
209209
onMentorChange: function(event) {
210210

211211
this.bountyMentors = $('.mentor-users').select2('data').map(element => {
212212
return element.id;
213213
});
214-
console.log(event);
215-
console.log(this.bountyMentors);
216214
},
217215
updateBountyMentors: function() {
218216
let vm = this;
219217
const url = '/api/v0.1/bounty_mentor/';
220218

221219
const updateBountyMentor = fetchData(url, 'POST', JSON.stringify({
222-
has_overrides: false,
220+
bounty_org: vm.org_name,
223221
hackathon_id: vm.hackathon_id,
224222
set_default_mentors: true,
225223
new_default_mentors: vm.bountyMentors
@@ -238,7 +236,6 @@ Vue.component('manage-sponsor', {
238236
return element.id;
239237
});
240238

241-
console.log(this.bountyMentors);
242239
},
243240
data: function() {
244241
return {

app/dashboard/templates/dashboard/index-vue.html

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -761,32 +761,6 @@ <h4 class="font-bigger-1 font-weight-bold mb-3">[[hackathon.name]] Wall of Fame<
761761
</div>
762762

763763
</b-tab>
764-
{% if can_manage %}
765-
<b-tab class="col-12" title-item-class="navigation" lazy>
766-
<template v-slot:title>
767-
<div class="mt-4">
768-
{% trans "Dashboard" %}
769-
</div>
770-
</template>
771-
<manage-sponsor v-bind:hackathon_id="hackathonObj.id" inline-template>
772-
<div class="offset-3 col-6">
773-
<div class="from-group mb-3 mt-4">
774-
<label class="font-weight-semibold" for="org-mentors">Bounty Mentors (Optional) <small>Add Gitcoin/Github Usernames</small></label>
775-
<div class="form__select2 g-multiselect">
776-
<select id="org-mentors" class="mentor-users" multiple="multiple" aria-describedby="profilesHelp">
777-
{% for profile in default_mentors %}
778-
<option selected="selected" value="{{ profile.id }}">{{ profile }}</option>
779-
{% endfor %}
780-
</select>
781-
</div>
782-
</div>
783-
<div class="form-group mb-3 mt-4">
784-
<b-button @click="updateBountyMentors();">Update Mentors</b-button>
785-
</div>
786-
</div>
787-
</manage-sponsor>
788-
</b-tab>
789-
{% endif %}
790764
<template v-slot:tabs-end v-if="!hackHasEnded">
791765
<li role="presentation" class="nav-item navigation">
792766
<a href="{% url 'hackathon_onboard' hackathon.slug %}" class="text-reset text-decoration-none nav-link">

app/dashboard/templates/dashboard/sponsors.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
</div>
303303
</div>
304304
</b-tab>
305+
305306
<b-tab title-item-class="navigation">
306307
<template class="d-none" v-slot:title>
307308
<div class="mt-4">
@@ -315,6 +316,30 @@
315316
</div>
316317

317318
</b-tab>
319+
<b-tab title-item-class="navigation">
320+
<template class="d-none" v-slot:title>
321+
<div class="mt-4">
322+
{% trans "Mentors" %}
323+
</div>
324+
</template>
325+
<manage-mentors :org_name="userOrg.org_name" :hackathon_id="hackathonObj.id" inline-template>
326+
<div class="offset-3 col-6">
327+
<div class="from-group mb-3 mt-4">
328+
<label class="font-weight-semibold" for="org-mentors">Bounty Mentors (Optional) <small>Add Gitcoin/Github Usernames</small></label>
329+
<div class="form__select2 g-multiselect">
330+
<select id="org-mentors" class="mentor-users" multiple="multiple" aria-describedby="profilesHelp">
331+
{% for profile in default_mentors %}
332+
<option selected="selected" value="{{ profile.id }}">{{ profile }}</option>
333+
{% endfor %}
334+
</select>
335+
</div>
336+
</div>
337+
<div class="form-group mb-3 mt-4">
338+
<b-button @click="updateBountyMentors();">Update Mentors</b-button>
339+
</div>
340+
</div>
341+
</manage-mentors>
342+
</b-tab>
318343
</b-tabs>
319344
</div>
320345
</div>

app/dashboard/views.py

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,42 +1178,46 @@ def bounty_mentor(request):
11781178

11791179
body_unicode = request.body.decode('utf-8')
11801180
body = json.loads(body_unicode)
1181-
can_manage = request.user.profile.handle.lower() == body.bounty_org.lower()
1182-
1183-
if not can_manage:
1184-
return JsonResponse({'message': 'UNAUTHORIZED'}, status=401)
1185-
1186-
bounty_org_default_mentors = Group.objects.get_or_create(name=f'sponsor-org-{request.user.profile.handle.lower()}-mentors')[0]
1187-
message = f'Mentors Updated Successfully'
1188-
if body['set_default_mentors']:
1189-
current_mentors = Profile.objects.filter(user__groups=bounty_org_default_mentors)
1190-
mentors_to_remove = list(set([current.id for current in current_mentors]) - set(body['new_default_mentors']))
1191-
1192-
mentors_to_remove = Profile.objects.filter(id__in=mentors_to_remove)
1193-
for mentor_to_r in mentors_to_remove:
1194-
mentor_to_r.user.groups.remove(bounty_org_default_mentors)
1195-
1196-
mentors_to_add = Profile.objects.filter(id__in=body['new_default_mentors'])
1197-
for mentor in mentors_to_add:
1198-
mentor.user.groups.add(bounty_org_default_mentors)
1199-
1200-
if body['has_overrides']:
1201-
for key, val in body['overrides']:
1202-
bounty = Bounty.objects.get(id=key)
1203-
bounty_group = Group.objects.get_or_create(name=f'bounty-override-{key}-mentors')[0]
1204-
mentor_pks = [int(mentorpk) for mentorpk in val.mentors]
1205-
mentors = User.objects.filter(id__in=mentor_pks)
1206-
for mentor in mentors:
1207-
mentor.groups.add(bounty_group)
1208-
12091181
if body['hackathon_id']:
1210-
try:
1211-
hackathon_event = HackathonEvent.objects.get(id=int(body['hackathon_id']))
1212-
from chat.tasks import hackathon_chat_sync
1213-
hackathon_chat_sync.delay(hackathon_id=hackathon_event.id)
1214-
except Exception as e:
1215-
message = 'Hackathon does not exist'
1216-
logger.info(str(e))
1182+
1183+
hackathon_event = HackathonEvent.objects.get(id=int(body['hackathon_id']))
1184+
1185+
if body['bounty_org']:
1186+
sponsor = hackathon_event.sponsor_profiles.get(handle__iexact=body['bounty_org'])
1187+
else:
1188+
sponsor = None
1189+
1190+
if not hackathon_event:
1191+
return JsonResponse({'message': 'Event not Found'}, status=404)
1192+
1193+
profile = request.user.profile if request.user.is_authenticated and hasattr(request.user, 'profile') else None
1194+
1195+
print(sponsor)
1196+
is_sponsor_member = profile.organizations_fk.filter(pk=sponsor.pk)
1197+
1198+
if not is_sponsor_member:
1199+
return JsonResponse({'message': 'UNAUTHORIZED'}, status=401)
1200+
1201+
bounty_org_default_mentors = Group.objects.get_or_create(name=f'sponsor-org-{sponsor.handle.lower()}-mentors')[0]
1202+
message = f'Mentors Updated Successfully'
1203+
if body['set_default_mentors']:
1204+
current_mentors = Profile.objects.filter(user__groups=bounty_org_default_mentors)
1205+
mentors_to_remove = list(set([current.id for current in current_mentors]) - set(body['new_default_mentors']))
1206+
1207+
mentors_to_remove = Profile.objects.filter(id__in=mentors_to_remove)
1208+
for mentor_to_r in mentors_to_remove:
1209+
mentor_to_r.user.groups.remove(bounty_org_default_mentors)
1210+
1211+
mentors_to_add = Profile.objects.filter(id__in=body['new_default_mentors'])
1212+
for mentor in mentors_to_add:
1213+
mentor.user.groups.add(bounty_org_default_mentors)
1214+
1215+
try:
1216+
from chat.tasks import hackathon_chat_sync
1217+
hackathon_chat_sync.delay(hackathon_id=hackathon_event.id)
1218+
except Exception as e:
1219+
message = 'Hackathon does not exist'
1220+
logger.info(str(e))
12171221

12181222
return JsonResponse({'message': message}, status=200, safe=False)
12191223

@@ -3744,7 +3748,6 @@ def dashboard_sponsors(request, hackathon='', panel='prizes'):
37443748
static('v2/images/twitter_cards/tw_cards-02.png'))
37453749
network = get_default_network()
37463750
hackathon_not_started = timezone.now() < hackathon_event.start_date and not request.user.is_staff
3747-
print(sponsor_profile)
37483751
org = {
37493752
'display_name': sponsor_profile.name,
37503753
'avatar_url': sponsor_profile.avatar_url,
@@ -3759,6 +3762,8 @@ def dashboard_sponsors(request, hackathon='', panel='prizes'):
37593762
active_tab = 0
37603763
elif panel == "stats":
37613764
active_tab = 1
3765+
elif panel == "mentors":
3766+
active_tab = 2
37623767

37633768
filter = ''
37643769
if request.GET.get('filter'):
@@ -3768,7 +3773,17 @@ def dashboard_sponsors(request, hackathon='', panel='prizes'):
37683773

37693774
num_participants = BountyEvent.objects.filter(bounty__event_id=hackathon_event.id, event_type='express_interest', bounty__in=query_prizes).count()
37703775
num_submissions = BountyEvent.objects.filter(bounty__event_id=hackathon_event.id, event_type='submit_work', bounty__in=query_prizes).count()
3776+
3777+
profile = request.user.profile if request.user.is_authenticated and hasattr(request.user, 'profile') else None
3778+
3779+
default_mentors = []
3780+
if profile:
3781+
default_mentors = Profile.objects.filter(
3782+
user__groups__name=f'sponsor-org-{profile.handle}-mentors'
3783+
)
3784+
37713785
params = {
3786+
'default_mentors': default_mentors,
37723787
'active': 'dashboard',
37733788
'prize_count': query_prizes.count(),
37743789
'type': 'hackathon',
@@ -3918,16 +3933,6 @@ def hackathon(request, hackathon='', panel='prizes'):
39183933
from chat.tasks import get_chat_url
39193934
params['chat_override_url'] = f"{get_chat_url()}/hackathons/channels/{hackathon_event.chat_channel_id}"
39203935

3921-
can_manage = request.user.is_authenticated and any(
3922-
[request.user.profile.handle.lower() == bounty.bounty_owner_github_username.lower() for bounty in Bounty.objects.filter(event=hackathon_event)]
3923-
)
3924-
3925-
if can_manage:
3926-
params['can_manage'] = can_manage
3927-
params['default_mentors'] = Profile.objects.filter(
3928-
user__groups__name=f'sponsor-org-{request.user.profile.handle}-mentors'
3929-
)
3930-
39313936
return TemplateResponse(request, 'dashboard/index-vue.html', params)
39323937

39333938

0 commit comments

Comments
 (0)