From 17c20d12e0848c3331ed9c1b89ea4ea2ffcb1286 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Wed, 10 Feb 2021 20:21:45 +0100 Subject: [PATCH] refactor authentication / authorization into a mixin --- owrx/controllers/admin.py | 3 +-- owrx/controllers/profile.py | 5 +++-- owrx/controllers/settings.py | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/owrx/controllers/admin.py b/owrx/controllers/admin.py index 822bf63..dd87a5c 100644 --- a/owrx/controllers/admin.py +++ b/owrx/controllers/admin.py @@ -1,4 +1,3 @@ -from .template import WebpageController from .session import SessionStorage from owrx.config import Config from owrx.users import UserList @@ -25,7 +24,7 @@ class Authentication(object): return None -class AdminController(WebpageController): +class AuthorizationMixin(object): def __init__(self, handler, request, options): self.authentication = Authentication() self.user = self.authentication.getUser(request) diff --git a/owrx/controllers/profile.py b/owrx/controllers/profile.py index 6542553..6fd3aaf 100644 --- a/owrx/controllers/profile.py +++ b/owrx/controllers/profile.py @@ -1,9 +1,10 @@ -from owrx.controllers.admin import AdminController +from owrx.controllers.template import WebpageController +from owrx.controllers.admin import AuthorizationMixin from owrx.users import UserList, DefaultPasswordClass from urllib.parse import parse_qs -class ProfileController(AdminController): +class ProfileController(AuthorizationMixin, WebpageController): def isAuthorized(self): return self.user is not None and self.user.is_enabled() and self.user.must_change_password diff --git a/owrx/controllers/settings.py b/owrx/controllers/settings.py index c6004cb..b5531ba 100644 --- a/owrx/controllers/settings.py +++ b/owrx/controllers/settings.py @@ -1,4 +1,5 @@ -from .admin import AdminController +from owrx.controllers.template import WebpageController +from owrx.controllers.admin import AuthorizationMixin from owrx.config import Config, CoreConfig from urllib.parse import parse_qs from owrx.form import ( @@ -54,12 +55,12 @@ class Section(object): return {k: v for i in self.inputs for k, v in i.parse(data).items()} -class SettingsController(AdminController): +class SettingsController(AuthorizationMixin, WebpageController): def indexAction(self): self.serve_template("settings.html", **self.template_variables()) -class SdrSettingsController(AdminController): +class SdrSettingsController(AuthorizationMixin, WebpageController): def template_variables(self): variables = super().template_variables() variables["devices"] = self.render_devices() @@ -93,7 +94,7 @@ class SdrSettingsController(AdminController): self.serve_template("sdrsettings.html", **self.template_variables()) -class GeneralSettingsController(AdminController): +class GeneralSettingsController(AuthorizationMixin, WebpageController): sections = [ Section( "Receiver information",