From ef585b6e3f294cd05dfe6e85abb3fb7ff7f3e040 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 29 Apr 2020 09:59:53 -0400 Subject: [PATCH] Prevent user from adding duplicate resources --- hubsrht/blueprints/mailing_lists.py | 4 +++- hubsrht/blueprints/sources.py | 10 ++++++++-- hubsrht/blueprints/trackers.py | 4 +++- hubsrht/templates/mailing-list-new.html | 8 ++++++++ hubsrht/templates/sources-select.html | 8 ++++++++ hubsrht/templates/tracker-new.html | 8 ++++++++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/hubsrht/blueprints/mailing_lists.py b/hubsrht/blueprints/mailing_lists.py index 33ccc8f..3100434 100644 --- a/hubsrht/blueprints/mailing_lists.py +++ b/hubsrht/blueprints/mailing_lists.py @@ -42,8 +42,10 @@ def new_GET(owner, project_name): # TODO: Pagination mls = lists.get_lists(owner) mls = sorted(mls, key=lambda r: r["updated"], reverse=True) + existing = [l.remote_id for l in (MailingList.query + .filter(MailingList.project_id == project.id)).all()] return render_template("mailing-list-new.html", view="new-resource", - owner=owner, project=project, lists=mls) + owner=owner, project=project, lists=mls, existing=existing) def lists_from_template(owner, project, template): project_url = url_for("projects.summary_GET", diff --git a/hubsrht/blueprints/sources.py b/hubsrht/blueprints/sources.py index 72afa1e..4cfe0b2 100644 --- a/hubsrht/blueprints/sources.py +++ b/hubsrht/blueprints/sources.py @@ -48,10 +48,13 @@ def git_new_GET(owner, project_name): # TODO: Pagination repos = git.get_repos(owner) repos = sorted(repos, key=lambda r: r["updated"], reverse=True) + existing = [r.remote_id for r in (SourceRepo.query + .filter(SourceRepo.project_id == project.id) + .filter(SourceRepo.repo_type == RepoType.git)).all()] return render_template("sources-select.html", view="new-resource", vcs="git", owner=owner, project=project, repos=repos, - existing=[]) # TODO: Fetch existing repos for this project + existing=existing) @sources.route("///hg/new") @loginrequired @@ -60,10 +63,13 @@ def hg_new_GET(owner, project_name): # TODO: Pagination repos = hg.get_repos(owner) repos = sorted(repos, key=lambda r: r["updated"], reverse=True) + existing = [r.remote_id for r in (SourceRepo.query + .filter(SourceRepo.project_id == project.id) + .filter(SourceRepo.repo_type == RepoType.hg)).all()] return render_template("sources-select.html", view="new-resource", vcs="hg", owner=owner, project=project, repos=repos, - existing=[]) # TODO: Fetch existing repos for this project + existing=existing) @sources.route("///git/new", methods=["POST"]) @loginrequired diff --git a/hubsrht/blueprints/trackers.py b/hubsrht/blueprints/trackers.py index 533d6c9..dc78fdb 100644 --- a/hubsrht/blueprints/trackers.py +++ b/hubsrht/blueprints/trackers.py @@ -39,8 +39,10 @@ def new_GET(owner, project_name): # TODO: Pagination trackers = todo.get_trackers(owner) trackers = sorted(trackers, key=lambda r: r["updated"], reverse=True) + existing = [t.remote_id for t in (Tracker.query + .filter(Tracker.project_id == project.id)).all()] return render_template("tracker-new.html", view="new-resource", - owner=owner, project=project, trackers=trackers) + owner=owner, project=project, trackers=trackers, existing=existing) @trackers.route("///trackers/new", methods=["POST"]) @loginrequired diff --git a/hubsrht/templates/mailing-list-new.html b/hubsrht/templates/mailing-list-new.html index e245925..1d1c4dc 100644 --- a/hubsrht/templates/mailing-list-new.html +++ b/hubsrht/templates/mailing-list-new.html @@ -136,11 +136,19 @@ {% for list in lists %}