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
33760b5c
Unverified
Commit
33760b5c
authored
Apr 17, 2018
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure user's default org is kept up to date
parent
00e74990
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
pkg/login/ext_user.go
+18
-0
pkg/login/ldap_test.go
+11
-0
pkg/services/sqlstore/user.go
+5
-4
No files found.
pkg/login/ext_user.go
View file @
33760b5c
...
@@ -99,14 +99,17 @@ func updateUser(user *m.User, extUser *m.ExternalUserInfo) error {
...
@@ -99,14 +99,17 @@ func updateUser(user *m.User, extUser *m.ExternalUserInfo) error {
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
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
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
needsUpdate
=
true
needsUpdate
=
true
}
}
...
@@ -172,5 +175,20 @@ func syncOrgRoles(user *m.User, extUser *m.ExternalUserInfo) error {
...
@@ -172,5 +175,20 @@ func syncOrgRoles(user *m.User, extUser *m.ExternalUserInfo) error {
}
}
}
}
// update user's default org if needed
if
_
,
ok
:=
extUser
.
OrgRoles
[
user
.
OrgId
];
!
ok
{
for
orgId
:=
range
extUser
.
OrgRoles
{
user
.
OrgId
=
orgId
break
}
err
:=
bus
.
Dispatch
(
&
m
.
SetUsingOrgCommand
{
UserId
:
user
.
Id
,
OrgId
:
user
.
OrgId
,
})
if
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
pkg/login/ldap_test.go
View file @
33760b5c
...
@@ -118,6 +118,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -118,6 +118,7 @@ func TestLdapAuther(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
updateOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
So
(
sc
.
updateOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
So
(
sc
.
setUsingOrgCmd
.
OrgId
,
ShouldEqual
,
1
)
})
})
})
})
...
@@ -139,6 +140,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -139,6 +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
)
})
})
})
})
...
@@ -159,6 +161,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -159,6 +161,7 @@ func TestLdapAuther(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
setUsingOrgCmd
.
OrgId
,
ShouldEqual
,
1
)
})
})
})
})
...
@@ -178,6 +181,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -178,6 +181,7 @@ func TestLdapAuther(t *testing.T) {
Convey
(
"Should take first match, and ignore subsequent matches"
,
func
()
{
Convey
(
"Should take first match, and ignore subsequent matches"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldBeNil
)
So
(
sc
.
setUsingOrgCmd
.
OrgId
,
ShouldEqual
,
1
)
})
})
})
})
...
@@ -197,6 +201,7 @@ func TestLdapAuther(t *testing.T) {
...
@@ -197,6 +201,7 @@ func TestLdapAuther(t *testing.T) {
Convey
(
"Should take first match, and ignore subsequent matches"
,
func
()
{
Convey
(
"Should take first match, and ignore subsequent matches"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
sc
.
addOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
So
(
sc
.
addOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
So
(
sc
.
setUsingOrgCmd
.
OrgId
,
ShouldEqual
,
1
)
})
})
})
})
...
@@ -340,6 +345,11 @@ func ldapAutherScenario(desc string, fn scenarioFunc) {
...
@@ -340,6 +345,11 @@ func ldapAutherScenario(desc string, fn scenarioFunc) {
return
nil
return
nil
})
})
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
SetUsingOrgCommand
)
error
{
sc
.
setUsingOrgCmd
=
cmd
return
nil
})
fn
(
sc
)
fn
(
sc
)
})
})
}
}
...
@@ -352,6 +362,7 @@ type scenarioContext struct {
...
@@ -352,6 +362,7 @@ type scenarioContext struct {
updateOrgUserCmd
*
m
.
UpdateOrgUserCommand
updateOrgUserCmd
*
m
.
UpdateOrgUserCommand
removeOrgUserCmd
*
m
.
RemoveOrgUserCommand
removeOrgUserCmd
*
m
.
RemoveOrgUserCommand
updateUserCmd
*
m
.
UpdateUserCommand
updateUserCmd
*
m
.
UpdateUserCommand
setUsingOrgCmd
*
m
.
SetUsingOrgCommand
}
}
func
(
sc
*
scenarioContext
)
userQueryReturns
(
user
*
m
.
User
)
{
func
(
sc
*
scenarioContext
)
userQueryReturns
(
user
*
m
.
User
)
{
...
...
pkg/services/sqlstore/user.go
View file @
33760b5c
...
@@ -295,11 +295,12 @@ func SetUsingOrg(cmd *m.SetUsingOrgCommand) error {
...
@@ -295,11 +295,12 @@ func SetUsingOrg(cmd *m.SetUsingOrgCommand) error {
}
}
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
user
:=
m
.
User
{}
user
:=
m
.
User
{
sess
.
Id
(
cmd
.
UserId
)
.
Get
(
&
user
)
Id
:
cmd
.
UserId
,
OrgId
:
cmd
.
OrgId
,
}
user
.
OrgId
=
cmd
.
OrgId
_
,
err
:=
sess
.
Id
(
cmd
.
UserId
)
.
Update
(
&
user
)
_
,
err
:=
sess
.
Id
(
user
.
Id
)
.
Update
(
&
user
)
return
err
return
err
})
})
}
}
...
...
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