Files
vikunja/frontend/src/helpers/parseScopesFromQuery.ts
T
kolaenteandGitHub ff01f8e859 feat(api-tokens): support title and scopes query parameters (#2143)
This allows external integrations to link directly to the API token creation page with pre-selected title and permission scopes. URLs can now use `?title=Name&scopes=group:perm,group:perm` format to pre-populate the form.

Example URL:
```
/user/settings/api-tokens?title=My%20Integration&scopes=tasks:create,tasks:delete,projects:read_all
```
2026-01-24 18:08:23 +00:00

24 lines
722 B
TypeScript

/**
* Parses scopes from a query parameter string in the format "group:permission,group:permission"
* @param scopesParam - The raw scopes query parameter value
* @returns An object mapping group names to arrays of permissions
*/
export function parseScopesFromQuery(scopesParam: string | null | undefined): Record<string, string[]> {
if (!scopesParam) return {}
const result: Record<string, string[]> = {}
const pairs = scopesParam.split(',').map(s => s.trim()).filter(Boolean)
for (const pair of pairs) {
const [group, permission] = pair.split(':').map(s => s.trim())
if (group && permission) {
if (!result[group]) {
result[group] = []
}
result[group].push(permission)
}
}
return result
}