func getOrgIdForNewUser(userEmail string, sess *session) (int64, error) { var org m.Org if setting.AutoAssignOrg { // right now auto assign to org with id 1 has, err := sess.Where("id=?", 1).Get(&org) if err != nil { return 0, err } if has { return org.Id, nil } else { org.Name = "Main Org." org.Id = 1 } } else { org.Name = userEmail } org.Created = time.Now() org.Updated = time.Now() if _, err := sess.Insert(&org); err != nil { return 0, err } sess.publishAfterCommit(&events.OrgCreated{ Timestamp: org.Created, Id: org.Id, Name: org.Name, }) return org.Id, nil }
func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *session) (int64, error) { if cmd.SkipOrgSetup { return -1, nil } var org m.Org if setting.AutoAssignOrg { // right now auto assign to org with id 1 has, err := sess.Where("id=?", 1).Get(&org) if err != nil { return 0, err } if has { return org.Id, nil } else { org.Name = "Main Org." org.Id = 1 } } else { org.Name = cmd.OrgName if len(org.Name) == 0 { org.Name = util.StringsFallback2(cmd.Email, cmd.Login) } } org.Created = time.Now() org.Updated = time.Now() if _, err := sess.Insert(&org); err != nil { return 0, err } sess.publishAfterCommit(&events.OrgCreated{ Timestamp: org.Created, Id: org.Id, Name: org.Name, }) return org.Id, nil }