Commit aa89416b by Torkel Ödegaard

fix(invite): fixes to org invite stuff, #2630

parent e93fba20
...@@ -154,10 +154,11 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor ...@@ -154,10 +154,11 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
} }
cmd := m.CreateUserCommand{ cmd := m.CreateUserCommand{
Email: completeInvite.Email, Email: completeInvite.Email,
Name: completeInvite.Name, Name: completeInvite.Name,
Login: completeInvite.Username, Login: completeInvite.Username,
Password: completeInvite.Password, Password: completeInvite.Password,
SkipOrgSetup: true,
} }
if err := bus.Dispatch(&cmd); err != nil { if err := bus.Dispatch(&cmd); err != nil {
......
...@@ -65,6 +65,7 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response { ...@@ -65,6 +65,7 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
OrgName: form.OrgName, OrgName: form.OrgName,
} }
// verify email
if setting.VerifyEmailEnabled { if setting.VerifyEmailEnabled {
if ok, rsp := verifyUserSignUpEmail(form.Email, form.Code); !ok { if ok, rsp := verifyUserSignUpEmail(form.Email, form.Code); !ok {
return rsp return rsp
...@@ -72,11 +73,13 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response { ...@@ -72,11 +73,13 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
createUserCmd.EmailVerified = true createUserCmd.EmailVerified = true
} }
// check if user exists
existing := m.GetUserByLoginQuery{LoginOrEmail: form.Email} existing := m.GetUserByLoginQuery{LoginOrEmail: form.Email}
if err := bus.Dispatch(&existing); err == nil { if err := bus.Dispatch(&existing); err == nil {
return ApiError(401, "User with same email address already exists", nil) return ApiError(401, "User with same email address already exists", nil)
} }
// dispatch create command
if err := bus.Dispatch(&createUserCmd); err != nil { if err := bus.Dispatch(&createUserCmd); err != nil {
return ApiError(500, "Failed to create user", err) return ApiError(500, "Failed to create user", err)
} }
......
...@@ -52,6 +52,7 @@ type CreateUserCommand struct { ...@@ -52,6 +52,7 @@ type CreateUserCommand struct {
Password string Password string
EmailVerified bool EmailVerified bool
IsAdmin bool IsAdmin bool
SkipOrgSetup bool
Result User Result User
} }
......
...@@ -153,7 +153,7 @@ func signUpCompletedHandler(evt *events.SignUpCompleted) error { ...@@ -153,7 +153,7 @@ func signUpCompletedHandler(evt *events.SignUpCompleted) error {
return sendEmailCommandHandler(&m.SendEmailCommand{ return sendEmailCommandHandler(&m.SendEmailCommand{
To: []string{evt.Email}, To: []string{evt.Email},
Template: tmplSignUpStarted, Template: tmplWelcomeOnSignUp,
Data: map[string]interface{}{ Data: map[string]interface{}{
"Name": evt.Name, "Name": evt.Name,
}, },
......
...@@ -30,6 +30,10 @@ func init() { ...@@ -30,6 +30,10 @@ func init() {
} }
func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *session) (int64, error) { func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *session) (int64, error) {
if cmd.SkipOrgSetup {
return -1, nil
}
var org m.Org var org m.Org
if setting.AutoAssignOrg { if setting.AutoAssignOrg {
...@@ -103,23 +107,6 @@ func CreateUser(cmd *m.CreateUserCommand) error { ...@@ -103,23 +107,6 @@ func CreateUser(cmd *m.CreateUserCommand) error {
return err return err
} }
// create org user link
orgUser := m.OrgUser{
OrgId: orgId,
UserId: user.Id,
Role: m.ROLE_ADMIN,
Created: time.Now(),
Updated: time.Now(),
}
if setting.AutoAssignOrg && !user.IsAdmin {
orgUser.Role = m.RoleType(setting.AutoAssignOrgRole)
}
if _, err = sess.Insert(&orgUser); err != nil {
return err
}
sess.publishAfterCommit(&events.UserCreated{ sess.publishAfterCommit(&events.UserCreated{
Timestamp: user.Created, Timestamp: user.Created,
Id: user.Id, Id: user.Id,
...@@ -129,6 +116,26 @@ func CreateUser(cmd *m.CreateUserCommand) error { ...@@ -129,6 +116,26 @@ func CreateUser(cmd *m.CreateUserCommand) error {
}) })
cmd.Result = user cmd.Result = user
// create org user link
if !cmd.SkipOrgSetup {
orgUser := m.OrgUser{
OrgId: orgId,
UserId: user.Id,
Role: m.ROLE_ADMIN,
Created: time.Now(),
Updated: time.Now(),
}
if setting.AutoAssignOrg && !user.IsAdmin {
orgUser.Role = m.RoleType(setting.AutoAssignOrgRole)
}
if _, err = sess.Insert(&orgUser); err != nil {
return err
}
}
return nil return nil
}) })
} }
......
...@@ -200,7 +200,7 @@ ...@@ -200,7 +200,7 @@
Multi format Multi format
</li> </li>
<li ng-show="current.multi"> <li ng-show="current.multi">
<select class="input-small tight-form-input last" ng-model="current.multiFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'regex values']"></select> <select class="input-medium tight-form-input last" ng-model="current.multiFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'regex values']"></select>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
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