Exemplo n.º 1
0
def uninterested(request, bounty_id, profile_id):
    """Remove party from given bounty

    Can only be called by the bounty funder

    :request method: GET

    Args:
        bounty_id (int): ID of the Bounty
        profile_id (int): ID of the interested profile

    Returns:
        dict: The success key with a boolean value and accompanying error.
    """
    try:
        bounty = Bounty.objects.get(pk=bounty_id)
    except Bounty.DoesNotExist:
        return JsonResponse({'errors': ['Bounty doesn\'t exist!']}, status=401)

    is_funder = bounty.is_funder(request.user.username.lower())
    is_staff = request.user.is_staff
    if not is_funder and not is_staff:
        return JsonResponse(
            {'error': 'Only bounty funders are allowed to remove users!'},
            status=401)

    try:
        interest = Interest.objects.get(profile_id=profile_id, bounty=bounty)
        bounty.interested.remove(interest)
        maybe_market_to_slack(bounty, 'stop_work')
        maybe_market_to_user_slack(bounty, 'stop_work')
        event_name = "bounty_removed_by_staff" if is_staff else "bounty_removed_by_funder"
        record_user_action_on_interest(interest, event_name, None)
        interest.delete()
    except Interest.DoesNotExist:
        return JsonResponse(
            {
                'errors':
                ['Party haven\'t expressed interest on this bounty.'],
                'success': False
            },
            status=401)
    except Interest.MultipleObjectsReturned:
        interest_ids = bounty.interested \
            .filter(
                profile_id=profile_id,
                bounty=bounty
            ).values_list('id', flat=True) \
            .order_by('-created')

        bounty.interested.remove(*interest_ids)
        Interest.objects.filter(pk__in=list(interest_ids)).delete()

    profile = Profile.objects.get(id=profile_id)
    if profile.user and profile.user.email:
        bounty_uninterested(profile.user.email, bounty, interest)
    else:
        print("no email sent -- user was not found")
    return JsonResponse({'success': True})
Exemplo n.º 2
0
def uninterested(request, bounty_id, profile_id):
    """Remove party from given bounty

    :request method: GET

    Args:
        bounty_id (int): ID of the Bounty
        profile_id (int): ID of the interested profile

    Returns:
        dict: The success key with a boolean value and accompanying error.
    """

    session_profile_id = request.session.get('profile_id')
    if not session_profile_id:
        return JsonResponse({'error': 'You must be authenticated!'},
                            status=401)

    try:
        bounty = Bounty.objects.get(pk=bounty_id)
    except Bounty.DoesNotExist:
        return JsonResponse({'errors': ['Bounty doesn\'t exist!']}, status=401)

    if not bounty.is_funder(request.session.get('handle').lower()):
        return JsonResponse(
            {'error': 'Only bounty funders are allowed to remove users!'},
            status=401)

    try:
        interest = Interest.objects.get(profile_id=profile_id, bounty=bounty)
        bounty.interested.remove(interest)
        maybe_market_to_slack(bounty, 'stop_work')
        interest.delete()
    except Interest.DoesNotExist:
        return JsonResponse(
            {
                'errors':
                ['Party haven\'t expressed interest on this bounty.'],
                'success': False
            },
            status=401)
    except Interest.MultipleObjectsReturned:
        interest_ids = bounty.interested \
            .filter(
                profile_id=profile_id,
                bounty=bounty
            ).values_list('id', flat=True) \
            .order_by('-created')

        bounty.interested.remove(*interest_ids)
        Interest.objects.filter(pk__in=list(interest_ids)).delete()

    profile = Profile.objects.get(id=profile_id)
    bounty_uninterested(profile.email, bounty, interest)
    return JsonResponse({'success': True})
Exemplo n.º 3
0
 def handle(self, *args, **options):
     b = Bounty.objects.all().last()
     i = Interest.objects.all().last()
     # new_bounty(b, [settings.CONTACT_EMAIL])
     new_match([settings.CONTACT_EMAIL, '*****@*****.**'], b, 'owocki')
     # weekly_roundup([settings.CONTACT_EMAIL])
     # new_bounty(b, [settings.CONTACT_EMAIL])
     # new_work_submission(b, [settings.CONTACT_EMAIL])
     # new_bounty_rejection(b, [settings.CONTACT_EMAIL])
     # new_bounty_acceptance(b, [settings.CONTACT_EMAIL])
     # bounty_expire_warning(b, [settings.CONTACT_EMAIL])
     bounty_uninterested([settings.CONTACT_EMAIL, '*****@*****.**'], b,
                         i)