def get(self, request, **kwargs): self.organisation_id = str(request.user.organisation) self.organisation = get_organisation(request, self.organisation_id) user_permissions = kwargs.get("permissions", get_user_permissions(request)) can_administer_sites = Permissions.ADMINISTER_SITES in user_permissions can_administer_roles = Permissions.EXPORTER_ADMINISTER_ROLES in user_permissions context = { "organisation": self.organisation, "can_administer_sites": can_administer_sites, "can_administer_roles": can_administer_roles, "user_permissions": user_permissions, "tabs": [ Tab("members", Tabs.MEMBERS, reverse_lazy("organisation:members:members")), conditional( can_administer_sites, Tab("sites", Tabs.SITES, reverse_lazy("organisation:sites:sites"))), conditional( can_administer_roles, Tab("roles", Tabs.ROLES, reverse_lazy("organisation:roles:roles"))), Tab("details", Tabs.DETAILS, reverse_lazy("organisation:details")), ], } context.update(self.get_additional_context()) return render(request, f"organisation/{self.template_name}.html", context)
def get(self, request, *args, **kwargs): organisation_id = str(request.user.organisation) site = get_site(request, organisation_id, kwargs["pk"]) organisation = get_organisation(request, organisation_id) context = { "site": site, "organisation": organisation, } return render(request, "organisation/sites/site.html", context)
def validate_is_in_organisation_type(request, organisation_types): """ Raises an exception if the user's organisation is not inside of organisation_types organisation_types can be a string or list, expected values contain: 'hmrc', 'commercial', 'individual' """ organisation = get_organisation(request, request.user.organisation) if not organisation["type"]["key"] in organisation_types: raise Http404
def post(self, request, *args, **kwargs): action = request.POST.get("action") organisation = request.POST.get("organisation") if action == "continue": if organisation: organisation = get_organisation( request, request.POST.get("organisation")) return form_page(request, confirm_organisation_form(organisation)) else: # Return an error if the user hasn't selected an organisation return self.get(request, show_error=True, *args, **kwargs) else: return redirect( reverse_lazy("hmrc:reference_name", kwargs={"org_id": organisation}))
def get(self, request, **kwargs): params = { "page": int(request.GET.get("page", 1)), "submitted": str_to_bool(request.GET.get("submitted", True)) } organisation = get_organisation(request, request.user.organisation) applications = get_applications(request, **params) context = { "applications": applications, "organisation": organisation, "params": params, "page": params.pop("page"), "params_str": convert_dict_to_query_params(params), } return render( request, "applications/applications.html" if params["submitted"] else "applications/drafts.html", context)
def post(self, request, **kwargs): # If no data is given, error if not request.POST.get("organisation"): return form_page( request, self.form, errors={"organisation": ["Select an organisation to use"]}) request.user.organisation = request.POST["organisation"] organisation = get_organisation(request, request.POST["organisation"]) if "errors" in organisation: return redirect( reverse_lazy("core:register_an_organisation_confirm") + "?show_back_link=True") request.user.organisation_name = organisation["name"] request.user.save() return redirect("/")
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)