mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-07-24 08:48:48 -05:00
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 ```
24 lines
722 B
TypeScript
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
|
|
}
|