You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2025/10/29 19:47:37 UTC
(tooling-trusted-releases) branch main updated: Show an upload warning when an OpenPGP key is already in the database
This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 0dd8843 Show an upload warning when an OpenPGP key is already in the database
0dd8843 is described below
commit 0dd8843fe2188f54b7440c042704ad18b38f51c2
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Wed Oct 29 19:47:03 2025 +0000
Show an upload warning when an OpenPGP key is already in the database
---
atr/shared/keys.py | 13 ++++++++++++-
atr/storage/writers/keys.py | 8 +++++---
playwright/test.py | 18 ++++++++++++++----
3 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/atr/shared/keys.py b/atr/shared/keys.py
index 34be485..563f8e8 100644
--- a/atr/shared/keys.py
+++ b/atr/shared/keys.py
@@ -32,6 +32,7 @@ import wtforms
import atr.db as db
import atr.forms as forms
import atr.get as get
+import atr.htm as htm
import atr.log as log
import atr.models.sql as sql
import atr.shared as shared
@@ -168,7 +169,17 @@ async def add(session: web.Committer) -> str:
)
oc.result_or_raise()
- await quart.flash(f"OpenPGP key {key.key_model.fingerprint.upper()} added successfully.", "success")
+ fingerprint_upper = key.key_model.fingerprint.upper()
+ if key.status == types.KeyStatus.PARSED:
+ details_url = util.as_url(get.keys.details, fingerprint=key.key_model.fingerprint)
+ p = htm.p[
+ f"OpenPGP key {fingerprint_upper} was already in the database. ",
+ htm.a(href=details_url)["View key details"],
+ ".",
+ ]
+ await quart.flash(str(p), "warning")
+ else:
+ await quart.flash(f"OpenPGP key {fingerprint_upper} added successfully.", "success")
# Clear form data on success by creating a new empty form instance
form = await AddOpenPGPKeyForm.create_form()
forms.choices(form.selected_committees, committee_choices)
diff --git a/atr/storage/writers/keys.py b/atr/storage/writers/keys.py
index 942c080..caf705d 100644
--- a/atr/storage/writers/keys.py
+++ b/atr/storage/writers/keys.py
@@ -250,12 +250,14 @@ class FoundationCommitter(GeneralPublic):
.on_conflict_do_nothing(index_elements=["fingerprint"])
.returning(via(sql.PublicSigningKey.fingerprint))
)
+ await self.__data.commit()
+
if key_insert_result.one_or_none() is None:
- # raise storage.AccessError(f"Key not inserted: {key.key_model.fingerprint}")
- pass
+ log.info(f"Key {key.key_model.fingerprint} already exists in database")
+ return outcome.Result(types.Key(status=types.KeyStatus.PARSED, key_model=key.key_model))
+
log.info(f"Inserted key {key.key_model.fingerprint}")
- await self.__data.commit()
# TODO: PARSED now acts as "ALREADY_ADDED"
return outcome.Result(types.Key(status=types.KeyStatus.INSERTED, key_model=key.key_model))
diff --git a/playwright/test.py b/playwright/test.py
index 5f31217..937ca1a 100755
--- a/playwright/test.py
+++ b/playwright/test.py
@@ -788,10 +788,20 @@ def test_openpgp_01_upload(page: sync_api.Page, credentials: Credentials) -> Non
wait_for_path(page, "/keys/add")
logging.info("Checking for success flash message on /keys/add page")
- flash_message_locator = page.locator("div.flash-success")
- sync_api.expect(flash_message_locator).to_be_visible()
- sync_api.expect(flash_message_locator).to_contain_text(f"OpenPGP key {key_fingerprint_upper} added successfully.")
- logging.info("OpenPGP key upload successful message shown")
+ try:
+ flash_message_locator = page.locator("div.flash-success")
+ sync_api.expect(flash_message_locator).to_be_visible()
+ sync_api.expect(flash_message_locator).to_contain_text(
+ f"OpenPGP key {key_fingerprint_upper} added successfully."
+ )
+ logging.info("OpenPGP key upload successful message shown")
+ except AssertionError:
+ flash_message_locator = page.locator("div.flash-warning")
+ sync_api.expect(flash_message_locator).to_be_visible()
+ sync_api.expect(flash_message_locator).to_contain_text(
+ f"OpenPGP key {key_fingerprint_upper} was already in the database."
+ )
+ logging.info("OpenPGP key already in database message shown")
logging.info("Navigating back to /keys to verify key presence")
go_to_path(page, "/keys")
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org