Skip to content

Commit

Permalink
[change] Enable OrganizationUserAdmin by default
Browse files Browse the repository at this point in the history
If OrganizationUserAdmin is disabled, OrganizationOwnerInline
was loading a select with all the users in the DB, which
doesn't work on large databases.

This change enables this admin page by default and avoids
loading the OrganizationOwnerInline if OrganizationUserAdmin
is disabled.
  • Loading branch information
nemesifier committed Nov 10, 2023
1 parent d8ed5fe commit f363505
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
5 changes: 1 addition & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,12 @@ Settings
+--------------+------------------+
| **type**: | ``boolean`` |
+--------------+------------------+
| **default**: | ``False`` |
| **default**: | ``True`` |
+--------------+------------------+

Indicates whether the admin section for managing ``OrganizationUser`` items
is enabled or not.

It is disabled by default because these items can be managed via inline items
in the user administration section.

``OPENWISP_ORGANIZATION_OWNER_ADMIN``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
7 changes: 4 additions & 3 deletions openwisp_users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def _construct_form(self, i, **kwargs):
class OrganizationOwnerInline(admin.StackedInline):
model = OrganizationOwner
extra = 0
if app_settings.ORGANIZATION_USER_ADMIN and app_settings.ORGANIZATION_OWNER_ADMIN:
autocomplete_fields = ('organization_user',)
autocomplete_fields = ('organization_user',)

def has_change_permission(self, request, obj=None):
if obj and not request.user.is_superuser and not request.user.is_owner(obj):
Expand Down Expand Up @@ -498,7 +497,9 @@ class OrganizationAdmin(
MultitenantAdminMixin, BaseOrganizationAdmin, BaseAdmin, UUIDAdmin
):
view_on_site = False
inlines = [OrganizationOwnerInline]
# this inline has an autocomplete field pointing to OrganizationUserAdmin
if app_settings.ORGANIZATION_USER_ADMIN and app_settings.ORGANIZATION_OWNER_ADMIN:
inlines = [OrganizationOwnerInline]
readonly_fields = ['uuid', 'created', 'modified']
ordering = ['name']
list_display = ['name', 'is_active', 'created', 'modified']
Expand Down
6 changes: 3 additions & 3 deletions openwisp_users/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ def register_menu_group(self):
'name': 'changelist',
'icon': 'ow-org',
},
5: {
3: {
'label': _('Groups & Permissions'),
'model': get_model_name(self.app_label, 'Group'),
'name': 'changelist',
'icon': 'ow-permission',
},
}
if app_settings.ORGANIZATION_OWNER_ADMIN:
items[3] = {
items[4] = {
'label': _('Organization Owners'),
'model': get_model_name(self.app_label, 'OrganizationOwner'),
'name': 'changelist',
'icon': 'ow-org-owner',
}
if app_settings.ORGANIZATION_USER_ADMIN:
items[4] = {
items[5] = {
'label': _('Organization Users'),
'model': get_model_name(self.app_label, 'OrganizationUser'),
'name': 'changelist',
Expand Down
2 changes: 1 addition & 1 deletion openwisp_users/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from openwisp_utils.utils import default_or_test

ORGANIZATION_USER_ADMIN = getattr(settings, 'OPENWISP_ORGANIZATION_USER_ADMIN', False)
ORGANIZATION_USER_ADMIN = getattr(settings, 'OPENWISP_ORGANIZATION_USER_ADMIN', True)
ORGANIZATION_OWNER_ADMIN = getattr(settings, 'OPENWISP_ORGANIZATION_OWNER_ADMIN', True)
USERS_AUTH_API = getattr(settings, 'OPENWISP_USERS_AUTH_API', True)
USERS_AUTH_THROTTLE_RATE = getattr(
Expand Down
2 changes: 0 additions & 2 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_CACHE_ALIAS = 'default'

OPENWISP_ORGANIZATION_USER_ADMIN = True

if SAMPLE_APP:
users_index = INSTALLED_APPS.index('openwisp_users')
INSTALLED_APPS.insert(users_index, 'openwisp2.sample_users')
Expand Down

0 comments on commit f363505

Please sign in to comment.