예제 #1
0
    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)
예제 #2
0
    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.user.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)
예제 #3
0
    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"],
                ),
            ]
        )

        context = {
            "data": data,
            "team": get_gov_user(request)[0]["user"]["team"]["id"],
            "filters": filters,
        }
        return render(request, "flags/flagging-rules-list.html", context)
예제 #4
0
    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")
예제 #5
0
    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.action = put_flagging_rule
        self.success_url = reverse_lazy("flags:flagging_rules")
예제 #6
0
    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)()
예제 #7
0
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
예제 #8
0
    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 lite_menu(request):
    has_notifications = False
    try:
        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"},
            ),
        ]
    except AttributeError:
        # Tests dont provide a user which causes has_permission to error,
        # so return an empty pages list so tests work
        pages = []
    return {"LITE_MENU": [x for x in pages if x is not None], "MENU_NOTIFICATIONS": has_notifications}
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
0
    def get(self, request, **kwargs):
        """
        Show a list of cases pertaining to the given queue
        """
        queue_pk = kwargs.get("queue_pk") or request.user.default_queue
        queue = get_queue(request, queue_pk)

        context = {
            "queue": queue,  # Used for showing current queue
            "filters": case_filters_bar(request, queue),
            "params": convert_parameters_to_query_params(request.GET),  # Used for passing params to JS
            "case_officer": request.GET.get("case_officer"),  # Used for reading params dynamically
            "assigned_user": request.GET.get("assigned_user"),  # ""
            "team_advice_type": request.GET.get("team_advice_type"),  # ""
            "final_advice_type": request.GET.get("final_advice_type"),  # ""
            "is_all_cases_queue": queue_pk == ALL_CASES_QUEUE_ID,
            "enforcement_check": Permission.ENFORCEMENT_CHECK.value in get_user_permissions(request),
            "updated_cases_banner_queue_id": UPDATED_CASES_QUEUE_ID,
        }
        return render(request, "queues/cases.html", context)
예제 #13
0
    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)
예제 #14
0
    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