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
e82b3632
Unverified
Commit
e82b3632
authored
Dec 18, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix signed in user for orgId=0 result should return active org id
parent
a4091813
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
pkg/services/sqlstore/user.go
+6
-1
pkg/services/sqlstore/user_test.go
+22
-1
No files found.
pkg/services/sqlstore/user.go
View file @
e82b3632
...
@@ -345,8 +345,12 @@ func GetUserOrgList(query *m.GetUserOrgListQuery) error {
...
@@ -345,8 +345,12 @@ func GetUserOrgList(query *m.GetUserOrgListQuery) error {
return
err
return
err
}
}
func
newSignedInUserCacheKey
(
orgID
,
userID
int64
)
string
{
return
fmt
.
Sprintf
(
"signed-in-user-%d-%d"
,
userID
,
orgID
)
}
func
(
ss
*
SqlStore
)
GetSignedInUserWithCache
(
query
*
m
.
GetSignedInUserQuery
)
error
{
func
(
ss
*
SqlStore
)
GetSignedInUserWithCache
(
query
*
m
.
GetSignedInUserQuery
)
error
{
cacheKey
:=
fmt
.
Sprintf
(
"signed-in-user-%d-%d"
,
query
.
UserId
,
query
.
Org
Id
)
cacheKey
:=
newSignedInUserCacheKey
(
query
.
OrgId
,
query
.
User
Id
)
if
cached
,
found
:=
ss
.
CacheService
.
Get
(
cacheKey
);
found
{
if
cached
,
found
:=
ss
.
CacheService
.
Get
(
cacheKey
);
found
{
query
.
Result
=
cached
.
(
*
m
.
SignedInUser
)
query
.
Result
=
cached
.
(
*
m
.
SignedInUser
)
return
nil
return
nil
...
@@ -357,6 +361,7 @@ func (ss *SqlStore) GetSignedInUserWithCache(query *m.GetSignedInUserQuery) erro
...
@@ -357,6 +361,7 @@ func (ss *SqlStore) GetSignedInUserWithCache(query *m.GetSignedInUserQuery) erro
return
err
return
err
}
}
cacheKey
=
newSignedInUserCacheKey
(
query
.
Result
.
OrgId
,
query
.
UserId
)
ss
.
CacheService
.
Set
(
cacheKey
,
query
.
Result
,
time
.
Second
*
5
)
ss
.
CacheService
.
Set
(
cacheKey
,
query
.
Result
,
time
.
Second
*
5
)
return
nil
return
nil
}
}
...
...
pkg/services/sqlstore/user_test.go
View file @
e82b3632
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
func
TestUserDataAccess
(
t
*
testing
.
T
)
{
func
TestUserDataAccess
(
t
*
testing
.
T
)
{
Convey
(
"Testing DB"
,
t
,
func
()
{
Convey
(
"Testing DB"
,
t
,
func
()
{
InitTestDB
(
t
)
ss
:=
InitTestDB
(
t
)
Convey
(
"Creating a user"
,
func
()
{
Convey
(
"Creating a user"
,
func
()
{
cmd
:=
&
m
.
CreateUserCommand
{
cmd
:=
&
m
.
CreateUserCommand
{
...
@@ -153,6 +153,27 @@ func TestUserDataAccess(t *testing.T) {
...
@@ -153,6 +153,27 @@ func TestUserDataAccess(t *testing.T) {
So
(
prefsQuery
.
Result
.
UserId
,
ShouldEqual
,
0
)
So
(
prefsQuery
.
Result
.
UserId
,
ShouldEqual
,
0
)
})
})
})
})
Convey
(
"when retreiving signed in user for orgId=0 result should return active org id"
,
func
()
{
ss
.
CacheService
.
Flush
()
query
:=
&
m
.
GetSignedInUserQuery
{
OrgId
:
users
[
1
]
.
OrgId
,
UserId
:
users
[
1
]
.
Id
}
err
:=
ss
.
GetSignedInUserWithCache
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
,
ShouldNotBeNil
)
So
(
query
.
OrgId
,
ShouldEqual
,
users
[
1
]
.
OrgId
)
err
=
SetUsingOrg
(
&
m
.
SetUsingOrgCommand
{
UserId
:
users
[
1
]
.
Id
,
OrgId
:
users
[
0
]
.
OrgId
})
So
(
err
,
ShouldBeNil
)
query
=
&
m
.
GetSignedInUserQuery
{
OrgId
:
0
,
UserId
:
users
[
1
]
.
Id
}
err
=
ss
.
GetSignedInUserWithCache
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
,
ShouldNotBeNil
)
So
(
query
.
Result
.
OrgId
,
ShouldEqual
,
users
[
0
]
.
OrgId
)
cacheKey
:=
newSignedInUserCacheKey
(
query
.
Result
.
OrgId
,
query
.
UserId
)
_
,
found
:=
ss
.
CacheService
.
Get
(
cacheKey
)
So
(
found
,
ShouldBeTrue
)
})
})
})
})
})
...
...
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