Allow settting of default org id to auto-assign to (#12401)

Author:    Mark Meyer <mark@ofosos.org>
This commit is contained in:
Mark Meyer
2018-07-13 12:14:40 -07:00
committed by Torkel Ödegaard
parent 7ae844518c
commit 0f6e5e2953
5 changed files with 21 additions and 4 deletions
+1
View File
@@ -387,6 +387,7 @@ func insertTestDashboardForPlugin(title string, orgId int64, folderId int64, isF
func createUser(name string, role string, isAdmin bool) m.User {
setting.AutoAssignOrg = true
setting.AutoAssignOrgId = 1
setting.AutoAssignOrgRole = role
currentUserCmd := m.CreateUserCommand{Login: name, Email: name + "@test.com", Name: "a " + name, IsAdmin: isAdmin}
+1
View File
@@ -17,6 +17,7 @@ func TestAccountDataAccess(t *testing.T) {
Convey("Given single org mode", func() {
setting.AutoAssignOrg = true
setting.AutoAssignOrgId = 1
setting.AutoAssignOrgRole = "Viewer"
Convey("Users should be added to default organization", func() {
+11 -4
View File
@@ -42,16 +42,23 @@ func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *DBSession) (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)
has, err := sess.Where("id=?", setting.AutoAssignOrgId).Get(&org)
if err != nil {
return 0, err
}
if has {
return org.Id, nil
} else {
if setting.AutoAssignOrgId == 1 {
org.Name = "Main Org."
org.Id = int64(setting.AutoAssignOrgId)
} else {
sqlog.Info("Could not create user: organization id %v does not exist",
setting.AutoAssignOrgId)
return 0, fmt.Errorf("Could not create user: organization id %v does not exist",
setting.AutoAssignOrgId)
}
}
org.Name = "Main Org."
org.Id = 1
} else {
org.Name = cmd.OrgName
if len(org.Name) == 0 {