Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(rbac): close the selected role when the roles url has no role hash (#118781)

posthog[bot]53c24f774fe8
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.test.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.test.ts
new file mode 100644
index 000000000000..6c5467c35490
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.test.ts
@@ -0,0 +1,33 @@
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { urls } from 'scenes/urls'
+
+import { initKeaTests } from '~/test/init'
+
+import { roleAccessControlLogic } from './roleAccessControlLogic'
+
+describe('roleAccessControlLogic', () => {
+ let logic: ReturnType<typeof roleAccessControlLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ router.actions.push(urls.settings('organization-roles'), {}, { role: 'role-a' })
+ logic = roleAccessControlLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ })
+
+ it('syncs the selected role with the role in the URL hash', async () => {
+ await expectLogic(logic).toMatchValues({ selectedRoleId: 'role-a' })
+
+ router.actions.push(urls.settings('organization-roles'), {}, { role: 'role-b' })
+ await expectLogic(logic).toMatchValues({ selectedRoleId: 'role-b' })
+
+ router.actions.push(urls.settings('organization-roles'))
+ await expectLogic(logic).toMatchValues({ selectedRoleId: null })
+ })
+})
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.ts
index 1267128deba5..5e2007a573ea 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.ts
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/roleAccessControlLogic.ts
@@ -2,7 +2,7 @@ import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, redu
import { forms } from 'kea-forms'
import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'
import { loaders } from 'kea-loaders'
-import { actionToUrl, router } from 'kea-router'
+import { actionToUrl, router, urlToAction } from 'kea-router'
import { lemonToast } from '@posthog/lemon-ui'
@@ -10,6 +10,7 @@ import api from 'lib/api'
import { membersLogic } from 'scenes/organization/membersLogic'
import { organizationLogic } from 'scenes/organizationLogic'
import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
import { AccessControlResponseType, RoleType } from '~/types'
@@ -437,4 +438,13 @@ export const roleAccessControlLogic = kea<roleAccessControlLogicType>([
]
},
})),
+
+ urlToAction(({ actions, values }) => ({
+ [urls.settings('organization-roles')]: (_, __, hashParams) => {
+ const roleId = hashParams.role ?? null
+ if (roleId !== values.selectedRoleId) {
+ actions.selectRoleId(roleId)
+ }
+ },
+ })),
])