Beispiel #1
0
    def get(self, request, *args, **kwargs):
        organisation = get_user(request, params={"in_review":
                                                 True})["organisations"][0]
        organisation_name = organisation["name"]
        organisation_status = organisation["status"]["key"]

        if organisation_status != "in_review":
            raise Http404

        return success_page(
            request=request,
            title=f"You've successfully registered: {organisation_name}",
            secondary_title="We're currently processing your application.",
            description="",
            what_happens_next=[
                "Export Control Joint Unit (ECJU) is processing your request for an export control account. "
                "We'll send you an email when we've made a final decision."
            ],
            links={},
            back_link=conditional(
                request.GET.get("show_back_link", False),
                BackLink(generic.BACK,
                         reverse_lazy("core:pick_organisation"))),
            animated=True,
            additional_context={"user_in_limbo": True},
        )
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     self.data = get_user(request, self.object_pk)["user"]
     self.form = assign_sites(request)
     self.action = put_assign_sites
     self.success_url = reverse_lazy("organisation:members:user",
                                     kwargs={"pk": self.object_pk})
Beispiel #3
0
    def init(self, request, **kwargs):
        self.forms = register_triage()
        self.action = validate_register_organisation_triage
        self.additional_context = {"user_in_limbo": True}

        if not request.user.is_authenticated:
            raise Http404

        if request.user.user_token and get_user(request)["organisations"]:
            raise Http404
    def get_additional_context(self):
        user = get_user(self.request)
        user_role_id = user["role"]["id"]
        roles = get_roles(self.request, self.organisation_id, page=self.request.GET.get("page", 1))
        all_permissions = get_permissions(self.request)

        return {
            "roles": roles,
            "user_role_id": user_role_id,
            "immutable_roles": [SUPER_USER_ROLE_ID, DEFAULT_USER_ROLE_ID],
            "all_permissions": all_permissions,
        }
Beispiel #5
0
    def init(self, request, **kwargs):
        _type = self.kwargs["type"]
        location = self.kwargs["location"]

        self.forms = (register_a_commercial_organisation_group(
            request, location) if _type == "commercial" else
                      register_an_individual_group(request, location))
        self.action = register_commercial_organisation if _type == "commercial" else register_private_individual
        self.hide_components = ["site.address.address_line_2"]
        self.additional_context = {"user_in_limbo": True}

        if not request.user.is_authenticated:
            raise Http404

        if request.user.user_token and get_user(request)["organisations"]:
            raise Http404
    def get(self, request, **kwargs):
        request_user = get_organisation_user(request,
                                             str(request.user.organisation),
                                             str(kwargs["pk"]))
        user = get_user(request)

        is_request_user_super_user = is_super_user(request_user)
        is_user_super_user = is_super_user(user)
        is_self_editing = user["id"] == request_user["id"]

        show_change_status = not is_self_editing and is_user_super_user and not is_request_user_super_user
        show_change_role = not is_self_editing and is_user_super_user
        show_assign_sites = not is_self_editing and not is_request_user_super_user

        context = {
            "signed_in_user": user,
            "profile": request_user,
            "show_change_status": show_change_status,
            "show_change_role": show_change_role,
            "show_assign_sites": show_assign_sites,
        }
        return render(request, "organisation/members/profile.html", context)
Beispiel #7
0
    def get(self, request, **kwargs):
        if not request.user.is_authenticated:
            return render(request, "core/start.html")

        try:
            user = get_user(request)
            user_permissions = user["role"]["permissions"]
        except (JSONDecodeError, TypeError, KeyError):
            return redirect("auth:login")

        organisation = get_organisation(request,
                                        str(request.user.organisation))
        notifications, _ = get_notifications(request)
        existing = has_existing_applications_and_licences_and_nlrs(request)

        context = {
            "organisation": organisation,
            "user_data": user,
            "notifications": notifications,
            "existing": existing,
            "user_permissions": user_permissions,
        }

        return render(request, "core/hub.html", context)
def get_user_permissions(request):
    user = get_user(request)
    return user["role"]["permissions"]
    def get(self, request, *args, **kwargs):
        logging.info("Login callback received from GREAT SSO")

        auth_code = request.GET.get("code", None)

        if not auth_code:
            return redirect(reverse_lazy("auth:login"))

        state = self.request.session.get(TOKEN_SESSION_KEY + "_oauth_state",
                                         None)

        if not state:
            return HttpResponseServerError()

        try:
            token = get_client(self.request).fetch_token(
                TOKEN_URL,
                client_secret=settings.AUTHBROKER_CLIENT_SECRET,
                code=auth_code)

            self.request.session[TOKEN_SESSION_KEY] = dict(token)

            del self.request.session[TOKEN_SESSION_KEY + "_oauth_state"]

        # NOTE: the BaseException will be removed or narrowed at a later date. The try/except block is
        # here due to reports of the app raising a 500 if the url is copied.  Current theory is that
        # somehow the url with the authcode is being copied, which would cause `fetch_token` to raise
        # an exception. However, looking at the fetch_code method, I'm not entirely sure what exceptions it
        # would raise in this instance.
        except BaseException:
            client.captureException()

        profile = get_profile(get_client(self.request))

        response, status_code = authenticate_exporter_user(request, profile)

        if status_code == 400:
            return error_page(request, response.get("errors")[0])

        user = authenticate(request)
        login(request, user)

        if status_code == 200:
            user.user_token = response["token"]
            user.first_name = response["first_name"]
            user.last_name = response["last_name"]
            user.lite_api_user_id = response["lite_api_user_id"]
            user.organisation = None
            user.save()
        elif status_code == 401:
            user.organisation = None
            user.save()
            return redirect("core:register_an_organisation_triage")

        user_dict = get_user(request)

        if len(user_dict["organisations"]) == 0:
            return redirect("core:register_an_organisation_triage")
        elif len(user_dict["organisations"]) == 1:
            organisation = user_dict["organisations"][0]
            if organisation["status"]["key"] != "in_review":
                user.organisation = user_dict["organisations"][0]["id"]
                user.save()
            else:
                return redirect("core:register_an_organisation_confirm")
        elif len(user_dict["organisations"]) > 1:
            return redirect("core:pick_organisation")

        return redirect(getattr(settings, "LOGIN_REDIRECT_URL", "/"))
Beispiel #10
0
    def dispatch(self, request, *args, **kwargs):
        user = get_user(request)
        self.organisations = user["organisations"]
        self.form = select_your_organisation_form(self.organisations)

        return super(PickOrganisation, self).dispatch(request, *args, **kwargs)