Simplified single org settings, now auto_assign_org, and auto_assign_org_role, new [users] config section, Closes #1585
This commit is contained in:
@@ -15,9 +15,8 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
InitTestDB(t)
|
||||
|
||||
Convey("Given single org mode", func() {
|
||||
setting.SingleOrgMode = true
|
||||
setting.DefaultOrgName = "test"
|
||||
setting.DefaultOrgRole = "Viewer"
|
||||
setting.AutoAssignOrg = true
|
||||
setting.AutoAssignOrgRole = "Viewer"
|
||||
|
||||
Convey("Users should be added to default organization", func() {
|
||||
ac1cmd := m.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
||||
@@ -39,8 +38,7 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Given two saved users", func() {
|
||||
setting.SingleOrgMode = false
|
||||
setting.DefaultOrgName = "test"
|
||||
setting.AutoAssignOrg = false
|
||||
|
||||
ac1cmd := m.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
||||
ac2cmd := m.CreateUserCommand{Login: "ac2", Email: "ac2@test.com", Name: "ac2 name", IsAdmin: true}
|
||||
|
||||
@@ -33,15 +33,17 @@ func init() {
|
||||
func getOrgIdForNewUser(userEmail string, sess *session) (int64, error) {
|
||||
var org m.Org
|
||||
|
||||
if setting.SingleOrgMode {
|
||||
has, err := sess.Where("name=?", setting.DefaultOrgName).Get(&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 = setting.DefaultOrgName
|
||||
org.Name = "Main org."
|
||||
org.Id = 1
|
||||
}
|
||||
} else {
|
||||
org.Name = userEmail
|
||||
@@ -97,8 +99,8 @@ func CreateUser(cmd *m.CreateUserCommand) error {
|
||||
Updated: time.Now(),
|
||||
}
|
||||
|
||||
if setting.SingleOrgMode && !user.IsAdmin {
|
||||
orgUser.Role = m.RoleType(setting.DefaultOrgRole)
|
||||
if setting.AutoAssignOrg && !user.IsAdmin {
|
||||
orgUser.Role = m.RoleType(setting.AutoAssignOrgRole)
|
||||
}
|
||||
|
||||
if _, err = sess.Insert(&orgUser); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user