mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
users: Fix admin group appearing twice in permissions
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
f3d2b64832
commit
14442b1db2
@ -44,8 +44,8 @@ first_boot_steps = [
|
|||||||
|
|
||||||
name = _('Users and Groups')
|
name = _('Users and Groups')
|
||||||
|
|
||||||
# List of all FreedomBox user groups
|
# All FreedomBox user groups
|
||||||
groups = set()
|
groups = dict()
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
@ -104,4 +104,4 @@ def remove_group(group):
|
|||||||
|
|
||||||
|
|
||||||
def register_group(group):
|
def register_group(group):
|
||||||
groups.add(group)
|
groups[group[0]] = group[1]
|
||||||
|
|||||||
@ -32,15 +32,15 @@ from plinth.modules import first_boot, users
|
|||||||
from plinth.modules.security import set_restricted_access
|
from plinth.modules.security import set_restricted_access
|
||||||
from plinth.translation import set_language
|
from plinth.translation import set_language
|
||||||
from plinth.utils import is_user_admin
|
from plinth.utils import is_user_admin
|
||||||
from plinth.models import UserProfile
|
|
||||||
|
|
||||||
|
|
||||||
def get_group_choices():
|
def get_group_choices():
|
||||||
"""Return localized group description and group name in one string."""
|
"""Return localized group description and group name in one string."""
|
||||||
admin_group = ('admin', _('Access to all services and system settings'))
|
admin_group = ('admin', _('Access to all services and system settings'))
|
||||||
users.register_group(admin_group)
|
users.register_group(admin_group)
|
||||||
choices = {(g[0], ('{} ({})'.format(g[1], g[0]))) for g in users.groups}
|
choices = [(k, ('{} ({})'.format(users.groups[k], k)))
|
||||||
return sorted(list(choices), key=lambda g: g[0])
|
for k in users.groups]
|
||||||
|
return sorted(choices, key=lambda g: g[0])
|
||||||
|
|
||||||
|
|
||||||
class ValidNewUsernameCheckMixin(object):
|
class ValidNewUsernameCheckMixin(object):
|
||||||
@ -115,18 +115,19 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
|
|||||||
user.userprofile.save()
|
user.userprofile.save()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('users', [
|
actions.superuser_run(
|
||||||
'create-user', user.get_username()
|
'users',
|
||||||
], input=self.cleaned_data['password1'].encode())
|
['create-user', user.get_username()],
|
||||||
|
input=self.cleaned_data['password1'].encode())
|
||||||
except ActionError:
|
except ActionError:
|
||||||
messages.error(self.request, _('Creating LDAP user failed.'))
|
messages.error(self.request, _('Creating LDAP user failed.'))
|
||||||
|
|
||||||
for group in self.cleaned_data['groups']:
|
for group in self.cleaned_data['groups']:
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('users', [
|
actions.superuser_run(
|
||||||
'add-user-to-group',
|
'users',
|
||||||
user.get_username(), group
|
['add-user-to-group',
|
||||||
])
|
user.get_username(), group])
|
||||||
except ActionError:
|
except ActionError:
|
||||||
messages.error(
|
messages.error(
|
||||||
self.request,
|
self.request,
|
||||||
@ -207,10 +208,10 @@ class UserUpdateForm(ValidNewUsernameCheckMixin,
|
|||||||
|
|
||||||
if self.username != user.get_username():
|
if self.username != user.get_username():
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('users', [
|
actions.superuser_run(
|
||||||
'rename-user', self.username,
|
'users',
|
||||||
user.get_username()
|
['rename-user', self.username,
|
||||||
])
|
user.get_username()])
|
||||||
except ActionError:
|
except ActionError:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Renaming LDAP user failed.'))
|
_('Renaming LDAP user failed.'))
|
||||||
@ -263,10 +264,10 @@ class UserChangePasswordForm(SetPasswordForm):
|
|||||||
user = super(UserChangePasswordForm, self).save(commit)
|
user = super(UserChangePasswordForm, self).save(commit)
|
||||||
if commit:
|
if commit:
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('users', [
|
actions.superuser_run(
|
||||||
'set-user-password',
|
'users', ['set-user-password',
|
||||||
user.get_username()
|
user.get_username()],
|
||||||
], input=self.cleaned_data['new_password1'].encode())
|
input=self.cleaned_data['new_password1'].encode())
|
||||||
except ActionError:
|
except ActionError:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Changing LDAP user password failed.'))
|
_('Changing LDAP user password failed.'))
|
||||||
@ -288,17 +289,18 @@ class FirstBootForm(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
|||||||
first_boot.mark_step_done('users_firstboot')
|
first_boot.mark_step_done('users_firstboot')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('users', [
|
actions.superuser_run(
|
||||||
'create-user', user.get_username()
|
'users',
|
||||||
], input=self.cleaned_data['password1'].encode())
|
['create-user', user.get_username()],
|
||||||
|
input=self.cleaned_data['password1'].encode())
|
||||||
except ActionError:
|
except ActionError:
|
||||||
messages.error(self.request, _('Creating LDAP user failed.'))
|
messages.error(self.request, _('Creating LDAP user failed.'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('users', [
|
actions.superuser_run(
|
||||||
'add-user-to-group',
|
'users',
|
||||||
user.get_username(), 'admin'
|
['add-user-to-group',
|
||||||
])
|
user.get_username(), 'admin'])
|
||||||
except ActionError:
|
except ActionError:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Failed to add new user to admin group.'))
|
_('Failed to add new user to admin group.'))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user