From c7e72d21c97b2239ba0722af0458e8c9bdb42b58 Mon Sep 17 00:00:00 2001 From: Teja Date: Fri, 8 Sep 2017 16:06:36 +0200 Subject: [PATCH] added decorator for before firstrun only calls. --- src/octoprint/server/util/flask.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 5f41d661..3da01689 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -1108,6 +1108,23 @@ def restricted_access(func): return decorated_view +def firstrun_only_access(func): + """ + If you decorate a view with this, it will ensure that first setup has _not_ been + done for OctoPrint's Access Control. Otherwise it + will cause a HTTP 403 status code to be returned by the decorated resource. + """ + @functools.wraps(func) + def decorated_view(*args, **kwargs): + # if OctoPrint has been set up yet, abort + if settings().getBoolean(["server", "firstRun"]) and (octoprint.server.userManager is None or not octoprint.server.userManager.hasBeenCustomized()): + return func(*args, **kwargs) + else: + return flask.make_response("OctoPrint is already setup, this resource is not longer available.", 403) + + return decorated_view + + class AppSessionManager(object): VALIDITY_UNVERIFIED = 1 * 60 # 1 minute