mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
users: Add component for managing users and groups
- Handle groups needed by an app.
- Handle reserved usernames for an app.
- Updated documentation
- Updated unit tests
Tests performed:
- Reserved usernames: ez-ipupd, ejabberd, Debian-minetest, mldonkey,
monkeysphere, mumble-server, privoxy, quasselcore, radicale, debian-tor,
debian-transmission
- Reserved usernames checks should work in the following forms:
- Create user
- Update user
- First boot user creation
- Full list of available groups should appear in following cases:
- Create user form
- Update user form
- Full list of groups should get created in Django DB during:
- Update user form display
- First boot form save
- When updating the last admin user, the 'admin' group choice is checked
and disabled.
- Following groups show up (sorted by group name):
- bit-torrent: Download files using BitTorrent applications
- git-access: Read-write access to Git repositories
- i2p: Manage I2P application
- wiki: View and edit wiki applications
- minidlna: Media streaming server
- ed2k: Download files using eDonkey applications
- freedombox-share: Access to the private shares
- web-search: Search the web
- syncthing: Administer Syncthing application
- feed-reader: Read and subscribe to news feeds
- admin: Access to all services and system settings
- Directory validation form checks for write permissions for following apps:
- deluge with debian-deluged user
- transmission with debian-transmission user
- Sharing app should show all the groups in add/edit share forms
- The following apps should get added to share group during setup:
debian-transmission
debian-deluged
- Unit tests pass
- Functional tests for users and groups pass
- Test that an app (example syncthing) provides the necessary
permissions to users in that group (but not in admin group).
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Fix i18n of group descriptions]
[sunil: Update developer documentation]
[sunil: Separate out cosmetic changes]
[sunil: Fix component ID for mumble]
[sunil: sharing: Remove unneeded dependency on users app]
[sunil: Implement better API for getting groups in component]
[sunil: Fix incorrect regression change ttrss app]
[sunil: Make iterating over gourps more readable]
[sunil: Improve tests, drop single use fixtures]
[sunil: Simplify test_view.py fixture]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Tested-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
e6e67f7d53
commit
e04ae48637
30 files changed
+344
-166
No files matched your search
@@ -3,7 +3,6 @@
|
||||
import pwd
|
||||
import re
|
||||
|
||||
import plinth.forms
|
||||
from django import forms
|
||||
from django.contrib import auth, messages
|
||||
from django.contrib.auth.forms import SetPasswordForm, UserCreationForm
|
||||
@@ -13,23 +12,17 @@ from django.core.exceptions import ValidationError
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.translation import ugettext_lazy
|
||||
from plinth import actions, module_loader
|
||||
|
||||
import plinth.forms
|
||||
from plinth import actions
|
||||
from plinth.errors import ActionError
|
||||
from plinth.modules import first_boot, users
|
||||
from plinth.modules import first_boot
|
||||
from plinth.modules.security import set_restricted_access
|
||||
from plinth.translation import set_language
|
||||
from plinth.utils import is_user_admin
|
||||
|
||||
from . import get_last_admin_user
|
||||
|
||||
|
||||
def get_group_choices():
|
||||
"""Return localized group description and group name in one string."""
|
||||
admin_group = ('admin', _('Access to all services and system settings'))
|
||||
users.register_group(admin_group)
|
||||
choices = [(k, ('{} ({})'.format(users.groups[k], k)))
|
||||
for k in users.groups]
|
||||
return sorted(choices, key=lambda g: g[0])
|
||||
from .components import UsersAndGroups
|
||||
|
||||
|
||||
class ValidNewUsernameCheckMixin(object):
|
||||
@@ -40,8 +33,8 @@ class ValidNewUsernameCheckMixin(object):
|
||||
username = self.cleaned_data['username']
|
||||
if self.instance.username != username and \
|
||||
not self.is_valid_new_username():
|
||||
raise ValidationError(
|
||||
_('Username is taken or is reserved.'), code='invalid')
|
||||
raise ValidationError(_('Username is taken or is reserved.'),
|
||||
code='invalid')
|
||||
|
||||
return username
|
||||
|
||||
@@ -52,10 +45,8 @@ class ValidNewUsernameCheckMixin(object):
|
||||
if username.lower() in existing_users:
|
||||
return False
|
||||
|
||||
for module_name, module in module_loader.loaded_modules.items():
|
||||
for reserved_username in getattr(module, 'reserved_usernames', []):
|
||||
if username.lower() == reserved_username.lower():
|
||||
return False
|
||||
if UsersAndGroups.is_username_reserved(username.lower()):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@@ -88,10 +79,9 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
|
||||
"""
|
||||
username = USERNAME_FIELD
|
||||
groups = forms.MultipleChoiceField(
|
||||
choices=get_group_choices(), label=ugettext_lazy('Permissions'),
|
||||
required=False, widget=forms.CheckboxSelectMultiple,
|
||||
help_text=ugettext_lazy(
|
||||
'Select which services should be available to the new '
|
||||
choices=UsersAndGroups.get_group_choices,
|
||||
label=ugettext_lazy('Permissions'), required=False,
|
||||
widget=forms.CheckboxSelectMultiple, help_text=ugettext_lazy(
|
||||
'user. The user will be able to log in to services that '
|
||||
'support single sign-on through LDAP, if they are in the '
|
||||
'appropriate group.<br /><br />Users in the admin group '
|
||||
@@ -109,7 +99,6 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
|
||||
"""Initialize the form with extra request argument."""
|
||||
self.request = request
|
||||
super(CreateUserForm, self).__init__(*args, **kwargs)
|
||||
self.fields['groups'].choices = get_group_choices()
|
||||
self.fields['username'].widget.attrs.update({
|
||||
'autofocus': 'autofocus',
|
||||
'autocapitalize': 'none',
|
||||
@@ -175,7 +164,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin,
|
||||
|
||||
def __init__(self, request, username, *args, **kwargs):
|
||||
"""Initialize the form with extra request argument."""
|
||||
group_choices = dict(get_group_choices())
|
||||
group_choices = dict(UsersAndGroups.get_group_choices())
|
||||
for group in group_choices:
|
||||
Group.objects.get_or_create(name=group)
|
||||
|
||||
@@ -313,9 +302,8 @@ class UserChangePasswordForm(SetPasswordForm):
|
||||
"""Initialize the form with extra request argument."""
|
||||
self.request = request
|
||||
super(UserChangePasswordForm, self).__init__(*args, **kwargs)
|
||||
self.fields['new_password1'].widget.attrs.update({
|
||||
'autofocus': 'autofocus'
|
||||
})
|
||||
self.fields['new_password1'].widget.attrs.update(
|
||||
{'autofocus': 'autofocus'})
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Save the user model and change LDAP password as well."""
|
||||
@@ -366,7 +354,7 @@ class FirstBootForm(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
||||
_('Failed to add new user to admin group.'))
|
||||
|
||||
# Create initial Django groups
|
||||
for group_choice in get_group_choices():
|
||||
for group_choice in UsersAndGroups.get_group_choices():
|
||||
auth.models.Group.objects.get_or_create(name=group_choice[0])
|
||||
|
||||
admin_group = auth.models.Group.objects.get(name='admin')
|
||||
|
||||
Reference in new issue
Block a user