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
This commit is contained in:
pycat 2017-05-02 15:54:00 +03:00 committed by James Valleroy
parent 89146f64ce
commit a017a9bf4a
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 6 additions and 20 deletions

View File

@ -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."""

View File

@ -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