From 5eb9ae7c4dff03249dda13f9102030da60ebbe57 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Fri, 1 Dec 2023 13:47:50 +0000 Subject: [PATCH] Fix add hash_ids on robots created before hash_id implementation --- robosats/middleware.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/robosats/middleware.py b/robosats/middleware.py index 8e27fc45..1c9036c9 100644 --- a/robosats/middleware.py +++ b/robosats/middleware.py @@ -90,6 +90,16 @@ class RobotTokenSHA256AuthenticationMiddleWare: try: if token.user.last_login < timezone.now() - timedelta(minutes=2): update_last_login(None, token.user) + + # START deprecate after v0.6.0 + # Add the hash_id to robots created before hash_ids were introduced + if not token.user.robot.hash_id: + token_sha256 = base91_to_hex(token_sha256_b91) + hash = hashlib.sha256(token_sha256.encode("utf-8")).hexdigest() + token.user.robot.hash_id = hash + token.user.robot.save(update_fields=["hash_id"]) + # END deprecate after v0.6.0 + except Exception: update_last_login(None, token.user)