2023-04-27 07:09:10 +02:00
|
|
|
package graph
|
|
|
|
|
|
|
|
|
|
import (
|
2026-01-17 22:53:46 +01:00
|
|
|
"gitea.unbound.se/unboundsoftware/schemas/domain"
|
|
|
|
|
"gitea.unbound.se/unboundsoftware/schemas/graph/model"
|
2023-04-27 07:09:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ToGqlOrganizations(orgs []domain.Organization) []*model.Organization {
|
|
|
|
|
result := make([]*model.Organization, len(orgs))
|
|
|
|
|
for i, o := range orgs {
|
|
|
|
|
result[i] = ToGqlOrganization(o)
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ToGqlOrganization(o domain.Organization) *model.Organization {
|
|
|
|
|
users := ToGqlUsers(o.Users)
|
|
|
|
|
apiKeys := ToGqlAPIKeys(o.APIKeys)
|
|
|
|
|
return &model.Organization{
|
|
|
|
|
ID: o.ID.String(),
|
|
|
|
|
Name: o.Name,
|
|
|
|
|
Users: users,
|
|
|
|
|
APIKeys: apiKeys,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ToGqlUsers(users []string) []*model.User {
|
|
|
|
|
result := make([]*model.User, len(users))
|
|
|
|
|
for i, u := range users {
|
|
|
|
|
result[i] = &model.User{ID: u}
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ToGqlAPIKeys(keys []domain.APIKey) []*model.APIKey {
|
|
|
|
|
result := make([]*model.APIKey, len(keys))
|
|
|
|
|
for i, k := range keys {
|
|
|
|
|
result[i] = &model.APIKey{
|
|
|
|
|
ID: apiKeyId(k.OrganizationId, k.Name),
|
|
|
|
|
Name: k.Name,
|
2025-11-20 22:11:17 +01:00
|
|
|
Key: nil, // Never return the hashed key - only return plaintext on creation
|
2023-04-27 07:09:10 +02:00
|
|
|
Organization: nil,
|
|
|
|
|
Refs: k.Refs,
|
|
|
|
|
Read: k.Read,
|
|
|
|
|
Publish: k.Publish,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|