Skip to content

Commit

Permalink
Protect legal aid available page to categorys that are eligible only
Browse files Browse the repository at this point in the history
  • Loading branch information
said-moj committed Mar 6, 2025
1 parent 31ec4e2 commit f4a8a01
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/categories/results/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
CannotFindYourProblemPage,
NextStepsPage,
)
from app.mixins import InScopeMixin


class InScopeResultPage(InScopeMixin, ResultPage):
pass


bp.add_url_rule(
"/legal-aid-available",
view_func=ResultPage.as_view("in_scope", template="categories/in-scope.html"),
view_func=InScopeResultPage.as_view(
"in_scope", template="categories/in-scope.html"
),
)
bp.add_url_rule(
"/legal-aid-available-hlpas",
Expand Down
4 changes: 3 additions & 1 deletion app/means_test/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from app.means_test.forms.outgoings import OutgoingsForm
from app.means_test.forms.review import ReviewForm, BaseMeansTestForm
from app.categories.models import CategoryAnswer
from app.mixins import InScopeMixin


class FormsMixin:
Expand All @@ -26,7 +27,7 @@ class FormsMixin:
}


class MeansTest(FormsMixin, View):
class MeansTest(FormsMixin, InScopeMixin, View):
def __init__(self, current_form_class, current_name):
self.form_class = current_form_class
self.current_name = current_name
Expand All @@ -50,6 +51,7 @@ def handle_multiple_properties_ajax_request(self, form):
return None

def dispatch_request(self):
self.ensure_in_scope()
eligibility = session.get_eligibility()
form_data = eligibility.forms.get(self.current_name, {})
form = self.form_class(formdata=request.form or None, data=form_data)
Expand Down
11 changes: 11 additions & 0 deletions app/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import session, url_for, redirect


class InScopeMixin:
def dispatch_request(self):
self.ensure_in_scope()

def ensure_in_scope(self):
if not session.in_scope:
return redirect(url_for("main.session_expired"))
return super().dispatch_request()

0 comments on commit f4a8a01

Please sign in to comment.