From c5b355705a22f2b0494f9b522cc752dabb90c6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 18 Aug 2015 13:30:23 +0200 Subject: [PATCH] Inject user manager into plugins --- docs/plugins/concepts.rst | 2 ++ src/octoprint/server/__init__.py | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/plugins/concepts.rst b/docs/plugins/concepts.rst index 42b66d37..6170ae5d 100644 --- a/docs/plugins/concepts.rst +++ b/docs/plugins/concepts.rst @@ -328,6 +328,8 @@ An overview of these properties follows. OctoPrint's printer management object, an instance of :class:`octoprint.printer.PrinterInterface`. ``self._app_session_manager`` OctoPrint's application session manager, an instance of :class:`octoprint.server.util.flask.AppSessionManager`. +``self._user_manager`` + OctoPrint's user manager, an instance of :class:`octoprint.users.UserManager`. .. seealso:: diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index a79494a9..afa0ccee 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -186,6 +186,15 @@ class Server(): appSessionManager = util.flask.AppSessionManager() pluginLifecycleManager = LifecycleManager(pluginManager) + # setup access control + if s.getBoolean(["accessControl", "enabled"]): + userManagerName = s.get(["accessControl", "userManager"]) + try: + clazz = octoprint.util.get_class(userManagerName) + userManager = clazz() + except AttributeError, e: + self._logger.exception("Could not instantiate user manager %s, will run with accessControl disabled!" % userManagerName) + def octoprint_plugin_inject_factory(name, implementation): if not isinstance(implementation, octoprint.plugin.OctoPrintPlugin): return None @@ -199,7 +208,8 @@ class Server(): printer=printer, app_session_manager=appSessionManager, plugin_lifecycle_manager=pluginLifecycleManager, - data_folder=os.path.join(settings().getBaseFolder("data"), name) + data_folder=os.path.join(settings().getBaseFolder("data"), name), + user_manager=userManager ) def settings_plugin_inject_factory(name, implementation): @@ -275,15 +285,6 @@ class Server(): if self._debug: events.DebugEventListener() - # setup access control - if s.getBoolean(["accessControl", "enabled"]): - userManagerName = s.get(["accessControl", "userManager"]) - try: - clazz = octoprint.util.get_class(userManagerName) - userManager = clazz() - except AttributeError, e: - self._logger.exception("Could not instantiate user manager %s, will run with accessControl disabled!" % userManagerName) - app.wsgi_app = util.ReverseProxied( app.wsgi_app, s.get(["server", "reverseProxy", "prefixHeader"]),