Skip to content

Commit 129f823

Browse files
committed
Move/rename _handle_ldap_admin_status
Grokking what this function did from its name wasn't all too easy. Also, given all the other methods of the LdapBackend class, it fit better as an extra method of that class. Additionally, added a more explicit docstring.
1 parent 3136756 commit 129f823

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

python/nav/web/auth/ldap_auth_backend.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,29 @@ def _create_nav_account(ldap_user: "LDAPUser", password: str) -> Account:
112112
nav_account.save()
113113
return nav_account
114114

115-
@staticmethod
115+
@classmethod
116116
def _sync_nav_account(
117-
ldap_user: "LDAPUser", nav_user: Account, password: str
117+
cls, ldap_user: "LDAPUser", nav_user: Account, password: str
118118
) -> None:
119119
"""Ensures the necessary local account details are synced from LDAP user
120120
details.
121121
"""
122122
nav_user.set_password(password)
123123
nav_user.save()
124-
_handle_ldap_admin_status(ldap_user, nav_user)
125-
124+
cls._sync_nav_account_admin_privileges_from_ldap(ldap_user, nav_user)
126125

127-
def _handle_ldap_admin_status(ldap_user: "LDAPUser", nav_account: Account) -> None:
128-
is_admin = ldap_user.is_admin()
129-
# Only modify admin status if an entitlement is configured in webfront.conf
130-
if is_admin is not None:
131-
admin_group = AccountGroup.objects.get(id=AccountGroup.ADMIN_GROUP)
132-
if is_admin:
133-
nav_account.groups.add(admin_group)
134-
else:
135-
nav_account.groups.remove(admin_group)
126+
@staticmethod
127+
def _sync_nav_account_admin_privileges_from_ldap(
128+
ldap_user: "LDAPUser", nav_account: Account
129+
) -> None:
130+
"""Synchronizes the admin privileges of a given NAV account based on LDAP
131+
configuration parameters and the LDAP user object entitlements.
132+
"""
133+
is_admin = ldap_user.is_admin()
134+
# Only modify admin status if an entitlement is configured in webfront.conf
135+
if is_admin is not None:
136+
admin_group = AccountGroup.objects.get(id=AccountGroup.ADMIN_GROUP)
137+
if is_admin:
138+
nav_account.groups.add(admin_group)
139+
else:
140+
nav_account.groups.remove(admin_group)

0 commit comments

Comments
 (0)