API: Minor fix for team creation endpoint when using API key (#18252)
* Fix CreateTeam api endpoint No team member should be created for requests authenticated by API tokens. * Update middleware test Assert that `isAnonymous` is set for `SignedInUser` authenticated via API key. * Add test for team creation Assert that no team member is created if the signed in user is anomymous. * Revert "Fix CreateTeam api endpoint" This reverts commit9fcc4e67f5. * Revert "Update middleware test" This reverts commit75f767e58d. * Fix CreateTeam api endpoint No team member should be created for requests authenticated by API tokens. * Update team test * Change error to warning and update tests
This commit is contained in:
+15
-8
@@ -24,15 +24,22 @@ func (hs *HTTPServer) CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Respo
|
||||
}
|
||||
|
||||
if c.OrgRole == m.ROLE_EDITOR && hs.Cfg.EditorsCanAdmin {
|
||||
addMemberCmd := m.AddTeamMemberCommand{
|
||||
UserId: c.SignedInUser.UserId,
|
||||
OrgId: cmd.OrgId,
|
||||
TeamId: cmd.Result.Id,
|
||||
Permission: m.PERMISSION_ADMIN,
|
||||
}
|
||||
// if the request is authenticated using API tokens
|
||||
// the SignedInUser is an empty struct therefore
|
||||
// an additional check whether it is an actual user is required
|
||||
if c.SignedInUser.IsRealUser() {
|
||||
addMemberCmd := m.AddTeamMemberCommand{
|
||||
UserId: c.SignedInUser.UserId,
|
||||
OrgId: cmd.OrgId,
|
||||
TeamId: cmd.Result.Id,
|
||||
Permission: m.PERMISSION_ADMIN,
|
||||
}
|
||||
|
||||
if err := hs.Bus.Dispatch(&addMemberCmd); err != nil {
|
||||
c.Logger.Error("Could not add creator to team.", "error", err)
|
||||
if err := hs.Bus.Dispatch(&addMemberCmd); err != nil {
|
||||
c.Logger.Error("Could not add creator to team.", "error", err)
|
||||
}
|
||||
} else {
|
||||
c.Logger.Warn("Could not add creator to team because is not a real user.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user