From a3df414f24b0ce66d32600405ee674edba7c6bf6 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 14 Mar 2022 22:11:26 +0100 Subject: [PATCH] sources/ldap: fix parent_group not being applied closes #2464 Signed-off-by: Jens Langhammer --- authentik/sources/ldap/sync/groups.py | 2 +- authentik/sources/ldap/tests/test_sync.py | 11 ++++++++--- web/src/user/LibraryPage.ts | 4 ++-- .../details/UserSettingsFlowExecutor.ts | 12 +++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/authentik/sources/ldap/sync/groups.py b/authentik/sources/ldap/sync/groups.py index 7a305a028..a1364ee22 100644 --- a/authentik/sources/ldap/sync/groups.py +++ b/authentik/sources/ldap/sync/groups.py @@ -37,6 +37,7 @@ class GroupLDAPSynchronizer(BaseLDAPSynchronizer): uniq = self._flatten(attributes[self._source.object_uniqueness_field]) try: defaults = self.build_group_properties(group_dn, **attributes) + defaults["parent"] = self._source.sync_parent_group self._logger.debug("Creating group with attributes", **defaults) if "name" not in defaults: raise IntegrityError("Name was not set by propertymappings") @@ -47,7 +48,6 @@ class GroupLDAPSynchronizer(BaseLDAPSynchronizer): Group, { f"attributes__{LDAP_UNIQUENESS}": uniq, - "parent": self._source.sync_parent_group, }, defaults, ) diff --git a/authentik/sources/ldap/tests/test_sync.py b/authentik/sources/ldap/tests/test_sync.py index af8e9d71b..0053adeea 100644 --- a/authentik/sources/ldap/tests/test_sync.py +++ b/authentik/sources/ldap/tests/test_sync.py @@ -5,6 +5,7 @@ from django.db.models import Q from django.test import TestCase from authentik.core.models import Group, User +from authentik.core.tests.utils import create_test_admin_user from authentik.events.models import Event, EventAction from authentik.lib.generators import generate_key from authentik.managed.manager import ObjectManager @@ -24,7 +25,7 @@ class LDAPSyncTests(TestCase): def setUp(self): ObjectManager().run() - self.source = LDAPSource.objects.create( + self.source: LDAPSource = LDAPSource.objects.create( name="ldap", slug="ldap", base_dn="dc=goauthentik,dc=io", @@ -120,6 +121,9 @@ class LDAPSyncTests(TestCase): self.source.property_mappings_group.set( LDAPPropertyMapping.objects.filter(managed="goauthentik.io/sources/ldap/default-name") ) + _user = create_test_admin_user() + parent_group = Group.objects.get(name=_user.username) + self.source.sync_parent_group = parent_group connection = PropertyMock(return_value=mock_ad_connection(LDAP_PASSWORD)) with patch("authentik.sources.ldap.models.LDAPSource.connection", connection): self.source.save() @@ -127,8 +131,9 @@ class LDAPSyncTests(TestCase): group_sync.sync() membership_sync = MembershipLDAPSynchronizer(self.source) membership_sync.sync() - group = Group.objects.filter(name="test-group") - self.assertTrue(group.exists()) + group: Group = Group.objects.filter(name="test-group").first() + self.assertIsNotNone(group) + self.assertEqual(group.parent, parent_group) def test_sync_groups_openldap(self): """Test group sync""" diff --git a/web/src/user/LibraryPage.ts b/web/src/user/LibraryPage.ts index cd0d5b5e4..3f0855619 100644 --- a/web/src/user/LibraryPage.ts +++ b/web/src/user/LibraryPage.ts @@ -165,9 +165,9 @@ export class LibraryPage extends LitElement {
${loading( this.apps, - html`${((this.apps?.results || []).filter((app) => { + html`${(this.apps?.results || []).filter((app) => { return app.launchUrl !== null; - })).length > 0 + }).length > 0 ? this.renderApps(config) : this.renderEmptyState()}`, )} diff --git a/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts b/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts index a9e9f1cca..3544753b9 100644 --- a/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts +++ b/web/src/user/user-settings/details/UserSettingsFlowExecutor.ts @@ -101,11 +101,13 @@ export class UserSettingsFlowExecutor extends LitElement implements StageHost { if (!this.flowSlug) { return; } - new FlowsApi(DEFAULT_CONFIG).flowsInstancesExecuteRetrieve({ - slug: this.flowSlug || "", - }).then(() => { - this.nextChallenge(); - }) + new FlowsApi(DEFAULT_CONFIG) + .flowsInstancesExecuteRetrieve({ + slug: this.flowSlug || "", + }) + .then(() => { + this.nextChallenge(); + }); }); }