mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-12-07 14:09:47 +00:00
Implements synchronizing an external user's quota group with provided OAuth2 claim. This functionality will allow system administrators to manage user's quota groups automatically. Documentation is at forgejo/docs#1337 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8554 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: thezzisu <thezzisu@gmail.com> Co-committed-by: thezzisu <thezzisu@gmail.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package auth
|
|
|
|
import (
|
|
"forgejo.org/modules/container"
|
|
"forgejo.org/modules/json"
|
|
"forgejo.org/modules/log"
|
|
)
|
|
|
|
func UnmarshalGroupTeamMapping(raw string) (map[string]map[string][]string, error) {
|
|
groupTeamMapping := make(map[string]map[string][]string)
|
|
if raw == "" {
|
|
return groupTeamMapping, nil
|
|
}
|
|
err := json.Unmarshal([]byte(raw), &groupTeamMapping)
|
|
if err != nil {
|
|
log.Error("Failed to unmarshal group team mapping: %v", err)
|
|
return nil, err
|
|
}
|
|
return groupTeamMapping, nil
|
|
}
|
|
|
|
func UnmarshalQuotaGroupMapping(raw string) (map[string]container.Set[string], error) {
|
|
quotaGroupMapping := make(map[string]container.Set[string])
|
|
if raw == "" {
|
|
return quotaGroupMapping, nil
|
|
}
|
|
|
|
rawMapping := make(map[string][]string)
|
|
err := json.Unmarshal([]byte(raw), &rawMapping)
|
|
if err != nil {
|
|
log.Error("Failed to unmarshal group quota group mapping: %v", err)
|
|
return nil, err
|
|
}
|
|
|
|
for key, values := range rawMapping {
|
|
set := make(container.Set[string])
|
|
set.AddMultiple(values...)
|
|
quotaGroupMapping[key] = set
|
|
}
|
|
|
|
return quotaGroupMapping, nil
|
|
}
|