Explorar o código

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

Torkel Ödegaard %!s(int64=10) %!d(string=hai) anos
pai
achega
aa89416bca

+ 5 - 4
pkg/api/org_invite.go

@@ -154,10 +154,11 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
 	}
 
 	cmd := m.CreateUserCommand{
-		Email:    completeInvite.Email,
-		Name:     completeInvite.Name,
-		Login:    completeInvite.Username,
-		Password: completeInvite.Password,
+		Email:        completeInvite.Email,
+		Name:         completeInvite.Name,
+		Login:        completeInvite.Username,
+		Password:     completeInvite.Password,
+		SkipOrgSetup: true,
 	}
 
 	if err := bus.Dispatch(&cmd); err != nil {

+ 3 - 0
pkg/api/signup.go

@@ -65,6 +65,7 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
 		OrgName:  form.OrgName,
 	}
 
+	// verify email
 	if setting.VerifyEmailEnabled {
 		if ok, rsp := verifyUserSignUpEmail(form.Email, form.Code); !ok {
 			return rsp
@@ -72,11 +73,13 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
 		createUserCmd.EmailVerified = true
 	}
 
+	// check if user exists
 	existing := m.GetUserByLoginQuery{LoginOrEmail: form.Email}
 	if err := bus.Dispatch(&existing); err == nil {
 		return ApiError(401, "User with same email address already exists", nil)
 	}
 
+	// dispatch create command
 	if err := bus.Dispatch(&createUserCmd); err != nil {
 		return ApiError(500, "Failed to create user", err)
 	}

+ 1 - 0
pkg/models/user.go

@@ -52,6 +52,7 @@ type CreateUserCommand struct {
 	Password      string
 	EmailVerified bool
 	IsAdmin       bool
+	SkipOrgSetup  bool
 
 	Result User
 }

+ 1 - 1
pkg/services/notifications/notifications.go

@@ -153,7 +153,7 @@ func signUpCompletedHandler(evt *events.SignUpCompleted) error {
 
 	return sendEmailCommandHandler(&m.SendEmailCommand{
 		To:       []string{evt.Email},
-		Template: tmplSignUpStarted,
+		Template: tmplWelcomeOnSignUp,
 		Data: map[string]interface{}{
 			"Name": evt.Name,
 		},

+ 24 - 17
pkg/services/sqlstore/user.go

@@ -30,6 +30,10 @@ func init() {
 }
 
 func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *session) (int64, error) {
+	if cmd.SkipOrgSetup {
+		return -1, nil
+	}
+
 	var org m.Org
 
 	if setting.AutoAssignOrg {
@@ -103,23 +107,6 @@ func CreateUser(cmd *m.CreateUserCommand) error {
 			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{
 			Timestamp: user.Created,
 			Id:        user.Id,
@@ -129,6 +116,26 @@ func CreateUser(cmd *m.CreateUserCommand) error {
 		})
 
 		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
 	})
 }

+ 1 - 1
public/app/features/templating/partials/editor.html

@@ -200,7 +200,7 @@
 								Multi format
 							</li>
 							<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>
 						</ul>
 						<div class="clearfix"></div>