Merge pull request #39008 from ShrihariMahabal/invalidate-accepted-user-invitation

fix: invalidate user invitation if already accepted
This commit is contained in:
Shrihari Mahabal 2026-04-29 19:32:28 +05:30 committed by GitHub
commit f185f03660
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View file

@ -129,7 +129,7 @@ def _accept_invitation(key: str, in_test: bool) -> None:
hashed_key = frappe.utils.sha256_hash(key)
invitation_name = frappe.db.get_value("User Invitation", filters={"key": hashed_key})
if not invitation_name:
frappe.throw(title=_("Error"), msg=_("Invalid key"))
frappe.throw(title=_("Error"), msg=_("Invalid or expired key"))
invitation = frappe.get_doc("User Invitation", invitation_name)
# accept invitation

View file

@ -39,9 +39,7 @@ class UserInvitation(Document):
self._after_insert()
def accept(self, ignore_permissions: bool = False):
accepted_now = self._accept()
if not accepted_now:
return
self._accept()
user, user_inserted = self._upsert_user(ignore_permissions)
self.save(ignore_permissions)
user.save(ignore_permissions)
@ -120,7 +118,7 @@ class UserInvitation(Document):
def _accept(self):
if self.status == "Accepted":
return False
frappe.throw(title=_("Error"), msg=_("Invitation already accepted"))
if self.status == "Expired":
frappe.throw(title=_("Error"), msg=_("Invitation is expired"))
if self.status == "Cancelled":
@ -128,6 +126,7 @@ class UserInvitation(Document):
self.status = "Accepted"
self.accepted_at = frappe.utils.now()
self.user = self.email
self.key = None
return True
def _upsert_user(self, ignore_permissions: bool = False):