human_signup: clear error when the Gitea account's grant was already claimed under another handle

This commit is contained in:
leora 2026-10-10 12:36:36 +08:00
parent c46842f863
commit 7b49a53da5
2 changed files with 6 additions and 1 deletions

View File

@ -565,6 +565,11 @@ class CofferProduct:
raise ProductError("gitea_id is required") raise ProductError("gitea_id is required")
key = f"signup_grant:gitea:{gid}" key = f"signup_grant:gitea:{gid}"
with self._atomic(): with self._atomic():
row = self.db.execute("SELECT order_id FROM idempotency WHERE key=?", (key,)).fetchone()
if row is not None and row["order_id"].split("|", 1)[-1] != aid:
# Same Gitea user, different handle (e.g. a renamed account): the grant already went
# to the earlier wallet and is never given twice.
raise ProductError("signup grant already claimed for this Gitea account under another handle")
seen = self._claim(key, aid) seen = self._claim(key, aid)
if seen is not None: if seen is not None:
self.db.commit() self.db.commit()

View File

@ -33,7 +33,7 @@ class PeopleTests(unittest.TestCase):
def test_grant_keyed_on_gitea_id_rename_and_concurrency(self): def test_grant_keyed_on_gitea_id_rename_and_concurrency(self):
self.p.human_signup("sam", 101) self.p.human_signup("sam", 101)
with self.assertRaises(ProductError): # rename: the Gitea id already had its grant with self.assertRaisesRegex(ProductError, "already claimed for this Gitea account under another handle"): # rename
self.p.human_signup("sam-renamed", 101) self.p.human_signup("sam-renamed", 101)
self.assertEqual(self.p.balance("human:sam-renamed")["spendable"], 0.0) self.assertEqual(self.p.balance("human:sam-renamed")["spendable"], 0.0)
import threading import threading