mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package preferences
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana/pkg/kinds/preferences"
|
|
"github.com/grafana/grafana/pkg/services/store/entity"
|
|
)
|
|
|
|
func GetEntityKindInfo() entity.EntityKindInfo {
|
|
return entity.EntityKindInfo{
|
|
ID: entity.StandardKindPreferences,
|
|
Name: "Preferences",
|
|
}
|
|
}
|
|
|
|
func GetEntitySummaryBuilder() entity.EntitySummaryBuilder {
|
|
return func(ctx context.Context, uid string, body []byte) (*entity.EntitySummary, []byte, error) {
|
|
if uid != "default" {
|
|
if !(strings.HasPrefix(uid, "user-") || strings.HasPrefix(uid, "team-")) {
|
|
return nil, nil, fmt.Errorf("expecting UID: default, user-{#}, or team-{#}")
|
|
}
|
|
}
|
|
|
|
obj := &preferences.Spec{}
|
|
err := json.Unmarshal(body, obj)
|
|
if err != nil {
|
|
return nil, nil, err // unable to read object
|
|
}
|
|
|
|
summary := &entity.EntitySummary{
|
|
Kind: entity.StandardKindPreferences,
|
|
Name: uid, // team-${id} | user-${id}
|
|
UID: uid,
|
|
}
|
|
|
|
if obj.HomeDashboardUID != nil && *obj.HomeDashboardUID != "" {
|
|
summary.References = append(summary.References, &entity.EntityExternalReference{
|
|
Family: entity.StandardKindDashboard,
|
|
Identifier: *obj.HomeDashboardUID,
|
|
})
|
|
}
|
|
|
|
out, err := json.MarshalIndent(obj, "", " ")
|
|
return summary, out, err
|
|
}
|
|
}
|