From a017a9bf4afe20c94c37c71762b369dae894dc33 Mon Sep 17 00:00:00 2001 From: pycat Date: Tue, 2 May 2017 15:54:00 +0300 Subject: [PATCH] Split rerserved usernames list - possible solution demostration #551 This commit contains an implementation only for module repro - Loop through all the loaded modules - Get each module reserved_username attribute - Check the username against the reserved_username --- plinth/modules/repro/__init__.py | 2 +- plinth/modules/users/forms.py | 24 +++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/plinth/modules/repro/__init__.py b/plinth/modules/repro/__init__.py index 77e67b379..1d1443e2d 100644 --- a/plinth/modules/repro/__init__.py +++ b/plinth/modules/repro/__init__.py @@ -28,7 +28,6 @@ from plinth import cfg from plinth import frontpage from plinth import service as service_module from plinth.views import ServiceView - version = 2 depends = ['apps'] @@ -62,6 +61,7 @@ description = [ service = None +reserved_usernames = ['repro'] def init(): """Initialize the repro module.""" diff --git a/plinth/modules/users/forms.py b/plinth/modules/users/forms.py index 4b0bf5b9b..6c6f1961c 100644 --- a/plinth/modules/users/forms.py +++ b/plinth/modules/users/forms.py @@ -30,23 +30,7 @@ from plinth.errors import ActionError from plinth.modules import first_boot from plinth.modules.security import set_restricted_access from plinth.utils import is_user_admin - -# Usernames used by optional services (that might not be installed yet). -RESERVED_USERNAMES = [ - 'debian-deluged', - 'Debian-minetest', - 'debian-tor', - 'debian-transmission', - 'ejabberd', - 'ez-ipupd', - 'monkeysphere', - 'mumble-server', - 'node-restore', - 'quasselcore', - 'radicale', - 'repro', - 'privoxy', -] +from plinth import module_loader GROUP_CHOICES = ( ('admin', _('admin')), @@ -78,8 +62,10 @@ class ValidNewUsernameCheckMixin(object): except subprocess.CalledProcessError: pass - if username in RESERVED_USERNAMES: - return False + for module_name, module in module_loader.loaded_modules.items(): + for reserved_username in getattr(module, 'reserved_usernames', []): + if username == reserved_username: + return False return True