Repository: CTFd/CTFd

Issue:
Force update check
It looks like CTFd doesn't force check for updates on startup if `next_version_check` time hasn't been reached. This causes users to update CTFd but the banner indicating a new version will still be there. 

We should probably force update checks on start if update checks arent disabled. 


Discussion:

Resolving patch:
diff --git a/CTFd/__init__.py b/CTFd/__init__.py
--- a/CTFd/__init__.py
+++ b/CTFd/__init__.py
@@ -139,7 +139,7 @@ def create_app(config='CTFd.config.Config'):
         cache.init_app(app)
         app.cache = cache
 
-        update_check()
+        update_check(force=True)
 
         version = utils.get_config('ctf_version')
 
diff --git a/CTFd/utils.py b/CTFd/utils.py
--- a/CTFd/utils.py
+++ b/CTFd/utils.py
@@ -730,35 +730,42 @@ def base64decode(s, urldecode=False):
 
 
 def update_check(force=False):
-    update = app.config.get('UPDATE_CHECK') or force
+    # If UPDATE_CHECK is disabled don't check for updates at all.
+    if app.config.get('UPDATE_CHECK') is False:
+        return
+
+    # Get when we should check for updates next.
+    next_update_check = get_config('next_update_check') or 0
+
+    # If we have passed our saved time or we are forcing we should check.
+    update = (next_update_check < time.time()) or force
+
     if update:
-        next_update_check = get_config('next_update_check') or 0
-        if (next_update_check < time.time()) or force:
+        try:
+            params = {
+                'current': app.VERSION
+            }
+            check = requests.get(
+                'https://versioning.ctfd.io/versions/latest',
+                params=params,
+                timeout=0.1
+            ).json()
+        except requests.exceptions.RequestException as e:
+            pass
+        else:
             try:
-                params = {
-                    'current': app.VERSION
-                }
-                check = requests.get(
-                    'https://versioning.ctfd.io/versions/latest',
-                    params=params,
-                    timeout=0.1
-                ).json()
-            except requests.exceptions.RequestException as e:
-                pass
-            else:
-                try:
-                    latest = check['resource']['tag']
-                    html_url = check['resource']['html_url']
-                    if StrictVersion(latest) > StrictVersion(app.VERSION):
-                        set_config('version_latest', html_url)
-                    elif StrictVersion(latest) <= StrictVersion(app.VERSION):
-                        set_config('version_latest', None)
-                except KeyError:
+                latest = check['resource']['tag']
+                html_url = check['resource']['html_url']
+                if StrictVersion(latest) > StrictVersion(app.VERSION):
+                    set_config('version_latest', html_url)
+                elif StrictVersion(latest) <= StrictVersion(app.VERSION):
                     set_config('version_latest', None)
-            finally:
-                # 12 hours later
-                next_update_check_time = int(time.time() + 43200)
-                set_config('next_update_check', next_update_check_time)
+            except KeyError:
+                set_config('version_latest', None)
+        finally:
+            # 12 hours later
+            next_update_check_time = int(time.time() + 43200)
+            set_config('next_update_check', next_update_check_time)
     else:
         set_config('version_latest', None)
 


Test patch: