예제 #1
0
 def post(self, request, *args, **kwargs):
     self.request_form = DomainRequestForm(request.POST)
     if self.request_form.is_valid():
         data = self.request_form.cleaned_data
         with CriticalSection(["domain_request_%s" % data["domain"]]):
             if DomainRequest.by_email(data["domain"], data["email"]) is not None:
                 messages.error(
                     request,
                     _(
                         "A request is pending for this email. "
                         "You will receive an email when the request is approved."
                     ),
                 )
             else:
                 domain_request = DomainRequest(**data)
                 domain_request.send_request_email()
                 domain_request.save()
                 domain = Domain.get_by_name(domain_request.domain)
                 return render(
                     request,
                     "users/confirmation_sent.html",
                     {
                         "hr_name": domain.display_name() if domain else domain_request.domain,
                         "url": reverse("appstore"),
                     },
                 )
     return self.get(request, *args, **kwargs)
예제 #2
0
 def post(self, request, *args, **kwargs):
     self.request_form = DomainRequestForm(request.POST)
     if self.request_form.is_valid():
         data = self.request_form.cleaned_data
         with CriticalSection(["domain_request_%s" % data['domain']]):
             if DomainRequest.by_email(data['domain'],
                                       data['email']) is not None:
                 messages.error(
                     request,
                     _("A request is pending for this email. "
                       "You will receive an email when the request is approved."
                       ))
             else:
                 domain_request = DomainRequest(**data)
                 domain_request.send_request_email()
                 domain_request.save()
                 domain = Domain.get_by_name(domain_request.domain)
                 return render(
                     request, "users/confirmation_sent.html", {
                         'hr_name':
                         domain.display_name()
                         if domain else domain_request.domain,
                         'url':
                         reverse("appstore"),
                     })
     return self.get(request, *args, **kwargs)
예제 #3
0
    def post(self, request, *args, **kwargs):
        if self.invite_web_user_form.is_valid():
            # If user exists and has already requested access, just add them to the project
            # Otherwise, send an invitation
            create_invitation = True
            data = self.invite_web_user_form.cleaned_data
            domain_request = DomainRequest.by_email(self.domain, data["email"])
            if domain_request is not None:
                domain_request.is_approved = True
                domain_request.save()
                user = CouchUser.get_by_username(domain_request.email)
                if user is not None:
                    domain_request.send_approval_email()
                    create_invitation = False
                    user.add_as_web_user(self.domain, role=data["role"],
                                         location_id=data.get("supply_point", None),
                                         program_id=data.get("program", None))
                messages.success(request, "%s added." % data["email"])
            else:
                messages.success(request, "Invitation sent to %s" % data["email"])

            if create_invitation:
                data["invited_by"] = request.couch_user.user_id
                data["invited_on"] = datetime.utcnow()
                data["domain"] = self.domain
                invite = DomainInvitation(**data)
                invite.save()
                invite.send_activation_email()
            return HttpResponseRedirect(reverse(
                ListWebUsersView.urlname,
                args=[self.domain]
            ))
        return self.get(request, *args, **kwargs)
예제 #4
0
    def post(self, request, *args, **kwargs):
        if self.invite_web_user_form.is_valid():
            # If user exists and has already requested access, just add them to the project
            # Otherwise, send an invitation
            create_invitation = True
            data = self.invite_web_user_form.cleaned_data
            domain_request = DomainRequest.by_email(self.domain, data["email"])
            if domain_request is not None:
                domain_request.is_approved = True
                domain_request.save()
                user = CouchUser.get_by_username(domain_request.email)
                if user is not None:
                    domain_request.send_approval_email()
                    create_invitation = False
                    user.add_as_web_user(self.domain,
                                         role=data["role"],
                                         location_id=data.get(
                                             "supply_point", None),
                                         program_id=data.get("program", None))
                messages.success(request, "%s added." % data["email"])
            else:
                track_workflow(request.couch_user.get_email(),
                               "Sent a project invitation",
                               {"Sent a project invitation": "yes"})
                meta = get_meta(request)
                track_sent_invite_on_hubspot.delay(request.couch_user,
                                                   request.COOKIES, meta)
                messages.success(request,
                                 "Invitation sent to %s" % data["email"])

            if create_invitation:
                data["invited_by"] = request.couch_user.user_id
                data["invited_on"] = datetime.utcnow()
                data["domain"] = self.domain
                invite = Invitation(**data)
                invite.save()
                invite.send_activation_email()
            return HttpResponseRedirect(
                reverse(ListWebUsersView.urlname, args=[self.domain]))
        return self.get(request, *args, **kwargs)