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
1181e967
Commit
1181e967
authored
Jun 15, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge create user handlers
parent
da91b91b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
79 deletions
+74
-79
pkg/services/sqlstore/dashboard_test.go
+2
-1
pkg/services/sqlstore/org_test.go
+6
-5
pkg/services/sqlstore/team_test.go
+2
-1
pkg/services/sqlstore/user.go
+60
-70
pkg/services/sqlstore/user_auth_test.go
+2
-1
pkg/services/sqlstore/user_test.go
+2
-1
No files found.
pkg/services/sqlstore/dashboard_test.go
View file @
1181e967
package
sqlstore
import
(
"context"
"fmt"
"testing"
"time"
...
...
@@ -389,7 +390,7 @@ func createUser(name string, role string, isAdmin bool) m.User {
setting
.
AutoAssignOrgRole
=
role
currentUserCmd
:=
m
.
CreateUserCommand
{
Login
:
name
,
Email
:
name
+
"@test.com"
,
Name
:
"a "
+
name
,
IsAdmin
:
isAdmin
}
err
:=
CreateUser
(
&
currentUserCmd
)
err
:=
CreateUser
(
context
.
Background
(),
&
currentUserCmd
)
So
(
err
,
ShouldBeNil
)
q1
:=
m
.
GetUserOrgListQuery
{
UserId
:
currentUserCmd
.
Result
.
Id
}
...
...
pkg/services/sqlstore/org_test.go
View file @
1181e967
package
sqlstore
import
(
"context"
"testing"
"time"
...
...
@@ -22,9 +23,9 @@ func TestAccountDataAccess(t *testing.T) {
ac1cmd
:=
m
.
CreateUserCommand
{
Login
:
"ac1"
,
Email
:
"ac1@test.com"
,
Name
:
"ac1 name"
}
ac2cmd
:=
m
.
CreateUserCommand
{
Login
:
"ac2"
,
Email
:
"ac2@test.com"
,
Name
:
"ac2 name"
}
err
:=
CreateUser
(
&
ac1cmd
)
err
:=
CreateUser
(
context
.
Background
(),
&
ac1cmd
)
So
(
err
,
ShouldBeNil
)
err
=
CreateUser
(
&
ac2cmd
)
err
=
CreateUser
(
context
.
Background
(),
&
ac2cmd
)
So
(
err
,
ShouldBeNil
)
q1
:=
m
.
GetUserOrgListQuery
{
UserId
:
ac1cmd
.
Result
.
Id
}
...
...
@@ -43,8 +44,8 @@ func TestAccountDataAccess(t *testing.T) {
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
}
err
:=
CreateUser
(
&
ac1cmd
)
err
=
CreateUser
(
&
ac2cmd
)
err
:=
CreateUser
(
context
.
Background
(),
&
ac1cmd
)
err
=
CreateUser
(
context
.
Background
(),
&
ac2cmd
)
So
(
err
,
ShouldBeNil
)
ac1
:=
ac1cmd
.
Result
...
...
@@ -182,7 +183,7 @@ func TestAccountDataAccess(t *testing.T) {
Convey
(
"Given an org user with dashboard permissions"
,
func
()
{
ac3cmd
:=
m
.
CreateUserCommand
{
Login
:
"ac3"
,
Email
:
"ac3@test.com"
,
Name
:
"ac3 name"
,
IsAdmin
:
false
}
err
:=
CreateUser
(
&
ac3cmd
)
err
:=
CreateUser
(
context
.
Background
(),
&
ac3cmd
)
So
(
err
,
ShouldBeNil
)
ac3
:=
ac3cmd
.
Result
...
...
pkg/services/sqlstore/team_test.go
View file @
1181e967
package
sqlstore
import
(
"context"
"fmt"
"testing"
...
...
@@ -22,7 +23,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
Name
:
fmt
.
Sprint
(
"user"
,
i
),
Login
:
fmt
.
Sprint
(
"loginuser"
,
i
),
}
err
:=
CreateUser
(
userCmd
)
err
:=
CreateUser
(
context
.
Background
(),
userCmd
)
So
(
err
,
ShouldBeNil
)
userIds
=
append
(
userIds
,
userCmd
.
Result
.
Id
)
}
...
...
pkg/services/sqlstore/user.go
View file @
1181e967
...
...
@@ -16,7 +16,7 @@ import (
)
func
init
()
{
bus
.
AddHandler
(
"sql"
,
CreateUser
)
//
bus.AddHandler("sql", CreateUser)
bus
.
AddHandler
(
"sql"
,
GetUserById
)
bus
.
AddHandler
(
"sql"
,
UpdateUser
)
bus
.
AddHandler
(
"sql"
,
ChangeUserPassword
)
...
...
@@ -31,7 +31,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
DeleteUser
)
bus
.
AddHandler
(
"sql"
,
UpdateUserPermissions
)
bus
.
AddHandler
(
"sql"
,
SetUserHelpFlag
)
bus
.
AddHandlerCtx
(
"sql"
,
CreateUser
Ctx
)
bus
.
AddHandlerCtx
(
"sql"
,
CreateUser
)
}
func
getOrgIdForNewUser
(
cmd
*
m
.
CreateUserCommand
,
sess
*
DBSession
)
(
int64
,
error
)
{
...
...
@@ -81,90 +81,80 @@ func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *DBSession) (int64, error
return
org
.
Id
,
nil
}
func
internalCreateUser
(
sess
*
DBSession
,
cmd
*
m
.
CreateUserCommand
)
error
{
orgId
,
err
:=
getOrgIdForNewUser
(
cmd
,
sess
)
if
err
!=
nil
{
return
err
}
func
CreateUser
(
ctx
context
.
Context
,
cmd
*
m
.
CreateUserCommand
)
error
{
return
inTransactionWithRetryCtx
(
ctx
,
func
(
sess
*
DBSession
)
error
{
orgId
,
err
:=
getOrgIdForNewUser
(
cmd
,
sess
)
if
err
!=
nil
{
return
err
}
if
cmd
.
Email
==
""
{
cmd
.
Email
=
cmd
.
Login
}
if
cmd
.
Email
==
""
{
cmd
.
Email
=
cmd
.
Login
}
// create user
user
:=
m
.
User
{
Email
:
cmd
.
Email
,
Name
:
cmd
.
Name
,
Login
:
cmd
.
Login
,
Company
:
cmd
.
Company
,
IsAdmin
:
cmd
.
IsAdmin
,
OrgId
:
orgId
,
EmailVerified
:
cmd
.
EmailVerified
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
LastSeenAt
:
time
.
Now
()
.
AddDate
(
-
10
,
0
,
0
),
}
// create user
user
:=
m
.
User
{
Email
:
cmd
.
Email
,
Name
:
cmd
.
Name
,
Login
:
cmd
.
Login
,
Company
:
cmd
.
Company
,
IsAdmin
:
cmd
.
IsAdmin
,
OrgId
:
orgId
,
EmailVerified
:
cmd
.
EmailVerified
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
LastSeenAt
:
time
.
Now
()
.
AddDate
(
-
10
,
0
,
0
),
}
if
len
(
cmd
.
Password
)
>
0
{
user
.
Salt
=
util
.
GetRandomString
(
10
)
user
.
Rands
=
util
.
GetRandomString
(
10
)
user
.
Password
=
util
.
EncodePassword
(
cmd
.
Password
,
user
.
Salt
)
}
if
len
(
cmd
.
Password
)
>
0
{
user
.
Salt
=
util
.
GetRandomString
(
10
)
user
.
Rands
=
util
.
GetRandomString
(
10
)
user
.
Password
=
util
.
EncodePassword
(
cmd
.
Password
,
user
.
Salt
)
}
sess
.
UseBool
(
"is_admin"
)
sess
.
UseBool
(
"is_admin"
)
if
_
,
err
:=
sess
.
Insert
(
&
user
);
err
!=
nil
{
return
err
}
if
_
,
err
:=
sess
.
Insert
(
&
user
);
err
!=
nil
{
return
err
}
sess
.
publishAfterCommit
(
&
events
.
UserCreated
{
Timestamp
:
user
.
Created
,
Id
:
user
.
Id
,
Name
:
user
.
Name
,
Login
:
user
.
Login
,
Email
:
user
.
Email
,
})
sess
.
publishAfterCommit
(
&
events
.
UserCreated
{
Timestamp
:
user
.
Created
,
Id
:
user
.
Id
,
Name
:
user
.
Name
,
Login
:
user
.
Login
,
Email
:
user
.
Email
,
})
cmd
.
Result
=
user
cmd
.
Result
=
user
// create org user link
if
!
cmd
.
SkipOrgSetup
{
orgUser
:=
m
.
OrgUser
{
OrgId
:
orgId
,
UserId
:
user
.
Id
,
Role
:
m
.
ROLE_ADMIN
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
// create org user link
if
!
cmd
.
SkipOrgSetup
{
orgUser
:=
m
.
OrgUser
{
OrgId
:
orgId
,
UserId
:
user
.
Id
,
Role
:
m
.
ROLE_ADMIN
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
if
setting
.
AutoAssignOrg
&&
!
user
.
IsAdmin
{
if
len
(
cmd
.
DefaultOrgRole
)
>
0
{
orgUser
.
Role
=
m
.
RoleType
(
cmd
.
DefaultOrgRole
)
}
else
{
orgUser
.
Role
=
m
.
RoleType
(
setting
.
AutoAssignOrgRole
)
if
setting
.
AutoAssignOrg
&&
!
user
.
IsAdmin
{
if
len
(
cmd
.
DefaultOrgRole
)
>
0
{
orgUser
.
Role
=
m
.
RoleType
(
cmd
.
DefaultOrgRole
)
}
else
{
orgUser
.
Role
=
m
.
RoleType
(
setting
.
AutoAssignOrgRole
)
}
}
}
if
_
,
err
=
sess
.
Insert
(
&
orgUser
);
err
!=
nil
{
return
err
if
_
,
err
=
sess
.
Insert
(
&
orgUser
);
err
!=
nil
{
return
err
}
}
}
return
nil
}
func
CreateUserCtx
(
ctx
context
.
Context
,
cmd
*
m
.
CreateUserCommand
)
error
{
return
inTransactionWithRetryCtx
(
ctx
,
func
(
sess
*
DBSession
)
error
{
return
internalCreateUser
(
sess
,
cmd
)
return
nil
},
0
)
}
func
CreateUser
(
cmd
*
m
.
CreateUserCommand
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
return
internalCreateUser
(
sess
,
cmd
)
})
}
func
GetUserById
(
query
*
m
.
GetUserByIdQuery
)
error
{
user
:=
new
(
m
.
User
)
has
,
err
:=
x
.
Id
(
query
.
Id
)
.
Get
(
user
)
...
...
pkg/services/sqlstore/user_auth_test.go
View file @
1181e967
package
sqlstore
import
(
"context"
"fmt"
"testing"
...
...
@@ -22,7 +23,7 @@ func TestUserAuth(t *testing.T) {
Name
:
fmt
.
Sprint
(
"user"
,
i
),
Login
:
fmt
.
Sprint
(
"loginuser"
,
i
),
}
err
=
CreateUser
(
cmd
)
err
=
CreateUser
(
c
ontext
.
Background
(),
c
md
)
So
(
err
,
ShouldBeNil
)
users
=
append
(
users
,
cmd
.
Result
)
}
...
...
pkg/services/sqlstore/user_test.go
View file @
1181e967
package
sqlstore
import
(
"context"
"fmt"
"testing"
...
...
@@ -24,7 +25,7 @@ func TestUserDataAccess(t *testing.T) {
Name
:
fmt
.
Sprint
(
"user"
,
i
),
Login
:
fmt
.
Sprint
(
"loginuser"
,
i
),
}
err
=
CreateUser
(
cmd
)
err
=
CreateUser
(
c
ontext
.
Background
(),
c
md
)
So
(
err
,
ShouldBeNil
)
users
=
append
(
users
,
cmd
.
Result
)
}
...
...
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