Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwan-samarasinghe committed Feb 7, 2025
1 parent 0bf80bd commit 3f61a13
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 116 deletions.
19 changes: 6 additions & 13 deletions app/blueprints/fund/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from app.db.queries.fund import add_fund, get_all_funds, get_fund_by_id, update_fund, delete_selected_fund
from app.shared.helpers import flash_message
from app.shared.table_pagination import GovUKTableAndPagination
from config import Config

INDEX_BP_DASHBOARD = "index_bp.dashboard"
SELECT_GRANT_PAGE = "select_grant"
Expand Down Expand Up @@ -45,16 +44,18 @@ def view_all_funds():
return render_template("view_all_funds.html", **params)


@fund_bp.route("/<uuid:fund_id>", methods=["GET"])
@fund_bp.route("/<uuid:fund_id>", methods=["GET", "DELETE"])
def view_fund_details(fund_id):
"""
Renders grant details page
"""
form = FundForm()
if request.method == "DELETE":
delete_selected_fund(fund_id)
return redirect(url_for("fund_bp.view_all_funds"))
fund = get_fund_by_id(fund_id)
return render_template("fund_details.html",
form=form, fund=fund,
feature_flags=Config.FEATURE_FLAGS)
#TODO at this time we are not implementing the delete grant but later we have to implement
return render_template("fund_details.html", form=form, fund=fund)


def _create_fund_get_previous_url(actions):
Expand Down Expand Up @@ -180,11 +181,3 @@ def edit_fund(fund_id):

params.update({"fund_id": fund_id, "form": form, "prev_nav_url": prev_nav_url})
return render_template("fund.html", **params)


@fund_bp.route("/<uuid:fund_id>/delete", methods=["GET"])
def delete_fund(fund_id):
if not Config.FEATURE_FLAGS.get('feature_delete'):
return "Delete Feature Disabled", 403
delete_selected_fund(fund_id)
return redirect(url_for("fund_bp.view_all_funds"))
11 changes: 0 additions & 11 deletions app/blueprints/fund/templates/fund_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,4 @@ <h1 class="govuk-heading-l">{{ fund.name_json["en"] }}</h1>
}) }}
</div>
</div>
{% if feature_flags.get('feature_delete') %}
<div class="govuk-grid-row govuk-!-margin-top-8">
<div class="govuk-grid-column-full">
{{ govukButton({
"text": "Delete grant ",
"classes": "govuk-button--warning",
"href": url_for("fund_bp.delete_fund", fund_id=fund.fund_id)
}) }}
</div>
</div>
{% endif %}
{% endblock content %}
20 changes: 7 additions & 13 deletions app/blueprints/round/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,16 @@ def clone_round(round_id):
return redirect(url_for(ROUND_DETAILS, round_id=round_id))


@round_bp.route("/<round_id>")
@round_bp.route("/<round_id>", methods=["GET", "DELETE"])
def round_details(round_id):
fund_round = get_round_by_id(round_id)
form = RoundForm(data={"fund_id": fund_round.fund_id})
cloned_form = CloneRoundForm(data={"fund_id": fund_round.fund_id})
fund_form = FundForm()
if request.method == "DELETE":
delete_selected_round(round_id)
return redirect(url_for("round_bp.view_all_rounds"))
cloned_form = CloneRoundForm(data={"fund_id": fund_round.fund_id})
# TODO at this time we are not implementing the delete applications but later we have to implement
return render_template(
"round_details.html", form=form, fund_form=fund_form, round=fund_round,
cloned_form=cloned_form,
feature_flags=Config.FEATURE_FLAGS
)


@round_bp.route("/<uuid:round_id>/delete", methods=["GET"])
def delete_round(round_id):
if not Config.FEATURE_FLAGS.get('feature_delete'):
return "Delete Feature Disabled", 403
delete_selected_round(round_id)
return redirect(url_for("round_bp.view_all_rounds"))
cloned_form=cloned_form)
11 changes: 0 additions & 11 deletions app/blueprints/round/templates/round_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,4 @@ <h2 class="govuk-heading-l govuk-!-margin-bottom-0">Apply for {{ round.fund.titl
}) }}
</div>
</div>
{% if feature_flags.get('feature_delete') %}
<div class="govuk-grid-row govuk-!-margin-top-8">
<div class="govuk-grid-column-full">
{{ govukButton({
"text": "Delete application ",
"classes": "govuk-button--warning",
"href": url_for("round_bp.delete_round", round_id=round.round_id)
}) }}
</div>
</div>
{% endif %}
{% endblock content %}
4 changes: 0 additions & 4 deletions config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,3 @@ class DefaultConfig(object):
"x_xss_protection": True,
"content_security_policy_nonce_in": ["script-src"],
}

FEATURE_FLAGS = {
"feature_delete": getenv("FEATURE_DELETE", "False").strip().lower() == "true",
}
5 changes: 0 additions & 5 deletions copilot/fsd-fund-application-builder/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ variables:
NOTIFICATION_SERVICE_HOST: http://fsd-notification:8080
MAINTENANCE_MODE: false
SENTRY_DSN: https://4128cfd691c439577e8f106968217f72@o1432034.ingest.us.sentry.io/4508496706666497
FEATURE_DELETE: false

secrets:
RSA256_PUBLIC_KEY_BASE64: /copilot/${COPILOT_APPLICATION_NAME}/${COPILOT_ENVIRONMENT_NAME}/secrets/RSA256_PUBLIC_KEY_BASE64
Expand All @@ -65,8 +64,6 @@ environments:
dev:
count:
spot: 1
variables:
FEATURE_DELETE: true
sidecars:
nginx:
port: 8087
Expand All @@ -86,8 +83,6 @@ environments:
test:
count:
spot: 2
variables:
FEATURE_DELETE: true
sidecars:
nginx:
port: 8087
Expand Down
53 changes: 23 additions & 30 deletions tests/blueprints/fund/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest
from bs4 import BeautifulSoup
from flask import g
from sqlalchemy.orm import joinedload

from app.db.models import Fund, Round, Form, Section, Component, Lizt
from app.db.models import Fund, Round, Section, Component, Lizt
from app.db.models.fund import FundingType
from app.db.queries.fund import get_fund_by_id
from tests.helpers import submit_form
from config import Config
from sqlalchemy.orm import joinedload


@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user")
Expand Down Expand Up @@ -361,33 +360,27 @@ def test_create_fund_welsh_error_messages(flask_test_client, seed_dynamic_data):


@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user")
def test_delete_fund_feature_disabled(flask_test_client, monkeypatch, seed_fund_without_assessment):
"""Test that the delete endpoint returns 403 when a feature flag is disabled."""
test_fund: Fund = seed_fund_without_assessment["funds"][0]
monkeypatch.setattr(Config, "FEATURE_FLAGS", {"feature_delete": False})
response = flask_test_client.get(f"/grants/{test_fund.fund_id}/delete", follow_redirects=True)
assert response.status_code == 403
assert b"Delete Feature Disabled" in response.data


@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user")
def test_delete_fund_feature_enabled(_db, flask_test_client, monkeypatch, seed_fund_without_assessment):
def test_delete_fund_feature_enabled(_db, flask_test_client, seed_fund_without_assessment):
"""Test that the delete endpoint redirects when a feature flag is enabled."""
test_fund: Fund = seed_fund_without_assessment["funds"][0]
monkeypatch.setattr(Config, "FEATURE_FLAGS", {"feature_delete": True})
output: Fund = _db.session.get(Fund, test_fund.fund_id,
flask_test_client.get(f"/grants/{test_fund.fund_id}")
with flask_test_client.session_transaction():
output: Fund = _db.session.get(Fund, test_fund.fund_id,
options=[joinedload(Fund.rounds).joinedload(Round.sections)])
assert output is not None, "No values present in the db"
response = flask_test_client.delete(f"/grants/{test_fund.fund_id}", data={
"csrf_token": g.csrf_token,
}, follow_redirects=True)
assert response.status_code == 200 # Assuming redirection to a valid page
_db.session.commit()
output_f = _db.session.get(Fund, test_fund.fund_id,
options=[joinedload(Fund.rounds).joinedload(Round.sections)])
assert output is not None, "No values present in the db"
response = flask_test_client.get(f"/grants/{test_fund.fund_id}/delete", follow_redirects=True)
assert response.status_code == 200 # Assuming redirection to a valid page
_db.session.commit()
output_f = _db.session.get(Fund, test_fund.fund_id, options=[joinedload(Fund.rounds).joinedload(Round.sections)])
assert output_f is None, "Grant delete did not happened"
output_r = _db.session.query(Round).all()
assert not output_r, "Round delete did not happened"
output_s = _db.session.query(Section).all()
assert not output_s, "Section delete did not happened"
output_c = _db.session.query(Component).all()
assert not output_c, "Component delete did not happened"
output_l = _db.session.query(Lizt).all()
assert not output_l, "Lizt delete did not happened"
assert output_f is None, "Grant delete did not happened"
output_r = _db.session.query(Round).all()
assert not output_r, "Round delete did not happened"
output_s = _db.session.query(Section).all()
assert not output_s, "Section delete did not happened"
output_c = _db.session.query(Component).all()
assert not output_c, "Component delete did not happened"
output_l = _db.session.query(Lizt).all()
assert not output_l, "Lizt delete did not happened"
51 changes: 22 additions & 29 deletions tests/blueprints/round/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import pytest
from bs4 import BeautifulSoup
from flask import g, url_for
from sqlalchemy.orm import joinedload

from app.db.models import Round, Fund, Section, Component, Lizt
from app.db.queries.round import get_round_by_id
from tests.helpers import submit_form
from config import Config
from sqlalchemy.orm import joinedload

round_data_info = {
"opens": ["01", "10", "2024", "09", "00"],
Expand Down Expand Up @@ -335,33 +334,27 @@ def test_clone_round(flask_test_client, seed_dynamic_data):


@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user")
def test_delete_fund_feature_disabled(flask_test_client, monkeypatch, seed_fund_without_assessment):
"""Test that the delete endpoint returns 403 when a feature flag is disabled."""
test_round: Round = seed_fund_without_assessment["rounds"][0]
monkeypatch.setattr(Config, "FEATURE_FLAGS", {"feature_delete": False})
response = flask_test_client.get(f"/rounds/{test_round.round_id}/delete", follow_redirects=True)
assert response.status_code == 403
assert b"Delete Feature Disabled" in response.data


@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user")
def test_delete_fund_feature_enabled(_db, flask_test_client, monkeypatch, seed_fund_without_assessment):
def test_delete_fund_feature_enabled(_db, flask_test_client, seed_fund_without_assessment):
"""Test that the delete endpoint redirects when a feature flag is enabled."""
test_round: Round = seed_fund_without_assessment["rounds"][0]
monkeypatch.setattr(Config, "FEATURE_FLAGS", {"feature_delete": True})
output: Fund = _db.session.get(Fund, test_round.fund_id,
flask_test_client.get(f"/rounds/{test_round.round_id}")
with flask_test_client.session_transaction():
output: Fund = _db.session.get(Fund, test_round.fund_id,
options=[joinedload(Fund.rounds).joinedload(Round.sections)])
assert output is not None, "No values present in the db"
response = flask_test_client.delete(f"/rounds/{test_round.round_id}", data={
"csrf_token": g.csrf_token,
}, follow_redirects=True)
assert response.status_code == 200 # Assuming redirection to a valid page
_db.session.commit()
output_f = _db.session.get(Fund, test_round.fund_id,
options=[joinedload(Fund.rounds).joinedload(Round.sections)])
assert output is not None, "No values present in the db"
response = flask_test_client.get(f"/rounds/{test_round.round_id}/delete", follow_redirects=True)
assert response.status_code == 200 # Assuming redirection to a valid page
_db.session.commit()
output_f = _db.session.get(Fund, test_round.fund_id, options=[joinedload(Fund.rounds).joinedload(Round.sections)])
assert output_f is not None, "Grant deleted"
output_r = _db.session.query(Round).all()
assert not output_r, "Round delete did not happened"
output_s = _db.session.query(Section).all()
assert not output_s, "Section delete did not happened"
output_c = _db.session.query(Component).all()
assert not output_c, "Component delete did not happened"
output_l = _db.session.query(Lizt).all()
assert not output_l, "Lizt delete did not happened"
assert output_f is not None, "Grant deleted"
output_r = _db.session.query(Round).all()
assert not output_r, "Round delete did not happened"
output_s = _db.session.query(Section).all()
assert not output_s, "Section delete did not happened"
output_c = _db.session.query(Component).all()
assert not output_c, "Component delete did not happened"
output_l = _db.session.query(Lizt).all()
assert not output_l, "Lizt delete did not happened"

0 comments on commit 3f61a13

Please sign in to comment.