From: Michael Tremer Date: Mon, 27 Apr 2015 12:55:01 +0000 (+0200) Subject: fireinfo: Allow updating stale profiles X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c748b468ef8de0632dc30cf6bc51777387e4b2e;p=ipfire.org.git fireinfo: Allow updating stale profiles --- diff --git a/webapp/backend/fireinfo.py b/webapp/backend/fireinfo.py index 7ce51083..f828743d 100644 --- a/webapp/backend/fireinfo.py +++ b/webapp/backend/fireinfo.py @@ -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 \