Skip to content

Commit

Permalink
added decorator for before firstrun only calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
Teja authored and Teja committed Sep 8, 2017
1 parent 4c6dfed commit c7e72d2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/octoprint/server/util/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,23 @@ def decorated_view(*args, **kwargs):
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
Expand Down

0 comments on commit c7e72d2

Please sign in to comment.