Claim Work for a Bounty. :request method: POST Args: bounty_id (int): ID of the Bounty. Returns: dict: The success key with a boolean value and accompanying error.
(request, bounty_id)
| 210 | @csrf_exempt |
| 211 | @require_POST |
| 212 | def new_interest(request, bounty_id): |
| 213 | """Claim Work for a Bounty. |
| 214 | |
| 215 | :request method: POST |
| 216 | |
| 217 | Args: |
| 218 | bounty_id (int): ID of the Bounty. |
| 219 | |
| 220 | Returns: |
| 221 | dict: The success key with a boolean value and accompanying error. |
| 222 | |
| 223 | """ |
| 224 | profile_id = request.user.profile.pk if request.user.is_authenticated and hasattr(request.user, 'profile') else None |
| 225 | |
| 226 | access_token = request.GET.get('token') |
| 227 | if access_token: |
| 228 | helper_handle_access_token(request, access_token) |
| 229 | github_user_data = get_github_user_data(access_token) |
| 230 | profile = Profile.objects.prefetch_related('bounty_set') \ |
| 231 | .filter(handle=github_user_data['login']).first() |
| 232 | profile_id = profile.pk |
| 233 | else: |
| 234 | profile = request.user.profile if profile_id else None |
| 235 | |
| 236 | if not profile_id: |
| 237 | return JsonResponse( |
| 238 | {'error': _('You must be authenticated via github to use this feature!')}, |
| 239 | status=401) |
| 240 | |
| 241 | try: |
| 242 | bounty = Bounty.objects.get(pk=bounty_id) |
| 243 | except Bounty.DoesNotExist: |
| 244 | raise Http404 |
| 245 | |
| 246 | if bounty.is_project_type_fulfilled: |
| 247 | return JsonResponse({ |
| 248 | 'error': _(f'There is already someone working on this bounty.'), |
| 249 | 'success': False}, |
| 250 | status=401) |
| 251 | |
| 252 | num_issues = profile.max_num_issues_start_work |
| 253 | active_bounties = Bounty.objects.current().filter(idx_status__in=['open', 'started']) |
| 254 | num_active = Interest.objects.filter(profile_id=profile_id, bounty__in=active_bounties).count() |
| 255 | is_working_on_too_much_stuff = num_active >= num_issues |
| 256 | if is_working_on_too_much_stuff: |
| 257 | return JsonResponse({ |
| 258 | 'error': _(f'You may only work on max of {num_issues} issues at once.'), |
| 259 | 'success': False}, |
| 260 | status=401) |
| 261 | |
| 262 | if profile.no_times_slashed_by_staff(): |
| 263 | return JsonResponse({ |
| 264 | 'error': _('Because a staff member has had to remove you from a bounty in the past, you are unable to start' |
| 265 | 'more work at this time. Please leave a message on slack if you feel this message is in error.'), |
| 266 | 'success': False}, |
| 267 | status=401) |
| 268 | |
| 269 | try: |
nothing calls this directly
no test coverage detected