2022-10-08 11:05:46 -05:00
|
|
|
package store
|
2022-10-05 12:00:34 -05:00
|
|
|
|
|
|
|
import (
|
2022-10-05 20:46:17 -05:00
|
|
|
"fmt"
|
2022-10-05 12:00:34 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
|
|
|
)
|
|
|
|
|
2022-10-05 20:46:17 -05:00
|
|
|
// Really just spitballing here :) this should hook into a system that can give better display info
|
|
|
|
func GetUserIDString(user *user.SignedInUser) string {
|
2024-06-05 12:23:32 -05:00
|
|
|
// TODO: should we check IsDisabled?
|
|
|
|
// TODO: could we use the NamespacedID.ID() as prefix instead of manually
|
|
|
|
// setting "anon", "key", etc.?
|
2024-06-05 13:18:33 -05:00
|
|
|
// TODO: the default unauthenticated user is not anonymous and would be
|
|
|
|
// returned as `sys:0:` here. We may want to do something special in that
|
|
|
|
// case
|
2022-10-05 20:46:17 -05:00
|
|
|
if user == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2022-11-03 18:35:20 -05:00
|
|
|
if user.IsAnonymous {
|
|
|
|
return "anon"
|
|
|
|
}
|
|
|
|
if user.ApiKeyID > 0 {
|
|
|
|
return fmt.Sprintf("key:%d", user.UserID)
|
|
|
|
}
|
2022-10-05 20:46:17 -05:00
|
|
|
if user.IsRealUser() {
|
|
|
|
return fmt.Sprintf("user:%d:%s", user.UserID, user.Login)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("sys:%d:%s", user.UserID, user.Login)
|
|
|
|
}
|