From 65b5086a59d7cc94caceae24067c74c66e0fbcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20Toulet?= <35176601+AgnesToulet@users.noreply.github.com> Date: Mon, 26 Oct 2020 15:47:01 +0100 Subject: [PATCH] API: add login username in SendLoginLogCommand (#28544) * API: add login username in Login actions * LoginUser -> LoginUsername * fix test --- pkg/api/login.go | 11 ++++++----- pkg/api/login_test.go | 1 + pkg/models/user_auth.go | 13 +++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/api/login.go b/pkg/api/login.go index 25952330744..566c27aa321 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -178,11 +178,12 @@ func (hs *HTTPServer) LoginPost(c *models.ReqContext, cmd dtos.LoginCommand) Res err = errors.New(response.errMessage) } hs.SendLoginLog(&models.SendLoginLogCommand{ - ReqContext: c, - LogAction: action, - User: user, - HTTPStatus: response.status, - Error: err, + ReqContext: c, + LogAction: action, + User: user, + LoginUsername: cmd.User, + HTTPStatus: response.status, + Error: err, }) }() diff --git a/pkg/api/login_test.go b/pkg/api/login_test.go index c1925b9314a..8ecc506c83b 100644 --- a/pkg/api/login_test.go +++ b/pkg/api/login_test.go @@ -687,6 +687,7 @@ func TestLoginPostSendLoginLog(t *testing.T) { cmd := testReceiver.cmd assert.Equal(t, c.cmd.LogAction, cmd.LogAction) + assert.Equal(t, "admin", cmd.LoginUsername) assert.Equal(t, c.cmd.HTTPStatus, cmd.HTTPStatus) assert.Equal(t, c.cmd.Error, cmd.Error) diff --git a/pkg/models/user_auth.go b/pkg/models/user_auth.go index 80cd730a3a5..9ac44ce8612 100644 --- a/pkg/models/user_auth.go +++ b/pkg/models/user_auth.go @@ -66,12 +66,13 @@ type DeleteAuthInfoCommand struct { } type SendLoginLogCommand struct { - ReqContext *ReqContext - LogAction string - User *User - ExternalUser *ExternalUserInfo - HTTPStatus int - Error error + ReqContext *ReqContext + LogAction string + User *User + ExternalUser *ExternalUserInfo + LoginUsername string + HTTPStatus int + Error error } // ----------------------