mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Simplified single org settings, now auto_assign_org, and auto_assign_org_role, new [users] config section, Closes #1585
This commit is contained in:
parent
4f03a86414
commit
f3d4d2782f
@ -60,24 +60,24 @@ secret_key = SW2YcwTIb9zpOOhoPsMm
|
|||||||
login_remember_days = 7
|
login_remember_days = 7
|
||||||
cookie_username = grafana_user
|
cookie_username = grafana_user
|
||||||
cookie_remember_name = grafana_remember
|
cookie_remember_name = grafana_remember
|
||||||
; disable user signup / registration
|
|
||||||
disable_user_signup = false
|
|
||||||
|
|
||||||
[account.single]
|
[users]
|
||||||
; Enable this feature to auto assign new users to a single account, suitable for NON multi tenant setups
|
; disable user signup / registration
|
||||||
enabled = true
|
allow_sign_up = true
|
||||||
; Name of default account
|
; Allow non admin users to create organizations
|
||||||
account_name = main
|
allow_org_create = true
|
||||||
; Default role new users will be automatically assigned
|
# Set to true to automatically assign new users to the default organization (id 1)
|
||||||
default_role = Editor
|
auto_assign_org = true
|
||||||
|
; Default role new users will be automatically assigned (if disabled above is set to true)
|
||||||
|
auto_assign_org_role = Viewer
|
||||||
|
|
||||||
[auth.anonymous]
|
[auth.anonymous]
|
||||||
; enable anonymous access
|
; enable anonymous access
|
||||||
enabled = false
|
enabled = false
|
||||||
; specify account name that should be used for unauthenticated users
|
; specify organization name that should be used for unauthenticated users
|
||||||
account_name = main
|
org_name = main
|
||||||
; specify role for unauthenticated users
|
; specify role for unauthenticated users
|
||||||
account_role = Viewer
|
org_role = Viewer
|
||||||
|
|
||||||
[auth.github]
|
[auth.github]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
@ -25,7 +25,7 @@ func LoginView(c *middleware.Context) {
|
|||||||
settings := c.Data["Settings"].(map[string]interface{})
|
settings := c.Data["Settings"].(map[string]interface{})
|
||||||
settings["googleAuthEnabled"] = setting.OAuthService.Google
|
settings["googleAuthEnabled"] = setting.OAuthService.Google
|
||||||
settings["githubAuthEnabled"] = setting.OAuthService.GitHub
|
settings["githubAuthEnabled"] = setting.OAuthService.GitHub
|
||||||
settings["disableUserSignUp"] = setting.DisableUserSignUp
|
settings["disableUserSignUp"] = !setting.AllowUserSignUp
|
||||||
|
|
||||||
// Check auto-login.
|
// Check auto-login.
|
||||||
uname := c.GetCookie(setting.CookieUserName)
|
uname := c.GetCookie(setting.CookieUserName)
|
||||||
|
@ -56,7 +56,7 @@ func OAuthLogin(ctx *middleware.Context) {
|
|||||||
|
|
||||||
// create account if missing
|
// create account if missing
|
||||||
if err == m.ErrUserNotFound {
|
if err == m.ErrUserNotFound {
|
||||||
if setting.DisableUserSignUp {
|
if !setting.AllowUserSignUp {
|
||||||
ctx.Redirect(setting.AppSubUrl + "/login")
|
ctx.Redirect(setting.AppSubUrl + "/login")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
// POST /api/user/signup
|
// POST /api/user/signup
|
||||||
func SignUp(c *middleware.Context, cmd m.CreateUserCommand) {
|
func SignUp(c *middleware.Context, cmd m.CreateUserCommand) {
|
||||||
if setting.DisableUserSignUp {
|
if !setting.AllowUserSignUp {
|
||||||
c.JsonApiErr(401, "User signup is disabled", nil)
|
c.JsonApiErr(401, "User signup is disabled", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,8 @@ func TestAccountDataAccess(t *testing.T) {
|
|||||||
InitTestDB(t)
|
InitTestDB(t)
|
||||||
|
|
||||||
Convey("Given single org mode", func() {
|
Convey("Given single org mode", func() {
|
||||||
setting.SingleOrgMode = true
|
setting.AutoAssignOrg = true
|
||||||
setting.DefaultOrgName = "test"
|
setting.AutoAssignOrgRole = "Viewer"
|
||||||
setting.DefaultOrgRole = "Viewer"
|
|
||||||
|
|
||||||
Convey("Users should be added to default organization", func() {
|
Convey("Users should be added to default organization", func() {
|
||||||
ac1cmd := m.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
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() {
|
Convey("Given two saved users", func() {
|
||||||
setting.SingleOrgMode = false
|
setting.AutoAssignOrg = false
|
||||||
setting.DefaultOrgName = "test"
|
|
||||||
|
|
||||||
ac1cmd := m.CreateUserCommand{Login: "ac1", Email: "ac1@test.com", Name: "ac1 name"}
|
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}
|
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) {
|
func getOrgIdForNewUser(userEmail string, sess *session) (int64, error) {
|
||||||
var org m.Org
|
var org m.Org
|
||||||
|
|
||||||
if setting.SingleOrgMode {
|
if setting.AutoAssignOrg {
|
||||||
has, err := sess.Where("name=?", setting.DefaultOrgName).Get(&org)
|
// right now auto assign to org with id 1
|
||||||
|
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 {
|
} else {
|
||||||
org.Name = setting.DefaultOrgName
|
org.Name = "Main org."
|
||||||
|
org.Id = 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
org.Name = userEmail
|
org.Name = userEmail
|
||||||
@ -97,8 +99,8 @@ func CreateUser(cmd *m.CreateUserCommand) error {
|
|||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if setting.SingleOrgMode && !user.IsAdmin {
|
if setting.AutoAssignOrg && !user.IsAdmin {
|
||||||
orgUser.Role = m.RoleType(setting.DefaultOrgRole)
|
orgUser.Role = m.RoleType(setting.AutoAssignOrgRole)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = sess.Insert(&orgUser); err != nil {
|
if _, err = sess.Insert(&orgUser); err != nil {
|
||||||
|
@ -64,12 +64,12 @@ var (
|
|||||||
LogInRememberDays int
|
LogInRememberDays int
|
||||||
CookieUserName string
|
CookieUserName string
|
||||||
CookieRememberName string
|
CookieRememberName string
|
||||||
DisableUserSignUp bool
|
|
||||||
|
|
||||||
// single organization
|
// User settings
|
||||||
SingleOrgMode bool
|
AllowUserSignUp bool
|
||||||
DefaultOrgName string
|
AllowUserOrgCreate bool
|
||||||
DefaultOrgRole string
|
AutoAssignOrg bool
|
||||||
|
AutoAssignOrgRole string
|
||||||
|
|
||||||
// Http auth
|
// Http auth
|
||||||
AdminUser string
|
AdminUser string
|
||||||
@ -214,16 +214,15 @@ func NewConfigContext(config string) {
|
|||||||
LogInRememberDays = security.Key("login_remember_days").MustInt()
|
LogInRememberDays = security.Key("login_remember_days").MustInt()
|
||||||
CookieUserName = security.Key("cookie_username").String()
|
CookieUserName = security.Key("cookie_username").String()
|
||||||
CookieRememberName = security.Key("cookie_remember_name").String()
|
CookieRememberName = security.Key("cookie_remember_name").String()
|
||||||
DisableUserSignUp = security.Key("disable_user_signup").MustBool(false)
|
|
||||||
|
|
||||||
// admin
|
// admin
|
||||||
AdminUser = security.Key("admin_user").String()
|
AdminUser = security.Key("admin_user").String()
|
||||||
AdminPassword = security.Key("admin_password").String()
|
AdminPassword = security.Key("admin_password").String()
|
||||||
|
|
||||||
// single account
|
users := Cfg.Section("users")
|
||||||
SingleOrgMode = Cfg.Section("organization.single").Key("enabled").MustBool(false)
|
AllowUserSignUp = users.Key("allow_sign_up").MustBool(true)
|
||||||
DefaultOrgName = Cfg.Section("organization.single").Key("org_name").MustString("main")
|
AllowUserOrgCreate = users.Key("allow_org_create").MustBool(true)
|
||||||
DefaultOrgRole = Cfg.Section("organization.single").Key("default_role").In("Editor", []string{"Editor", "Admin", "Viewer"})
|
AutoAssignOrg = users.Key("auto_assign_org").MustBool(true)
|
||||||
|
AutoAssignOrgRole = users.Key("auto_assign_org_role").In("Editor", []string{"Editor", "Admin", "Viewer"})
|
||||||
|
|
||||||
// anonymous access
|
// anonymous access
|
||||||
AnonymousEnabled = Cfg.Section("auth.anonymous").Key("enabled").MustBool(false)
|
AnonymousEnabled = Cfg.Section("auth.anonymous").Key("enabled").MustBool(false)
|
||||||
|
Loading…
Reference in New Issue
Block a user