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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
22 deletions
+17
-22
pkg/login/ext_user.go
+15
-20
pkg/login/ldap_test.go
+2
-2
No files found.
pkg/login/ext_user.go
View file @
dbf61355
package
login
import
(
"fmt"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
...
...
@@ -24,13 +22,13 @@ func UpsertUser(cmd *m.UpsertUserCommand) error {
Login
:
extUser
.
Login
,
}
err
:=
bus
.
Dispatch
(
userQuery
)
if
err
!=
nil
{
if
err
!=
m
.
ErrUserNotFound
{
return
err
}
if
err
!=
m
.
ErrUserNotFound
&&
err
!=
nil
{
return
err
}
if
err
!=
nil
{
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
}
...
...
@@ -58,10 +56,10 @@ func UpsertUser(cmd *m.UpsertUserCommand) error {
return
err
}
}
}
else
{
cmd
.
Result
=
userQuery
.
Result
// sync user info
err
=
updateUser
(
cmd
.
Result
,
extUser
)
if
err
!=
nil
{
return
err
...
...
@@ -90,33 +88,32 @@ func updateUser(user *m.User, extUser *m.ExternalUserInfo) error {
updateCmd
:=
&
m
.
UpdateUserCommand
{
UserId
:
user
.
Id
,
}
needsUpdate
:=
false
needsUpdate
:=
false
if
extUser
.
Login
!=
""
&&
extUser
.
Login
!=
user
.
Login
{
updateCmd
.
Login
=
extUser
.
Login
user
.
Login
=
extUser
.
Login
needsUpdate
=
true
}
if
extUser
.
Email
!=
""
&&
extUser
.
Email
!=
user
.
Email
{
updateCmd
.
Email
=
extUser
.
Email
user
.
Email
=
extUser
.
Email
needsUpdate
=
true
}
if
extUser
.
Name
!=
""
&&
extUser
.
Name
!=
user
.
Name
{
updateCmd
.
Name
=
extUser
.
Name
user
.
Name
=
extUser
.
Name
needsUpdate
=
true
}
if
needsUpdate
{
log
.
Debug
(
"Syncing user info"
,
"id"
,
user
.
Id
,
"update"
,
updateCmd
)
err
:=
bus
.
Dispatch
(
updateCmd
)
if
err
!=
nil
{
return
err
}
if
!
needsUpdate
{
return
nil
}
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
{
...
...
@@ -176,13 +173,11 @@ func syncOrgRoles(user *m.User, extUser *m.ExternalUserInfo) error {
user
.
OrgId
=
orgId
break
}
err
:=
bus
.
Dispatch
(
&
m
.
SetUsingOrgCommand
{
return
bus
.
Dispatch
(
&
m
.
SetUsingOrgCommand
{
UserId
:
user
.
Id
,
OrgId
:
user
.
OrgId
,
})
if
err
!=
nil
{
return
err
}
}
return
nil
...
...
pkg/login/ldap_test.go
View file @
dbf61355
...
...
@@ -125,7 +125,7 @@ func TestLdapAuther(t *testing.T) {
ldapAutherScenario
(
"given current org role is removed in ldap"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
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) {
Convey
(
"Should remove org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
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