: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(settings): match scope search on shown label, drop error above list (#86745)
posthog[bot]319a917c447a
diff --git a/frontend/src/lib/integrations/PosthogConnect.tsx b/frontend/src/lib/integrations/PosthogConnect.tsxindex 7aa7e652badb..2b9df395d17a 100644--- a/frontend/src/lib/integrations/PosthogConnect.tsx+++ b/frontend/src/lib/integrations/PosthogConnect.tsx@@ -8,7 +8,7 @@ import api from 'lib/api'import { ScopeAccessRow } from 'lib/components/ScopeAccessRow/ScopeAccessRow'import { TZLabel } from 'lib/components/TZLabel'import { integrationsLogic } from 'lib/integrations/integrationsLogic'-import { API_SCOPES, scopesArrayToObject, scopesObjectToArray } from 'lib/scopes'+import { API_SCOPES, scopeMatchesSearch, scopesArrayToObject, scopesObjectToArray } from 'lib/scopes'import { userLogic } from 'scenes/userLogic'import { IntegrationType } from '~/types'@@ -113,10 +113,10 @@ function ConnectModal({ isOpen, onClose }: { isOpen: boolean; onClose: () => voisetScopes(scopesObjectToArray(next))}- const filteredScopes = useMemo(() => {- const term = searchTerm.trim().toLowerCase()- return term ? GRANTABLE_SCOPES.filter((s) => s.objectName.toLowerCase().includes(term)) : GRANTABLE_SCOPES- }, [searchTerm])+ const filteredScopes = useMemo(+ () => GRANTABLE_SCOPES.filter((s) => scopeMatchesSearch(s, searchTerm)),+ [searchTerm]+ )return (<LemonModaldiff --git a/frontend/src/lib/scopes.test.ts b/frontend/src/lib/scopes.test.tsindex 9ab900ef9adb..8f0920b201b6 100644--- a/frontend/src/lib/scopes.test.ts+++ b/frontend/src/lib/scopes.test.ts@@ -5,6 +5,7 @@ import {API_SCOPES,API_SCOPES_OMITTED_FROM_MODAL,getScopeDescription,+ scopeMatchesSearch,} from 'lib/scopes'import { API_SCOPE_OBJECTS } from '~/types'@@ -53,6 +54,39 @@ describe('API_SCOPES modal coverage', () => {})})+describe('scopeMatchesSearch', () => {+ const featureFlag = { key: 'feature_flag', objectName: 'Feature flag', objectPlural: 'feature flags' }++ it('matches every scope for an empty or whitespace term', () => {+ expect(scopeMatchesSearch(featureFlag, '')).toBe(true)+ expect(scopeMatchesSearch(featureFlag, ' ')).toBe(true)+ })++ // The regression this guards: the picker shows objectName, so a search on that label must match.+ it.each([+ ['key', 'feature_flag'],+ ['objectName', 'Feature flag'],+ ['objectPlural', 'feature flags'],+ ['a single word from the label', 'flag'],+ ['tokens in any order', 'flag feature'],+ ])('matches on %s', (_field, term) => {+ expect(scopeMatchesSearch(featureFlag, term)).toBe(true)+ })++ it('matches on the info text and ignores non-string info', () => {+ expect(scopeMatchesSearch({ key: 'query', objectName: 'Query', info: 'Run SQL' }, 'sql')).toBe(true)+ expect(scopeMatchesSearch({ key: 'query', objectName: 'Query', info: undefined }, 'undefined')).toBe(false)+ })++ it('matches on label for rows that carry no objectName', () => {+ expect(scopeMatchesSearch({ key: 'cohort', label: 'Cohort' }, 'cohort')).toBe(true)+ })++ it('returns false when a token matches no field', () => {+ expect(scopeMatchesSearch(featureFlag, 'dashboard')).toBe(false)+ })+})+describe('API_KEY_SCOPE_PRESETS', () => {const findPreset = (value: string): (typeof API_KEY_SCOPE_PRESETS)[number] => {const preset = API_KEY_SCOPE_PRESETS.find((p) => p.value === value)diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsxindex 8b9f15da700d..93ddcec7e408 100644--- a/frontend/src/lib/scopes.tsx+++ b/frontend/src/lib/scopes.tsx@@ -17,6 +17,32 @@ export type APIScope = {unprivilegedExcluded?: boolean}+/** Fields a scope search matches against. `label` covers rows that show a name outside `objectName`. */+export type ScopeSearchFields = {+ key?: string+ objectName?: string+ objectPlural?: string+ label?: string+ info?: string | JSX.Element+}++/**+ * Shared scope-search matcher for every scope picker. It splits the term into tokens and requires+ * each token to appear in the scope's key, names, or info text, so a multi-word or plural search+ * still matches the label the row shows. Keep all pickers on this one matcher so they can't drift.+ */+export function scopeMatchesSearch(scope: ScopeSearchFields, searchTerm: string): boolean {+ const tokens = searchTerm.toLowerCase().trim().split(/\s+/).filter(Boolean)+ if (tokens.length === 0) {+ return true+ }+ const haystack = [scope.key, scope.objectName, scope.objectPlural, scope.label, scope.info]+ .filter((field): field is string => typeof field === 'string')+ .join(' ')+ .toLowerCase()+ return tokens.every((token) => haystack.includes(token))+}+// Scopes whose write action also writes a feature flag as a side effect (survey targeting flag,// early access feature linked flag), so they imply `feature_flag:write`. Single source of truth for// both the picker warning (attached below) and the auto-select in personalAPIKeysLogic, so the rulediff --git a/frontend/src/scenes/authentication/cli/cliAuthorizeLogic.ts b/frontend/src/scenes/authentication/cli/cliAuthorizeLogic.tsindex 164f0273addf..fca6b95ce61f 100644--- a/frontend/src/scenes/authentication/cli/cliAuthorizeLogic.ts+++ b/frontend/src/scenes/authentication/cli/cliAuthorizeLogic.ts@@ -5,7 +5,7 @@ import { loaders } from 'kea-loaders'import { urlToAction } from 'kea-router'import api from 'lib/api'-import { AGENT_CLI_API_KEY_SCOPES, API_SCOPES, APIScope, scopesArrayToObject } from 'lib/scopes'+import { AGENT_CLI_API_KEY_SCOPES, API_SCOPES, APIScope, scopeMatchesSearch, scopesArrayToObject } from 'lib/scopes'import { userLogic } from 'scenes/userLogic'import { OrganizationBasicType } from '~/types'@@ -356,16 +356,7 @@ export const cliAuthorizeLogic = kea<cliAuthorizeLogicType>([],filteredScopes: [(s) => [s.searchTerm],- (searchTerm: string): APIScope[] => {- const search = searchTerm.trim().toLowerCase()- if (!search) {- return API_SCOPES- }- return API_SCOPES.filter(- (scope) =>- scope.key.toLowerCase().includes(search) || scope.objectPlural.toLowerCase().includes(search)- )- },+ (searchTerm: string): APIScope[] => API_SCOPES.filter((scope) => scopeMatchesSearch(scope, searchTerm)),],allAccessSelected: [(s) => [s.authorize],diff --git a/frontend/src/scenes/settings/project/projectSecretAPIKeysLogic.tsx b/frontend/src/scenes/settings/project/projectSecretAPIKeysLogic.tsxindex b4e80e665f3e..87bface7b791 100644--- a/frontend/src/scenes/settings/project/projectSecretAPIKeysLogic.tsx+++ b/frontend/src/scenes/settings/project/projectSecretAPIKeysLogic.tsx@@ -15,6 +15,7 @@ import {PROJECT_SECRET_API_KEY_SCOPE_PRESETS,ProjectSecretAPIKeyAllowedScope,ProjectSecretAPIKeyScopePreset,+ scopeMatchesSearch,} from 'lib/scopes'import { capitalizeFirstLetter } from 'lib/utils/strings'import { teamLogic } from 'scenes/teamLogic'@@ -374,11 +375,7 @@ export const projectSecretAPIKeysLogic = kea<projectSecretAPIKeysLogicType>([label: PROJECT_SECRET_SCOPE_OBJECT_NAMES[key] ?? capitalizeFirstLetter(key.replace(/_/g, ' ')),disabledActions: allActions.filter((a) => !allowed.has(a)),}))- if (!searchTerm.trim()) {- return scopes- }- const lowerSearch = searchTerm.toLowerCase()- return scopes.filter(({ label }) => label.toLowerCase().includes(lowerSearch))+ return scopes.filter((scope) => scopeMatchesSearch(scope, searchTerm))},],availablePresets: [diff --git a/frontend/src/scenes/settings/user/PersonalAPIKeys.tsx b/frontend/src/scenes/settings/user/PersonalAPIKeys.tsxindex cfa84f026c3d..446c9f304198 100644--- a/frontend/src/scenes/settings/user/PersonalAPIKeys.tsx+++ b/frontend/src/scenes/settings/user/PersonalAPIKeys.tsx@@ -19,7 +19,6 @@ import {import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'import { ScopeAccessRow } from 'lib/components/ScopeAccessRow/ScopeAccessRow'-import { IconErrorOutline } from 'lib/lemon-ui/icons'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { LemonField } from 'lib/lemon-ui/LemonField'import { Link } from 'lib/lemon-ui/Link'@@ -187,7 +186,7 @@ export function EditKeyModal({ zIndex }: EditKeyModalProps): JSX.Element {</div><LemonField name="scopes">- {({ error }) => (+ {() => (<><p className="mb-0">Personal API keys are scoped to limit what actions they are able to do. We highly@@ -199,12 +198,6 @@ export function EditKeyModal({ zIndex }: EditKeyModalProps): JSX.Element {permissions.</p>- {error && (- <div className="text-danger flex items-center gap-1 text-sm">- <IconErrorOutline className="text-xl" /> {error}- </div>- )}-{allAccessSelected ? (<LemonBannertype="warning"diff --git a/frontend/src/scenes/settings/user/personalAPIKeysLogic.tsx b/frontend/src/scenes/settings/user/personalAPIKeysLogic.tsxindex 15a63a6eaf51..b193943b41f5 100644--- a/frontend/src/scenes/settings/user/personalAPIKeysLogic.tsx+++ b/frontend/src/scenes/settings/user/personalAPIKeysLogic.tsx@@ -15,6 +15,7 @@ import {APIScope,API_SCOPES,SCOPES_IMPLYING_FEATURE_FLAG_WRITE,+ scopeMatchesSearch,scopesArrayToObject,scopesObjectToArray,} from 'lib/scopes'@@ -440,25 +441,8 @@ export const personalAPIKeysLogic = kea<personalAPIKeysLogicType>([],filteredScopes: [(s) => [s.searchTerm, s.allowedScopes],- (searchTerm: string, allowedScopes: APIScope[]): APIScope[] => {- const scopes = allowedScopes-- if (!searchTerm.trim()) {- return scopes- }- const lowerSearch = searchTerm.toLowerCase().trim()- return scopes.filter((scope) => {- // Search in key (e.g., "feature_flag")- if (scope.key.toLowerCase().includes(lowerSearch)) {- return true- }- // Search in objectPlural (e.g., "feature flags")- if (scope.objectPlural.toLowerCase().includes(lowerSearch)) {- return true- }- return false- })- },+ (searchTerm: string, allowedScopes: APIScope[]): APIScope[] =>+ allowedScopes.filter((scope) => scopeMatchesSearch(scope, searchTerm)),],formScopeRadioValues: [(s) => [s.editingKey],