Commit a1b1d2fe by Dan Cech

switch to Result

parent d5dd1c9b
...@@ -164,18 +164,18 @@ func OAuthLogin(ctx *m.ReqContext) { ...@@ -164,18 +164,18 @@ func OAuthLogin(ctx *m.ReqContext) {
} }
// add/update user in grafana // add/update user in grafana
userQuery := &m.UpsertUserCommand{ cmd := &m.UpsertUserCommand{
ExternalUser: &extUser, ExternalUser: &extUser,
SignupAllowed: connect.IsSignupAllowed(), SignupAllowed: connect.IsSignupAllowed(),
} }
err = login.UpsertUser(ctx, userQuery) err = login.UpsertUser(ctx, cmd)
if err != nil { if err != nil {
redirectWithError(ctx, err) redirectWithError(ctx, err)
return return
} }
// login // login
loginUserWithUser(userQuery.User, ctx) loginUserWithUser(cmd.Result, ctx)
metrics.M_Api_Login_OAuth.Inc() metrics.M_Api_Login_OAuth.Inc()
......
...@@ -39,15 +39,15 @@ var UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error { ...@@ -39,15 +39,15 @@ var UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error {
return ErrUsersQuotaReached return ErrUsersQuotaReached
} }
cmd.User, err = createUser(extUser) cmd.Result, err = createUser(extUser)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
cmd.User = userQuery.User cmd.Result = userQuery.User
// sync user info // sync user info
err = updateUser(cmd.User, extUser) err = updateUser(cmd.Result, extUser)
if err != nil { if err != nil {
return err return err
} }
...@@ -55,7 +55,7 @@ var UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error { ...@@ -55,7 +55,7 @@ var UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error {
if userQuery.UserAuth == nil && extUser.AuthModule != "" && extUser.AuthId != "" { if userQuery.UserAuth == nil && extUser.AuthModule != "" && extUser.AuthId != "" {
cmd2 := m.SetAuthInfoCommand{ cmd2 := m.SetAuthInfoCommand{
UserId: cmd.User.Id, UserId: cmd.Result.Id,
AuthModule: extUser.AuthModule, AuthModule: extUser.AuthModule,
AuthId: extUser.AuthId, AuthId: extUser.AuthId,
} }
...@@ -64,7 +64,7 @@ var UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error { ...@@ -64,7 +64,7 @@ var UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error {
} }
} }
err = syncOrgRoles(cmd.User, extUser) err = syncOrgRoles(cmd.Result, extUser)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -199,7 +199,7 @@ func (a *ldapAuther) GetGrafanaUserFor(ctx *m.ReqContext, ldapUser *LdapUserInfo ...@@ -199,7 +199,7 @@ func (a *ldapAuther) GetGrafanaUserFor(ctx *m.ReqContext, ldapUser *LdapUserInfo
return nil, err return nil, err
} }
return userQuery.User, nil return userQuery.Result, nil
} }
func (a *ldapAuther) serverBind() error { func (a *ldapAuther) serverBind() error {
......
...@@ -71,17 +71,17 @@ func initContextWithAuthProxy(ctx *m.ReqContext, orgID int64) bool { ...@@ -71,17 +71,17 @@ func initContextWithAuthProxy(ctx *m.ReqContext, orgID int64) bool {
} }
// add/update user in grafana // add/update user in grafana
userQuery := &m.UpsertUserCommand{ cmd := &m.UpsertUserCommand{
ExternalUser: &extUser, ExternalUser: &extUser,
SignupAllowed: setting.AuthProxyAutoSignUp, SignupAllowed: setting.AuthProxyAutoSignUp,
} }
err := login.UpsertUser(ctx, userQuery) err := login.UpsertUser(ctx, cmd)
if err != nil { if err != nil {
ctx.Handle(500, "Failed to login as user specified in auth proxy header", err) ctx.Handle(500, "Failed to login as user specified in auth proxy header", err)
return true return true
} }
query.UserId = userQuery.User.Id query.UserId = cmd.Result.Id
if err := bus.Dispatch(query); err != nil { if err := bus.Dispatch(query); err != nil {
ctx.Handle(500, "Failed to find user", err) ctx.Handle(500, "Failed to find user", err)
......
...@@ -184,7 +184,7 @@ func TestMiddlewareContext(t *testing.T) { ...@@ -184,7 +184,7 @@ func TestMiddlewareContext(t *testing.T) {
}) })
login.UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error { login.UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error {
cmd.User = &m.User{Id: 12} cmd.Result = &m.User{Id: 12}
return nil return nil
} }
...@@ -215,7 +215,7 @@ func TestMiddlewareContext(t *testing.T) { ...@@ -215,7 +215,7 @@ func TestMiddlewareContext(t *testing.T) {
}) })
login.UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error { login.UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error {
cmd.User = &m.User{Id: 33} cmd.Result = &m.User{Id: 33}
return nil return nil
} }
...@@ -277,7 +277,7 @@ func TestMiddlewareContext(t *testing.T) { ...@@ -277,7 +277,7 @@ func TestMiddlewareContext(t *testing.T) {
}) })
login.UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error { login.UpsertUser = func(ctx *m.ReqContext, cmd *m.UpsertUserCommand) error {
cmd.User = &m.User{Id: 33} cmd.Result = &m.User{Id: 33}
return nil return nil
} }
......
...@@ -29,7 +29,7 @@ type UpsertUserCommand struct { ...@@ -29,7 +29,7 @@ type UpsertUserCommand struct {
ExternalUser *ExternalUserInfo ExternalUser *ExternalUserInfo
SignupAllowed bool SignupAllowed bool
User *User Result *User
} }
type SetAuthInfoCommand struct { type SetAuthInfoCommand struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment