Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
dbf61355
Commit
dbf61355
authored
Apr 18, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style: code simplifications
parent
c22495b6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
pkg/login/ext_user.go
+13
-18
pkg/login/ldap_test.go
+2
-2
No files found.
pkg/login/ext_user.go
View file @
dbf61355
package
login
package
login
import
(
import
(
"fmt"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
...
@@ -24,13 +22,13 @@ func UpsertUser(cmd *m.UpsertUserCommand) error {
...
@@ -24,13 +22,13 @@ func UpsertUser(cmd *m.UpsertUserCommand) error {
Login
:
extUser
.
Login
,
Login
:
extUser
.
Login
,
}
}
err
:=
bus
.
Dispatch
(
userQuery
)
err
:=
bus
.
Dispatch
(
userQuery
)
if
err
!=
nil
{
if
err
!=
m
.
ErrUserNotFound
&&
err
!=
nil
{
if
err
!=
m
.
ErrUserNotFound
{
return
err
return
err
}
}
if
err
!=
nil
{
if
!
cmd
.
SignupAllowed
{
if
!
cmd
.
SignupAllowed
{
log
.
Warn
(
fmt
.
Sprintf
(
"Not allowing %s login, user not found in internal user database and allow signup = false"
,
extUser
.
AuthModule
)
)
log
.
Warn
(
"Not allowing %s login, user not found in internal user database and allow signup = false"
,
extUser
.
AuthModule
)
return
ErrInvalidCredentials
return
ErrInvalidCredentials
}
}
...
@@ -58,10 +56,10 @@ func UpsertUser(cmd *m.UpsertUserCommand) error {
...
@@ -58,10 +56,10 @@ func UpsertUser(cmd *m.UpsertUserCommand) error {
return
err
return
err
}
}
}
}
}
else
{
}
else
{
cmd
.
Result
=
userQuery
.
Result
cmd
.
Result
=
userQuery
.
Result
// sync user info
err
=
updateUser
(
cmd
.
Result
,
extUser
)
err
=
updateUser
(
cmd
.
Result
,
extUser
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -90,33 +88,32 @@ func updateUser(user *m.User, extUser *m.ExternalUserInfo) error {
...
@@ -90,33 +88,32 @@ func updateUser(user *m.User, extUser *m.ExternalUserInfo) error {
updateCmd
:=
&
m
.
UpdateUserCommand
{
updateCmd
:=
&
m
.
UpdateUserCommand
{
UserId
:
user
.
Id
,
UserId
:
user
.
Id
,
}
}
needsUpdate
:=
false
needsUpdate
:=
false
if
extUser
.
Login
!=
""
&&
extUser
.
Login
!=
user
.
Login
{
if
extUser
.
Login
!=
""
&&
extUser
.
Login
!=
user
.
Login
{
updateCmd
.
Login
=
extUser
.
Login
updateCmd
.
Login
=
extUser
.
Login
user
.
Login
=
extUser
.
Login
user
.
Login
=
extUser
.
Login
needsUpdate
=
true
needsUpdate
=
true
}
}
if
extUser
.
Email
!=
""
&&
extUser
.
Email
!=
user
.
Email
{
if
extUser
.
Email
!=
""
&&
extUser
.
Email
!=
user
.
Email
{
updateCmd
.
Email
=
extUser
.
Email
updateCmd
.
Email
=
extUser
.
Email
user
.
Email
=
extUser
.
Email
user
.
Email
=
extUser
.
Email
needsUpdate
=
true
needsUpdate
=
true
}
}
if
extUser
.
Name
!=
""
&&
extUser
.
Name
!=
user
.
Name
{
if
extUser
.
Name
!=
""
&&
extUser
.
Name
!=
user
.
Name
{
updateCmd
.
Name
=
extUser
.
Name
updateCmd
.
Name
=
extUser
.
Name
user
.
Name
=
extUser
.
Name
user
.
Name
=
extUser
.
Name
needsUpdate
=
true
needsUpdate
=
true
}
}
if
needsUpdate
{
if
!
needsUpdate
{
log
.
Debug
(
"Syncing user info"
,
"id"
,
user
.
Id
,
"update"
,
updateCmd
)
return
nil
err
:=
bus
.
Dispatch
(
updateCmd
)
if
err
!=
nil
{
return
err
}
}
}
return
nil
log
.
Debug
(
"Syncing user info"
,
"id"
,
user
.
Id
,
"update"
,
updateCmd
)
return
bus
.
Dispatch
(
updateCmd
)
}
}
func
syncOrgRoles
(
user
*
m
.
User
,
extUser
*
m
.
ExternalUserInfo
)
error
{
func
syncOrgRoles
(
user
*
m
.
User
,
extUser
*
m
.
ExternalUserInfo
)
error
{
...
@@ -176,13 +173,11 @@ func syncOrgRoles(user *m.User, extUser *m.ExternalUserInfo) error {
...
@@ -176,13 +173,11 @@ func syncOrgRoles(user *m.User, extUser *m.ExternalUserInfo) error {
user
.
OrgId
=
orgId
user
.
OrgId
=
orgId
break
break
}
}
err
:=
bus
.
Dispatch
(
&
m
.
SetUsingOrgCommand
{
return
bus
.
Dispatch
(
&
m
.
SetUsingOrgCommand
{
UserId
:
user
.
Id
,
UserId
:
user
.
Id
,
OrgId
:
user
.
OrgId
,
OrgId
:
user
.
OrgId
,
})
})
if
err
!=
nil
{
return
err
}
}
}
return
nil
return
nil
...
...
pkg/login/ldap_test.go
View file @
dbf61355
...
@@ -125,7 +125,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -125,7 +125,7 @@ func TestLdapAuther(t *testing.T) {
ldapAutherScenario
(
"given current org role is removed in ldap"
,
func
(
sc
*
scenarioContext
)
{
ldapAutherScenario
(
"given current org role is removed in ldap"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
{
GroupDN
:
"cn=users"
,
OrgId
:
2
,
OrgRole
:
"Admin"
},
},
},
})
})
...
@@ -140,7 +140,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -140,7 +140,7 @@ func TestLdapAuther(t *testing.T) {
Convey
(
"Should remove org role"
,
func
()
{
Convey
(
"Should remove org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
setUsingOrgCmd
.
OrgId
,
ShouldEqual
,
1
)
So
(
sc
.
setUsingOrgCmd
.
OrgId
,
ShouldEqual
,
2
)
})
})
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment