Commit 0f6e5e29 by Mark Meyer Committed by Torkel Ödegaard

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

Author:    Mark Meyer <mark@ofosos.org>
parent 7ae84451
...@@ -296,6 +296,12 @@ Set to `true` to automatically add new users to the main organization ...@@ -296,6 +296,12 @@ Set to `true` to automatically add new users to the main organization
(id 1). When set to `false`, new users will automatically cause a new (id 1). When set to `false`, new users will automatically cause a new
organization to be created for that new user. organization to be created for that new user.
### auto_assign_org_id
Set this value to automatically add new users to the provided org.
This requires `auto_assign_org` to be set to `true`. Please make sure
that this organization does already exists.
### auto_assign_org_role ### auto_assign_org_role
The role new users will be assigned for the main organization (if the The role new users will be assigned for the main organization (if the
......
...@@ -387,6 +387,7 @@ func insertTestDashboardForPlugin(title string, orgId int64, folderId int64, isF ...@@ -387,6 +387,7 @@ func insertTestDashboardForPlugin(title string, orgId int64, folderId int64, isF
func createUser(name string, role string, isAdmin bool) m.User { func createUser(name string, role string, isAdmin bool) m.User {
setting.AutoAssignOrg = true setting.AutoAssignOrg = true
setting.AutoAssignOrgId = 1
setting.AutoAssignOrgRole = role setting.AutoAssignOrgRole = role
currentUserCmd := m.CreateUserCommand{Login: name, Email: name + "@test.com", Name: "a " + name, IsAdmin: isAdmin} currentUserCmd := m.CreateUserCommand{Login: name, Email: name + "@test.com", Name: "a " + name, IsAdmin: isAdmin}
......
...@@ -17,6 +17,7 @@ func TestAccountDataAccess(t *testing.T) { ...@@ -17,6 +17,7 @@ func TestAccountDataAccess(t *testing.T) {
Convey("Given single org mode", func() { Convey("Given single org mode", func() {
setting.AutoAssignOrg = true setting.AutoAssignOrg = true
setting.AutoAssignOrgId = 1
setting.AutoAssignOrgRole = "Viewer" setting.AutoAssignOrgRole = "Viewer"
Convey("Users should be added to default organization", func() { Convey("Users should be added to default organization", func() {
......
...@@ -42,16 +42,23 @@ func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *DBSession) (int64, error ...@@ -42,16 +42,23 @@ func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *DBSession) (int64, error
var org m.Org var org m.Org
if setting.AutoAssignOrg { if setting.AutoAssignOrg {
// right now auto assign to org with id 1 has, err := sess.Where("id=?", setting.AutoAssignOrgId).Get(&org)
has, err := sess.Where("id=?", 1).Get(&org)
if err != nil { if err != nil {
return 0, err return 0, err
} }
if has { if has {
return org.Id, nil 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 { } else {
org.Name = cmd.OrgName org.Name = cmd.OrgName
if len(org.Name) == 0 { if len(org.Name) == 0 {
......
...@@ -100,6 +100,7 @@ var ( ...@@ -100,6 +100,7 @@ var (
AllowUserSignUp bool AllowUserSignUp bool
AllowUserOrgCreate bool AllowUserOrgCreate bool
AutoAssignOrg bool AutoAssignOrg bool
AutoAssignOrgId int
AutoAssignOrgRole string AutoAssignOrgRole string
VerifyEmailEnabled bool VerifyEmailEnabled bool
LoginHint string LoginHint string
...@@ -592,6 +593,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { ...@@ -592,6 +593,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
AllowUserSignUp = users.Key("allow_sign_up").MustBool(true) AllowUserSignUp = users.Key("allow_sign_up").MustBool(true)
AllowUserOrgCreate = users.Key("allow_org_create").MustBool(true) AllowUserOrgCreate = users.Key("allow_org_create").MustBool(true)
AutoAssignOrg = users.Key("auto_assign_org").MustBool(true) AutoAssignOrg = users.Key("auto_assign_org").MustBool(true)
AutoAssignOrgId = users.Key("auto_assign_org_id").MustInt(1)
AutoAssignOrgRole = users.Key("auto_assign_org_role").In("Editor", []string{"Editor", "Admin", "Viewer"}) AutoAssignOrgRole = users.Key("auto_assign_org_role").In("Editor", []string{"Editor", "Admin", "Viewer"})
VerifyEmailEnabled = users.Key("verify_email_enabled").MustBool(false) VerifyEmailEnabled = users.Key("verify_email_enabled").MustBool(false)
LoginHint = users.Key("login_hint").String() LoginHint = users.Key("login_hint").String()
......
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