mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
groups: Consistent listing of groups
- Remove conditional registration of groups on module initialization. - Create uninitialized groups on addition/update of groups for user. - Remove group creation on setup/installation of a module. Tested for: - Multi registration of groups. - Manual UI test to check visibility of groups irrespective of whether module is installed/enabled. Signed-off-by: Aakanksha Saini <aakanksa@thoughtworks.com> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
1 parent
834737d9dc
commit
0dea420ffe
7 files changed
+47
-13
No files matched your search
@@ -96,7 +96,6 @@ def _diagnose_ldap_entry(search_item):
|
||||
def create_group(group):
|
||||
"""Add an LDAP group."""
|
||||
actions.superuser_run('users', options=['create-group', group])
|
||||
register_group(group)
|
||||
|
||||
|
||||
def remove_group(group):
|
||||
|
||||
@@ -109,6 +109,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin, UserCreationForm):
|
||||
|
||||
for group in self.cleaned_data['groups']:
|
||||
try:
|
||||
users.create_group(group)
|
||||
actions.superuser_run('users', [
|
||||
'add-user-to-group',
|
||||
user.get_username(), group
|
||||
@@ -205,6 +206,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, forms.ModelForm):
|
||||
for new_group in new_groups:
|
||||
if new_group not in old_groups:
|
||||
try:
|
||||
users.create_group(new_group)
|
||||
actions.superuser_run('users', [
|
||||
'add-user-to-group',
|
||||
user.get_username(), new_group
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Test module to exercise group registration.
|
||||
|
||||
It is recommended to run this module with root privileges in a virtual machine.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
from plinth.modules import users
|
||||
|
||||
|
||||
class TestGroups(unittest.TestCase):
|
||||
"""Test groups behavior."""
|
||||
def test_register_group(self):
|
||||
"""Test for multi addition of same group"""
|
||||
group = ('TestGroup', 'Group for testing')
|
||||
users.register_group(group)
|
||||
users.register_group(group)
|
||||
self.assertEqual(
|
||||
len(users.groups), 1,
|
||||
'Duplicate entries for same group generated!')
|
||||
return users.groups
|
||||
Reference in new issue
Block a user