def _wrapped_view(request, *args, **kwargs):
            if helpers.has_permission(request, permission):
                return view_func(request, *args, **kwargs)

            raise PermissionDeniedError(
                f"You don't have the permission '{permission.value}' to view this, "
                "check urlpatterns or the function decorator if you want to change "
                "this functionality."
            )
 def init(self, request, **kwargs):
     select_team = has_permission(request, Permission.MANAGE_ALL_ROUTING_RULES)
     team_id = request.POST.get("team", get_gov_user(request)[0]["user"]["team"]["id"])
     self.forms = routing_rule_form_group(
         request=request,
         additional_rules=request.POST.getlist("additional_rules[]", ()),
         team_id=team_id,
         select_team=select_team,
     )
     self.success_url = reverse("routing_rules:list")
     self.action = post_routing_rule
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        case = get_case(request, self.object_pk)
        self.context = {"case": case}
        self.form = respond_to_grading_query_form(request, kwargs["queue_pk"], case)
        self.action = put_goods_query_pv_grading
        self.success_url = reverse("cases:case", kwargs=kwargs)
        self.success_message = PVGradingForm.SUCCESS_MESSAGE

        if not has_permission(request, Permission.RESPOND_PV_GRADING):
            return redirect(reverse_lazy("cases:case", kwargs={"queue_pk": kwargs["queue_pk"], "pk": self.object_pk}))
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        case = get_case(request, self.object_pk)
        self.context = {"case": case}
        self.form = respond_to_clc_query_form(request, kwargs["queue_pk"], case)
        self.action = put_goods_query_clc
        self.success_url = reverse("cases:case", kwargs=kwargs)
        self.success_message = CLCReviewGoods.SUCCESS_MESSAGE

        if not has_permission(request, Permission.REVIEW_GOODS):
            return redirect(reverse_lazy("cases:case", kwargs={"queue_pk": kwargs["queue_pk"], "pk": self.object_pk}))
    def get(self, request, **kwargs):
        params = {
            "page": int(request.GET.get("page", 1)),
            **get_params_if_exist(request, ["case_status", "team", "queue", "tier", "only_active"]),
        }
        data, _ = get_routing_rules(request, convert_dict_to_query_params(params))

        user_data, _ = get_gov_user(request, str(request.user.lite_api_user_id))

        status = request.GET.get("status", "active")

        filters = FiltersBar(
            [
                Select(title=Filter.CASE_STATUS, name="case_status", options=get_statuses(request, True)),
                *conditional(
                    has_permission(request, Permission.MANAGE_ALL_ROUTING_RULES),
                    [
                        Select(title=Filter.TEAM, name="team", options=get_teams(request, True)),
                        AutocompleteInput(
                            title=Filter.QUEUE, name="queue", options=get_queues(request, convert_to_options=True),
                        ),
                    ],
                    [
                        AutocompleteInput(
                            title=Filter.QUEUE,
                            name="queue",
                            options=get_users_team_queues(request, request.user.lite_api_user_id, True),
                        ),
                    ],
                ),
                TextInput(title=Filter.TIER, name="tier"),
                Checkboxes(
                    name="only_active", options=[Option(True, Filter.ACTIVE_ONLY)], classes=["govuk-checkboxes--small"],
                ),
            ]
        )

        context = {
            "data": data,
            "status": status,
            "user_data": user_data,
            "filters": filters,
        }
        return render(request, "routing-rules/index.html", context)
Beispiel #6
0
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        case = get_case(request, self.object_pk)
        self.data = flatten_goods_data(get_param_goods(request, case))
        self.form = review_goods_form(request,
                                      is_goods_type="goods_types"
                                      in request.GET,
                                      **kwargs)
        self.context = {"case": case, "goods": get_param_goods(request, case)}
        self.action = post_review_goods
        self.success_url = reverse("cases:case",
                                   kwargs={
                                       "queue_pk": kwargs["queue_pk"],
                                       "pk": self.object_pk
                                   })

        if not has_permission(request, Permission.REVIEW_GOODS):
            return redirect(
                reverse_lazy("cases:case",
                             kwargs={
                                 "queue_pk": kwargs["queue_pk"],
                                 "pk": self.object_pk
                             }))
     ],
 ),
 TextArea(title=advice.GiveOrChangeAdvicePage.REASON,
          extras={"max_length": 5000},
          name="text"),
 PicklistPicker(target="text",
                type=PicklistCategories.standard_advice.key),
 TextArea(
     title=advice.GiveOrChangeAdvicePage.NOTE,
     description=advice.GiveOrChangeAdvicePage.NOTE_DESCRIPTION,
     optional=True,
     extras={"max_length": 200},
     name="note",
 ),
 conditional(
     has_permission(request, Permission.MAINTAIN_FOOTNOTES)
     and tab != "final-advice",
     RadioButtons(
         title=advice.GiveOrChangeAdvicePage.FootNote.
         FOOTNOTE_REQUIRED,
         name="footnote_required",
         options=[
             Option(
                 True,
                 advice.GiveOrChangeAdvicePage.FootNote.YES_OPTION,
                 components=[
                     TextArea(name="footnote"),
                     PicklistPicker(
                         target="footnote",
                         type=PicklistCategories.footnotes.key),
                 ],