@@ -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