]> git.ipfire.org Git - ipfire.org.git/commitdiff
fireinfo: Allow updating stale profiles
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Apr 2015 12:55:01 +0000 (14:55 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Apr 2015 12:55:01 +0000 (14:55 +0200)
webapp/backend/fireinfo.py

index 7ce51083092ec6d5891aa09f36c2f11599bdd8a9..f828743db9fef0b361c669344c56432f2ce5e656 100644 (file)
@@ -1462,16 +1462,27 @@ class Fireinfo(Object):
                return False
 
        def can_update_profile(self, public_id, private_id, when=None):
-               res = self.db.get("SELECT 1 FROM fireinfo_profiles \
-                       WHERE public_id = %s AND private_id = %s \
-                       AND time_updated + INTERVAL '60 minutes' <= then_or_now(%s) \
-                       AND time_valid >= then_or_now(%s) ORDER BY time_updated DESC LIMIT 1",
+               # Check if the profile has been updated very recently. If so we deny
+               # any new updates for some time.
+               res = self.db.get("WITH profiles AS (SELECT * FROM fireinfo_profiles \
+                       WHERE public_id = %s AND private_id = %s AND time_valid >= then_or_now(%s) \
+                               ORDER BY time_updated DESC LIMIT 1) \
+                       SELECT 1 FROM profiles WHERE then_or_now(%s) <= \
+                               time_updated + INTERVAL '60 minutes'",
                        public_id, private_id, when, when)
 
                if res:
-                       return True
+                       return False
 
-               return False
+               # Check if a profile exists with a different private id that is still valid
+               res = self.db.get("SELECT 1 FROM fireinfo_profiles \
+                       WHERE public_id = %s AND NOT private_id = %s \
+                       AND time_valid >= then_or_now(%s) LIMIT 1", public_id, private_id, when)
+
+               if res:
+                       return False
+
+               return True
 
        def get_profile(self, public_id, private_id=None, when=None):
                res = self.db.get("SELECT * FROM fireinfo_profiles \