Identity: remove GetTypedID (#91745)
(cherry picked from commit bcfb66b416)
This commit is contained in:
@@ -592,21 +592,17 @@ func (s *Service) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (
|
||||
|
||||
user := cmd.SignedInUser
|
||||
|
||||
userID := int64(0)
|
||||
var err error
|
||||
namespaceID, userIDstr := user.GetTypedID()
|
||||
if namespaceID != identity.TypeUser && namespaceID != identity.TypeServiceAccount {
|
||||
s.log.Debug("User does not belong to a user or service account namespace, using 0 as user ID", "namespaceID", namespaceID, "userID", userIDstr)
|
||||
var userID int64
|
||||
if id, err := identity.UserIdentifier(cmd.SignedInUser.GetID()); err == nil {
|
||||
userID = id
|
||||
} else {
|
||||
userID, err = identity.IntIdentifier(namespaceID, userIDstr)
|
||||
if err != nil {
|
||||
s.log.Debug("failed to parse user ID", "namespaceID", namespaceID, "userID", userIDstr, "error", err)
|
||||
}
|
||||
s.log.Warn("User does not belong to a user or service account namespace, using 0 as user ID", "id", cmd.SignedInUser.GetID())
|
||||
}
|
||||
|
||||
if userID == 0 {
|
||||
userID = -1
|
||||
}
|
||||
|
||||
dashFolder.CreatedBy = userID
|
||||
dashFolder.UpdatedBy = userID
|
||||
dashFolder.UpdateSlug()
|
||||
@@ -682,8 +678,6 @@ func (s *Service) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (
|
||||
}
|
||||
|
||||
if cmd.NewTitle != nil {
|
||||
namespace, id := cmd.SignedInUser.GetTypedID()
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
|
||||
if err := s.bus.Publish(ctx, &events.FolderTitleUpdated{
|
||||
Timestamp: foldr.Updated,
|
||||
@@ -692,7 +686,7 @@ func (s *Service) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (
|
||||
UID: dashFolder.UID,
|
||||
OrgID: cmd.OrgID,
|
||||
}); err != nil {
|
||||
s.log.ErrorContext(ctx, "failed to publish FolderTitleUpdated event", "folder", foldr.Title, "user", id, "namespace", namespace, "error", err)
|
||||
s.log.ErrorContext(ctx, "failed to publish FolderTitleUpdated event", "folder", foldr.Title, "user", cmd.SignedInUser.GetID(), "error", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -739,12 +733,10 @@ func (s *Service) legacyUpdate(ctx context.Context, cmd *folder.UpdateFolderComm
|
||||
}
|
||||
|
||||
var userID int64
|
||||
namespace, id := cmd.SignedInUser.GetTypedID()
|
||||
if namespace == identity.TypeUser || namespace == identity.TypeServiceAccount {
|
||||
userID, err = identity.IntIdentifier(namespace, id)
|
||||
if err != nil {
|
||||
s.log.ErrorContext(ctx, "failed to parse user ID", "namespace", namespace, "userID", id, "error", err)
|
||||
}
|
||||
if id, err := identity.UserIdentifier(cmd.SignedInUser.GetID()); err == nil {
|
||||
userID = id
|
||||
} else {
|
||||
s.log.Warn("User does not belong to a user or service account namespace, using 0 as user ID", "id", cmd.SignedInUser.GetID())
|
||||
}
|
||||
|
||||
prepareForUpdate(dashFolder, cmd.OrgID, userID, cmd)
|
||||
@@ -1163,15 +1155,11 @@ func (s *Service) buildSaveDashboardCommand(ctx context.Context, dto *dashboards
|
||||
}
|
||||
}
|
||||
|
||||
userID := int64(0)
|
||||
namespaceID, userIDstr := dto.User.GetTypedID()
|
||||
if namespaceID != identity.TypeUser && namespaceID != identity.TypeServiceAccount {
|
||||
s.log.Warn("User does not belong to a user or service account namespace, using 0 as user ID", "namespaceID", namespaceID, "userID", userIDstr)
|
||||
var userID int64
|
||||
if id, err := identity.UserIdentifier(dto.User.GetID()); err == nil {
|
||||
userID = id
|
||||
} else {
|
||||
userID, err = identity.IntIdentifier(namespaceID, userIDstr)
|
||||
if err != nil {
|
||||
s.log.Warn("failed to parse user ID", "namespaceID", namespaceID, "userID", userIDstr, "error", err)
|
||||
}
|
||||
s.log.Warn("User does not belong to a user or service account namespace, using 0 as user ID", "id", dto.User.GetID())
|
||||
}
|
||||
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Folder).Inc()
|
||||
|
||||
Reference in New Issue
Block a user