Replace signed in user for identity.requester (#73750)
* Make identity.Requester available at Context * Clean pkg/services/guardian/guardian.go * Clean guardian provider and guardian AC * Clean pkg/api/team.go * Clean ctxhandler, datasources, plugin and live * Question: what to do with the UserDisplayDTO? * Clean dashboards and guardian * Remove identity.Requester from ReqContext * Implement NewUserDisplayDTOFromRequester * Fix tests * Change status code numbers for http constants * Upgrade signature of ngalert services * log parsing errors instead of throwing error * Fix tests and add logs * linting
This commit is contained in:
@@ -43,6 +43,9 @@ func (u *SignedInUser) NameOrFallback() string {
|
||||
return u.Email
|
||||
}
|
||||
|
||||
// TODO: There's a need to remove this struct since it creates a circular dependency
|
||||
|
||||
// DEPRECATED: This function uses `UserDisplayDTO` model which we want to remove
|
||||
func (u *SignedInUser) ToUserDisplayDTO() *UserDisplayDTO {
|
||||
return &UserDisplayDTO{
|
||||
ID: u.UserID,
|
||||
@@ -51,6 +54,16 @@ func (u *SignedInUser) ToUserDisplayDTO() *UserDisplayDTO {
|
||||
}
|
||||
}
|
||||
|
||||
// Static function to parse a requester into a UserDisplayDTO
|
||||
func NewUserDisplayDTOFromRequester(requester identity.Requester) (*UserDisplayDTO, error) {
|
||||
userID, _ := identity.IntIdentifier(requester.GetNamespacedID())
|
||||
return &UserDisplayDTO{
|
||||
ID: userID,
|
||||
Login: requester.GetLogin(),
|
||||
Name: requester.GetDisplayName(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *SignedInUser) HasRole(role roletype.RoleType) bool {
|
||||
if u.IsGrafanaAdmin {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user