From 3c6f828df21843634665fdc45407d9c49614a1da Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 9 Jul 2020 09:52:53 -0400 Subject: [PATCH] Fix project deletion SQLAlchemy's internal cascade handling is the most miserable, broken piece of shit I have ever had the displeasure of using. So we circumvent it entirely and let the SQL server do the right thing. A word of advice: don't use SQLAlchemy for new projects. --- hubsrht/blueprints/projects.py | 4 ++-- hubsrht/blueprints/public.py | 10 ++++++---- hubsrht/templates/dashboard.html | 3 +++ hubsrht/templates/new-user-dashboard.html | 3 +++ hubsrht/templates/project-config.html | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hubsrht/blueprints/projects.py b/hubsrht/blueprints/projects.py index 015bac2..d4c06a4 100644 --- a/hubsrht/blueprints/projects.py +++ b/hubsrht/blueprints/projects.py @@ -157,8 +157,8 @@ def config_POST(owner, project_name): @loginrequired def delete_POST(owner, project_name): owner, project = get_project(owner, project_name, ProjectAccess.write) - project.summary_repo_id = None - db.session.delete(project) + session["notice"] = f"{project.name} has been deleted." + db.engine.execute(f"DELETE FROM project WHERE id = {project.id}") db.session.commit() return redirect(url_for("public.index")) diff --git a/hubsrht/blueprints/public.py b/hubsrht/blueprints/public.py index ce28009..9de7ad2 100644 --- a/hubsrht/blueprints/public.py +++ b/hubsrht/blueprints/public.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, request +from flask import Blueprint, render_template, request, session from hubsrht.types import Project, Feature, Event, EventType, Visibility, User from srht.flask import paginate_query from srht.oauth import current_user, loginrequired @@ -9,6 +9,7 @@ public = Blueprint("public", __name__) @public.route("/") def index(): if current_user: + notice = session.pop("notice", None) projects = (Project.query .filter(Project.owner_id == current_user.id) .order_by(Project.updated.desc()) @@ -19,14 +20,15 @@ def index(): .order_by(Event.created.desc()) .limit(2)).all() return render_template("dashboard.html", - projects=projects, EventType=EventType, events=events) - return render_template("new-user-dashboard.html") + projects=projects, EventType=EventType, events=events, + notice=notice) + return render_template("new-user-dashboard.html", notice=notice) return render_template("index.html") @public.route("/getting-started") @loginrequired def getting_started(): - return render_template("new-user-dashboard.html") + return render_template("new-user-dashboard.html", notice=notice) @public.route("/projects") def project_index(): diff --git a/hubsrht/templates/dashboard.html b/hubsrht/templates/dashboard.html index 02f0192..8bbbe92 100644 --- a/hubsrht/templates/dashboard.html +++ b/hubsrht/templates/dashboard.html @@ -4,6 +4,9 @@ {{cfg("sr.ht", "site-name")}} dashboard {% endblock %} {% block content %} +{% if notice %} +
{{notice}}
+{% endif %}

diff --git a/hubsrht/templates/new-user-dashboard.html b/hubsrht/templates/new-user-dashboard.html index f9eb0f1..7b40ee2 100644 --- a/hubsrht/templates/new-user-dashboard.html +++ b/hubsrht/templates/new-user-dashboard.html @@ -3,6 +3,9 @@ {{cfg("sr.ht", "site-name")}} dashboard {% endblock %} {% block content %} +{% if notice %} +

{{notice}}
+{% endif %}
Welcome to {{cfg("sr.ht", "site-name")}}! diff --git a/hubsrht/templates/project-config.html b/hubsrht/templates/project-config.html index 2606791..eae663d 100644 --- a/hubsrht/templates/project-config.html +++ b/hubsrht/templates/project-config.html @@ -215,12 +215,14 @@ Delete project {{icon('caret-right')}}
+ {#
+ #}