Пример #1
0
    def post(self, request, member_id):
        user = User.objects.get(id=member_id)
        if user.profile.state == "noob" or user.profile.state == "accountonly":
            # give default door access
            for door in models.Doors.objects.filter(all_members=True):
                user.profile.doors.add(door)

            # give default interlock access
            for interlock in models.Interlock.objects.filter(all_members=True):
                user.profile.interlocks.add(interlock)

            email = user.email_welcome()
            xero = user.profile.add_to_xero()
            invoice = user.profile.create_membership_invoice()
            user.profile.state = (
                "inactive"  # an admin should activate them when they pay their invoice
            )
            user.profile.update_last_induction()
            user.profile.save()

            subject = f"{user.profile.get_full_name()} just got turned into a member!"
            send_single_email(request.user, config.EMAIL_ADMIN, subject,
                              subject, subject)

            if "Error" not in xero and "Error" not in invoice and email:
                return Response({
                    "success": True,
                    "message": "adminTools.makeMemberSuccess",
                })

            elif "Error" in invoice:
                return Response({"success": False, "message": invoice})

            elif email is False:
                return Response({
                    "success": False,
                    "message": "adminTools.makeMemberErrorEmail"
                })

            else:
                return Response({
                    "success": False,
                    "message": "adminTools.makeMemberError",
                })
        else:
            return Response({
                "success": False,
                "message": "adminTools.makeMemberErrorExists",
            })
Пример #2
0
    def delete(self, request, proxy_id):
        proxy = ProxyVote.objects.get(id=proxy_id)

        if request.user == proxy.user:
            proxy.delete()
            subject = (
                f"{request.user.profile.get_full_name()} just removed you as a proxy"
            )
            message = f"{request.user.profile.get_full_name()} just removed you as a proxy for the {proxy.meeting.get_type()} meeting on {localtime(proxy.meeting.date)}."
            send_single_email(request.user, proxy.proxy_user.email, subject,
                              subject, message)

            subject = f"{proxy.proxy_user.profile.get_full_name()} is no longer your proxy for the {proxy.meeting.get_type()} meeting"
            message = f"{proxy.proxy_user.profile.get_full_name()} is no longer your proxy for the {proxy.meeting.get_type()} meeting on {localtime(proxy.meeting.date)}. You can manage this proxy from the member portal."
            send_single_email(request.user, request.user.email, subject,
                              subject, message)
            return Response()
        else:
            return Response(status=status.HTTP_403_FORBIDDEN)
Пример #3
0
    def post(self, request):
        body = request.data
        member_city = body.get("memberCity")
        proxy_id = body.get("proxy")
        proxy_city = body.get("proxyCity")
        meeting_id = body.get("meeting")

        existing_proxies = ProxyVote.objects.filter(
            user=request.user, meeting_id=meeting_id
        )

        # if the user already has a proxy for this meeting we'll override it
        if existing_proxies:
            for proxy in existing_proxies:
                proxy.delete()

        if member_city and proxy_id and proxy_city and meeting_id:
            meeting = Meeting.objects.get(pk=meeting_id)
            proxy_user = Profile.objects.get(id=proxy_id).user
            ProxyVote.objects.create(
                user=request.user,
                user_city=member_city,
                proxy_user=proxy_user,
                proxy_city=proxy_city,
                meeting=meeting,
            )

            subject = (
                f"{request.user.profile.get_full_name()} just assigned you as a proxy"
            )
            message = f"{request.user.profile.get_full_name()} just assigned you as a proxy for the {meeting.get_type()} meeting on {localtime(meeting.date)}."
            send_single_email(request.user, proxy_user.email, subject, subject, message)

            subject = f"{proxy_user.profile.get_full_name()} is confirmed as your proxy for the {meeting.get_type()} meeting"
            message = f"{proxy_user.profile.get_full_name()} is confirmed as your proxy for the {meeting.get_type()} meeting on {localtime(meeting.date)}. You can manage this proxy from the member portal."
            send_single_email(
                request.user, request.user.email, subject, subject, message
            )

            return Response({"success": True})

        else:
            return Response(status=status.HTTP_400_BAD_REQUEST)
Пример #4
0
    def post(self, request):
        body = request.data
        title = body["title"]
        description = request.user.profile.get_full_name(
        ) + ": " + body["description"]

        if not (title and description):
            return Response(status=status.HTTP_400_BAD_REQUEST)

        use_trello = config.ENABLE_TRELLO_INTEGRATION
        trello_key = config.TRELLO_API_KEY
        trello_token = config.TRELLO_API_TOKEN
        trello_id_list = config.TRELLO_ID_LIST

        if use_trello:
            url = "https://api.trello.com/1/cards"

            querystring = {
                "name": title,
                "desc": description,
                "pos": "top",
                "idList": trello_id_list,
                "keepFromSource": "all",
                "key": trello_key,
                "token": trello_token,
            }

            response = requests.request("POST", url, params=querystring)

            if response.status_code == 200:
                log_user_event(
                    request.user,
                    "Submitted issue: " + title + " Content: " + description,
                    "generic",
                )

                return Response(
                    {
                        "success": True,
                        "url": response.json()["shortUrl"]
                    },
                    status=status.HTTP_201_CREATED,
                )

            else:
                return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        # if Trello isn't configured, use email instead
        else:
            subject = (
                f"{request.user.profile.get_full_name()} submitted an issue ({title})"
            )

            if send_single_email(
                    request.user,
                    config.EMAIL_ADMIN,
                    subject,
                    subject,
                    description,
                    from_user=True,
            ):
                return Response(
                    {"success": True},
                    status=status.HTTP_201_CREATED,
                )

            else:
                return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #5
0
    def post(self, request, member_id):
        user = User.objects.get(id=member_id)

        # if they're a new member or account only
        if user.profile.state == "noob" or user.profile.state == "accountonly":
            # give default door access
            for door in models.Doors.objects.filter(all_members=True):
                user.profile.doors.add(door)

            # give default interlock access
            for interlock in models.Interlock.objects.filter(all_members=True):
                user.profile.interlocks.add(interlock)

            # send the welcome email
            email = user.email_welcome()

            xero = None
            invoice = None

            # if we should generate a Xero invoice and mark them as "inactive" until it's been paid
            if config.MAKEMEMBER_CREATE_XERO_INVOICES:
                xero = user.profile.add_to_xero()
                invoice = user.profile.create_membership_invoice()

                user.profile.state = "inactive"  # an admin should activate them when they pay their invoice
                user.profile.update_last_induction()
                user.profile.save()

            # if we should not generate a Xero invoice, mark them as "active" if their subscription is active
            elif user.profile.subscription_status == "active":
                user.profile.state = "active"
                user.profile.save()

            subject = f"{user.profile.get_full_name()} just got turned into a member!"
            send_single_email(request.user, config.EMAIL_ADMIN, subject,
                              subject, subject)

            # if we don't have to make a Xero invoice, we're done
            if not config.MAKEMEMBER_CREATE_XERO_INVOICES and email:
                return Response({
                    "success": True,
                    "message": "adminTools.makeMemberSuccess",
                })

            # if there were no errors when making the Xero invoice, then we're done
            elif "Error" not in xero and "Error" not in invoice and email:
                return Response({
                    "success": True,
                    "message": "adminTools.makeMemberSuccess",
                })

            # if there was an error creating the Xero invoice
            elif invoice is not None and "Error" in invoice:
                return Response({"success": False, "message": invoice})

            # if there was an error sending the welcome email
            elif email is False:
                return Response({
                    "success": False,
                    "message": "adminTools.makeMemberErrorEmail"
                })

            # otherwise some other error happened
            else:
                capture_message(
                    "Unknown error occurred when running makemember.")
                return Response({
                    "success": False,
                    "message": "adminTools.makeMemberError",
                })
        else:
            return Response({
                "success": False,
                "message": "adminTools.makeMemberErrorExists",
            })