def get(self, request, **kwargs): params = request.GET.copy() params["status"] = params.get("status", FlagStatus.ACTIVE.value) data = get_flags(request, **params) user_data, _ = get_gov_user(request, str(request.session["lite_api_user_id"])) filters = FiltersBar([ TextInput(name="name", title="name"), Select(name="level", title="level", options=level_options), TextInput(name="priority", title="priority"), Select(name="team", title="team", options=get_teams(request, True)), Checkboxes( name="status", options=[ Option(FlagStatus.DEACTIVATED.value, flags.FlagsList.SHOW_DEACTIVATED_FLAGS) ], classes=["govuk-checkboxes--small"], ), ]) context = { "data": data, "user_data": user_data, "filters": filters, "can_change_flag_status": Permission.ACTIVATE_FLAGS.value in get_user_permissions(request), } return render(request, "flags/index.html", context)
def init(self, request, **kwargs): if Permission.MANAGE_FLAGGING_RULES.value not in get_user_permissions( request): return redirect(reverse_lazy("cases:cases")) status = kwargs["status"] self.object_pk = kwargs["pk"] if status != "Deactivated" and status != "Active": raise Http404 if status == "Deactivated": title = strings.FlaggingRules.Status.DEACTIVATE_HEADING description = strings.FlaggingRules.Status.DEACTIVATE_WARNING confirm_text = strings.FlaggingRules.Status.DEACTIVATE_CONFIRM if status == "Active": title = strings.FlaggingRules.Status.REACTIVATE_HEADING description = strings.FlaggingRules.Status.REACTIVATE_WARNING confirm_text = strings.FlaggingRules.Status.REACTIVATE_CONFIRM self.form = deactivate_or_activate_flagging_rule_form( title=title, description=description, confirm_text=confirm_text, status=status) self.action = put_flagging_rule
def has_permissions(request, permissions: List[Permission]): """ Returns true if the user has the given permissions, else false """ user_permissions = get_user_permissions(request) return_value = True for permission in permissions: if permission.value not in user_permissions: return_value = False return return_value
def get(self, request, **kwargs): self.case_id = str(kwargs["pk"]) self.case = get_case(request, self.case_id) self.queue_id = kwargs["queue_pk"] self.queue = get_queue(request, self.queue_id) self.permissions = get_user_permissions(self.request) if hasattr(self, "get_" + self.case.sub_type + "_" + self.case.type): getattr(self, "get_" + self.case.sub_type + "_" + self.case.type)()
def init(self, request, **kwargs): if Permission.MANAGE_FLAGGING_RULES.value not in get_user_permissions( request): return redirect(reverse_lazy("cases:cases")) type = request.POST.get("level", None) self.forms = create_flagging_rules_formGroup(request=self.request, type=type) self.action = post_flagging_rules self.success_url = reverse_lazy("flags:flagging_rules")
def init(self, request, **kwargs): if Permission.MANAGE_FLAGGING_RULES.value not in get_user_permissions( request): return redirect(reverse_lazy("cases:cases")) self.object_pk = kwargs["pk"] self.data = get_flagging_rule(request, self.object_pk)[0]["flag"] self.form = select_condition_and_flag(request, type=self.data["level"]) self.form.buttons[0].value = "Edit flagging rule" self.action = put_flagging_rule self.success_url = reverse_lazy("flags:flagging_rules")
def get(self, request, **kwargs): if Permission.MANAGE_FLAGGING_RULES.value not in get_user_permissions( request): return redirect(reverse_lazy("cases:cases")) params = {"page": int(request.GET.get("page", 1))} params = get_params_if_exist( request, ["only_my_team", "level", "include_deactivated"], params) data, _ = get_flagging_rules(request, convert_dict_to_query_params(params)) filters = FiltersBar([ Select(name="level", title=strings.FlaggingRules.List.Filter.Type, options=_levels), Checkboxes( name="only_my_team", options=[ Option("true", strings.FlaggingRules.List.Filter.MY_TEAM_ONLY) ], classes=["govuk-checkboxes--small", "govuk-!-margin-top-6"], ), Checkboxes( name="include_deactivated", options=[ Option( "true", strings.FlaggingRules.List.Filter.INCLUDE_DEACTIVATED) ], classes=["govuk-checkboxes--small", "govuk-!-margin-top-6"], ), ]) countries, _ = get_countries(request) countries_map = { country["id"]: country["name"] for country in countries["countries"] } for rule in data["results"]: if rule["level"] == "Destination": rule["matching_values"] = [ countries_map[id] for id in rule["matching_values"] ] context = { "data": data, "team": get_gov_user(request)[0]["user"]["team"]["id"], "filters": filters, } return render(request, "flags/flagging-rules-list.html", context)
def get(self, request, **kwargs): search_term = request.GET.get("search_term", "").strip() org_type = request.GET.get("org_type", "").strip() params = { "page": int(request.GET.get("page", 1)), "status": request.GET.get("status", "active") } if search_term: params["search_term"] = search_term if org_type: params["org_type"] = org_type organisations, _ = get_organisations( request, convert_dict_to_query_params(params)) filters = FiltersBar([ TextInput(name="search_term", title=OrganisationsPage.Filters.NAME), Select( name="org_type", title=OrganisationsPage.Filters.TYPE, options=[ Option("individual", OrganisationsPage.Filters.Types.INDIVIDUAL), Option("commercial", OrganisationsPage.Filters.Types.COMMERCIAL), Option("hmrc", OrganisationsPage.Filters.Types.HMRC), ], ), HiddenField(name="status", value=params["status"]), ]) context = { "data": organisations, "filters": filters, "search_term": params.get("search_term", ""), "tab": params.get("status"), "in_review_total": get_menu_notifications(request)["notifications"].get( "organisations"), "can_manage_organisations": Permission.MANAGE_ORGANISATIONS.value in get_user_permissions(request), } return render(request, "organisations/index.html", context)
def get(self, request, **kwargs): roles, _ = get_roles(request) all_permissions = get_permissions(request) permissions = get_user_permissions(request) user, _ = get_gov_user(request) context = { "all_permissions": all_permissions, "roles": roles["roles"], "title": strings.roles.ManageRolesPage.TITLE, "user_permissions": permissions, "super_user_role_id": SUPER_USER_ROLE_ID, "user_role_id": user["user"]["role"]["id"], } return render(request, "users/roles.html", context)
def get_form(self): user_permissions = get_user_permissions(self.request) permission_to_edit_org_name = ( Permission.MANAGE_ORGANISATIONS.value in user_permissions and Permission.REOPEN_CLOSED_CASES.value in user_permissions) if self.data["primary_site"]["address"].get("address_line_1"): are_fields_optional = "address" in self.data["primary_site"][ "address"].get("address_line_1") else: are_fields_optional = self.data["primary_site"]["address"] form = edit_commercial_form if self.data["type"][ "key"] == "commercial" else edit_individual_form return form(self.data, permission_to_edit_org_name, are_fields_optional)
def get(self, request, **kwargs): user, _ = get_gov_user(self.request) team, _ = get_team(request, str(kwargs["pk"])) users, _ = get_users_by_team(request, str(kwargs["pk"])) context = { "team": team["team"], "users": users["users"], "is_user_in_team": user["user"]["team"]["id"] == team["team"]["id"], "can_manage_picklists": Permission.MANAGE_PICKLISTS.value in get_user_permissions(request), } return render(request, "teams/team.html", context)
def get(self, request, **kwargs): self.organisation_id = kwargs["pk"] self.organisation = get_organisation(request, self.organisation_id) context = { "organisation": self.organisation, "can_manage_organisations": Permission.MANAGE_ORGANISATIONS.value in get_user_permissions(request), "tabs": [ Tab( "details", OrganisationPage.Details.TITLE, reverse_lazy("organisations:organisation", kwargs={"pk": self.organisation_id}), ), Tab( "members", OrganisationPage.Members.TITLE, reverse_lazy("organisations:organisation_members", kwargs={"pk": self.organisation_id}), ), Tab( "sites", OrganisationPage.Sites.TITLE, reverse_lazy("organisations:organisation_sites", kwargs={"pk": self.organisation_id}), ), ], "activity": get_organisation_activity(request, self.organisation_id), } context.update(self.get_additional_context()) return render(request, f"organisations/organisation/{self.template_name}.html", context)
def get_context_data(self, *args, **kwargs): try: updated_queue = [ queue for queue in self.data["results"]["queues"] if queue["id"] == UPDATED_CASES_QUEUE_ID ][0] show_updated_cases_banner = updated_queue["case_count"] except IndexError: show_updated_cases_banner = False is_system_queue = self.queue.get("is_system_queue", False) context = { "sla_radius": SLA_RADIUS, "sla_circumference": SLA_CIRCUMFERENCE, "data": self.data, "queue": self.queue, # Used for showing current queue "filters": case_filters_bar(self.request, self.filters, is_system_queue), "is_all_cases_queue": self.queue_pk == ALL_CASES_QUEUE_ID, "enforcement_check": Permission.ENFORCEMENT_CHECK.value in get_user_permissions(self.request), "updated_cases_banner_queue_id": UPDATED_CASES_QUEUE_ID, "show_updated_cases_banner": show_updated_cases_banner, } return super().get_context_data(*args, **context, **kwargs)
def lite_menu(request): has_notifications = False if "lite_api_user_id" in request.session: permissions = get_user_permissions(request) notifications = get_menu_notifications(request) notification_data = notifications["notifications"] has_notifications = notifications["has_notifications"] pages = [ { "title": "Cases", "url": reverse_lazy("core:index"), "icon": "menu/cases" }, { "title": OrganisationsPage.TITLE, "url": reverse_lazy("organisations:organisations"), "icon": "menu/businesses", "notifications": notification_data.get("organisations"), }, { "title": TeamsPage.TITLE, "url": reverse_lazy("teams:teams"), "icon": "menu/teams" }, { "title": "My Team", "url": reverse_lazy("teams:team"), "icon": "menu/teams" }, { "title": QueuesList.TITLE, "url": reverse_lazy("queues:manage"), "icon": "menu/queues" }, { "title": UsersPage.TITLE, "url": reverse_lazy("users:users"), "icon": "menu/users" }, { "title": FlagsList.TITLE, "url": reverse_lazy("flags:flags"), "icon": "menu/flags" }, conditional( Permission.MAINTAIN_OGL.value in permissions, { "title": open_general_licences.List.TITLE, "url": reverse_lazy( "open_general_licences:open_general_licences"), "icon": "menu/open-general-licences", }, ), conditional( Permission.CONFIGURE_TEMPLATES.value in permissions, { "title": strings.DOCUMENT_TEMPLATES_TITLE, "url": reverse_lazy("letter_templates:letter_templates"), "icon": "menu/letter-templates", }, ), conditional( Permission.MANAGE_FLAGGING_RULES.value in permissions, { "title": "Flagging rules", "url": reverse_lazy("flags:flagging_rules"), "icon": "menu/flags" }, ), conditional( Permission.MANAGE_TEAM_ROUTING_RULES.value in permissions or Permission.MANAGE_ALL_ROUTING_RULES.value in permissions, { "title": "Routing rules", "url": reverse_lazy("routing_rules:list"), "icon": "menu/routing-rules" }, ), { "title": "Denial records", "url": reverse_lazy("external_data:denials-upload"), "icon": "menu/cases" }, ] else: pages = [] return { "LITE_MENU": [x for x in pages if x is not None], "MENU_NOTIFICATIONS": has_notifications }