mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
k8s dashboard - fix user parsing/fetching (#98635)
k8s dashboard - fix user parsing/fetching
This commit is contained in:
parent
58ed8a9ec2
commit
f20602ed42
@ -1511,23 +1511,17 @@ func (dr *DashboardServiceImpl) UnstructuredToLegacyDashboard(ctx context.Contex
|
||||
out.Deleted = obj.GetDeletionTimestamp().Time
|
||||
}
|
||||
|
||||
createdBy := obj.GetCreatedBy()
|
||||
if createdBy != "" && toUID(createdBy) != "" {
|
||||
creator, err := dr.userService.GetByUID(ctx, &user.GetUserByUIDQuery{UID: toUID(createdBy)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.CreatedBy = creator.ID
|
||||
creator, err := dr.getUserFromMeta(ctx, obj.GetCreatedBy())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.CreatedBy = creator.ID
|
||||
|
||||
updatedBy := obj.GetUpdatedBy()
|
||||
if updatedBy != "" && toUID(updatedBy) != "" {
|
||||
updator, err := dr.userService.GetByUID(ctx, &user.GetUserByUIDQuery{UID: toUID(updatedBy)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.UpdatedBy = updator.ID
|
||||
updater, err := dr.getUserFromMeta(ctx, obj.GetUpdatedBy())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.UpdatedBy = updater.ID
|
||||
|
||||
// any dashboards that have already been synced to unified storage will have the id in the spec
|
||||
// and not as a label. We will need to support this conversion until they have all been updated
|
||||
@ -1564,6 +1558,25 @@ func (dr *DashboardServiceImpl) UnstructuredToLegacyDashboard(ctx context.Contex
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) getUserFromMeta(ctx context.Context, userMeta string) (*user.User, error) {
|
||||
if userMeta == "" || toUID(userMeta) == "" {
|
||||
return &user.User{}, nil
|
||||
}
|
||||
usr, err := dr.getUser(ctx, toUID(userMeta))
|
||||
if err != nil && errors.Is(err, user.ErrUserNotFound) {
|
||||
return &user.User{}, nil
|
||||
}
|
||||
return usr, err
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) getUser(ctx context.Context, uid string) (*user.User, error) {
|
||||
userId, err := strconv.ParseInt(uid, 10, 64)
|
||||
if err == nil {
|
||||
return dr.userService.GetByID(ctx, &user.GetUserByIDQuery{ID: userId})
|
||||
}
|
||||
return dr.userService.GetByUID(ctx, &user.GetUserByUIDQuery{UID: uid})
|
||||
}
|
||||
|
||||
func LegacySaveCommandToUnstructured(cmd *dashboards.SaveDashboardCommand, namespace string) (unstructured.Unstructured, error) {
|
||||
uid := cmd.GetDashboardModel().UID
|
||||
if uid == "" {
|
||||
|
Loading…
Reference in New Issue
Block a user