예제 #1
0
 def page_context(self):
     if (not self.can_restrict_access_by_location
         and any(not role.permissions.access_all_locations
                 for role in self.user_roles)
     ):
         messages.warning(self.request, _(
             "This project has user roles that restrict data access by "
             "organization, but the software plan no longer supports that. "
             "Any users assigned to roles that are restricted in data access "
             "by organization can no longer access this project.  Please "
             "update the existing roles."))
     return {
         'user_roles': self.user_roles,
         'can_edit_roles': self.can_edit_roles,
         'default_role': UserRole.get_default(),
         'report_list': get_possible_reports(self.domain),
         'web_apps_list': get_cloudcare_apps(self.domain),
         'apps_list': get_brief_apps_in_domain(self.domain),
         'invitations': self.invitations,
         'requests': DomainRequest.by_domain(self.domain) if self.request.couch_user.is_domain_admin else [],
         'admins': WebUser.get_admins_by_domain(self.domain),
         'domain_object': self.domain_object,
         'uses_locations': self.domain_object.uses_locations,
         'can_restrict_access_by_location': self.can_restrict_access_by_location,
         'landing_page_choices': self.landing_page_choices,
         'show_integration': (
             toggles.OPENMRS_INTEGRATION.enabled(self.domain) or
             toggles.DHIS2_INTEGRATION.enabled(self.domain)
         ),
     }
예제 #2
0
 def page_context(self):
     return {
         'invitations': self.invitations,
         'requests': DomainRequest.by_domain(self.domain) if self.request.couch_user.is_domain_admin else [],
         'admins': WebUser.get_admins_by_domain(self.domain),
         'domain_object': self.domain_object,
     }
예제 #3
0
 def page_context(self):
     return {
         'invitations': self.invitations,
         'requests': DomainRequest.by_domain(self.domain) if self.request.couch_user.is_domain_admin else [],
         'admins': WebUser.get_admins_by_domain(self.domain),
         'domain_object': self.domain_object,
     }
예제 #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:
                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)
예제 #5
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)
예제 #6
0
 def page_context(self):
     return {
         'user_roles': self.user_roles,
         'can_edit_roles': self.can_edit_roles,
         'default_role': UserRole.get_default(),
         'report_list': get_possible_reports(self.domain),
         'invitations': self.invitations,
         'requests': DomainRequest.by_domain(self.domain) if self.request.couch_user.is_domain_admin else [],
         'admins': WebUser.get_admins_by_domain(self.domain),
         'domain_object': self.domain_object,
         'uses_locations': self.domain_object.uses_locations,
     }
예제 #7
0
 def page_context(self):
     return {
         "user_roles": self.user_roles,
         "can_edit_roles": self.can_edit_roles,
         "default_role": UserRole.get_default(),
         "report_list": get_possible_reports(self.domain),
         "invitations": self.invitations,
         "requests": DomainRequest.by_domain(self.domain) if self.request.couch_user.is_domain_admin else [],
         "admins": WebUser.get_admins_by_domain(self.domain),
         "domain_object": self.domain_object,
         "uses_locations": self.domain_object.uses_locations,
     }
예제 #8
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)
예제 #9
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)
예제 #10
0
 def page_context(self):
     return {
         'user_roles':
         self.user_roles,
         'can_edit_roles':
         self.can_edit_roles,
         'default_role':
         UserRole.get_default(),
         'report_list':
         get_possible_reports(self.domain),
         'invitations':
         self.invitations,
         'requests':
         DomainRequest.by_domain(self.domain)
         if self.request.couch_user.is_domain_admin else [],
         'admins':
         WebUser.get_admins_by_domain(self.domain),
         'domain_object':
         self.domain_object,
         'uses_locations':
         self.domain_object.uses_locations,
     }