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
9e7aa65f
Commit
9e7aa65f
authored
Jun 15, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: clean up after user and org user delete
parent
699f9095
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
4 deletions
+62
-4
pkg/services/sqlstore/org_test.go
+50
-0
pkg/services/sqlstore/org_users.go
+11
-4
pkg/services/sqlstore/user.go
+1
-0
No files found.
pkg/services/sqlstore/org_test.go
View file @
9e7aa65f
...
@@ -154,6 +154,56 @@ func TestAccountDataAccess(t *testing.T) {
...
@@ -154,6 +154,56 @@ func TestAccountDataAccess(t *testing.T) {
So
(
err
,
ShouldEqual
,
m
.
ErrLastOrgAdmin
)
So
(
err
,
ShouldEqual
,
m
.
ErrLastOrgAdmin
)
})
})
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
)
So
(
err
,
ShouldBeNil
)
ac3
:=
ac3cmd
.
Result
orgUserCmd
:=
m
.
AddOrgUserCommand
{
OrgId
:
ac1
.
OrgId
,
UserId
:
ac3
.
Id
,
Role
:
m
.
ROLE_VIEWER
,
}
err
=
AddOrgUser
(
&
orgUserCmd
)
So
(
err
,
ShouldBeNil
)
query
:=
m
.
GetOrgUsersQuery
{
OrgId
:
orgUserCmd
.
OrgId
}
err
=
GetOrgUsers
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
3
)
err
=
AddOrUpdateDashboardPermission
(
&
m
.
AddOrUpdateDashboardPermissionCommand
{
DashboardId
:
1
,
OrgId
:
ac1
.
OrgId
,
UserId
:
ac3
.
Id
,
PermissionType
:
m
.
PERMISSION_EDIT
})
So
(
err
,
ShouldBeNil
)
err
=
AddOrUpdateDashboardPermission
(
&
m
.
AddOrUpdateDashboardPermissionCommand
{
DashboardId
:
2
,
OrgId
:
ac3
.
OrgId
,
UserId
:
ac3
.
Id
,
PermissionType
:
m
.
PERMISSION_EDIT
})
So
(
err
,
ShouldBeNil
)
Convey
(
"When org user is deleted"
,
func
()
{
cmdRemove
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
orgUserCmd
.
OrgId
,
UserId
:
ac3
.
Id
}
err
:=
RemoveOrgUser
(
&
cmdRemove
)
So
(
err
,
ShouldBeNil
)
Convey
(
"Should remove dependent permissions for deleted org user"
,
func
()
{
permQuery
:=
&
m
.
GetDashboardPermissionsQuery
{
DashboardId
:
1
}
err
=
GetDashboardPermissions
(
permQuery
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
permQuery
.
Result
),
ShouldEqual
,
0
)
})
Convey
(
"Should not remove dashboard permissions for same user in another org"
,
func
()
{
permQuery
:=
&
m
.
GetDashboardPermissionsQuery
{
DashboardId
:
2
}
err
=
GetDashboardPermissions
(
permQuery
)
So
(
err
,
ShouldBeNil
)
So
(
permQuery
.
Result
[
0
]
.
OrgId
,
ShouldEqual
,
ac3
.
OrgId
)
So
(
permQuery
.
Result
[
0
]
.
UserId
,
ShouldEqual
,
ac3
.
Id
)
})
})
})
})
})
})
})
})
})
...
...
pkg/services/sqlstore/org_users.go
View file @
9e7aa65f
...
@@ -80,10 +80,17 @@ func GetOrgUsers(query *m.GetOrgUsersQuery) error {
...
@@ -80,10 +80,17 @@ func GetOrgUsers(query *m.GetOrgUsersQuery) error {
func
RemoveOrgUser
(
cmd
*
m
.
RemoveOrgUserCommand
)
error
{
func
RemoveOrgUser
(
cmd
*
m
.
RemoveOrgUserCommand
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
return
inTransaction
(
func
(
sess
*
DBSession
)
error
{
var
rawSql
=
"DELETE FROM org_user WHERE org_id=? and user_id=?"
deletes
:=
[]
string
{
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
OrgId
,
cmd
.
UserId
)
"DELETE FROM org_user WHERE org_id=? and user_id=?"
,
if
err
!=
nil
{
"DELETE FROM dashboard_acl WHERE org_id=? and user_id = ?"
,
return
err
"DELETE FROM user_group_member WHERE org_id=? and user_id = ?"
,
}
for
_
,
sql
:=
range
deletes
{
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
OrgId
,
cmd
.
UserId
)
if
err
!=
nil
{
return
err
}
}
}
return
validateOneAdminLeftInOrg
(
cmd
.
OrgId
,
sess
)
return
validateOneAdminLeftInOrg
(
cmd
.
OrgId
,
sess
)
...
...
pkg/services/sqlstore/user.go
View file @
9e7aa65f
...
@@ -399,6 +399,7 @@ func DeleteUser(cmd *m.DeleteUserCommand) error {
...
@@ -399,6 +399,7 @@ func DeleteUser(cmd *m.DeleteUserCommand) error {
"DELETE FROM org_user WHERE user_id = ?"
,
"DELETE FROM org_user WHERE user_id = ?"
,
"DELETE FROM dashboard_acl WHERE user_id = ?"
,
"DELETE FROM dashboard_acl WHERE user_id = ?"
,
"DELETE FROM preferences WHERE user_id = ?"
,
"DELETE FROM preferences WHERE user_id = ?"
,
"DELETE FROM user_group_member WHERE user_id = ?"
,
}
}
for
_
,
sql
:=
range
deletes
{
for
_
,
sql
:=
range
deletes
{
...
...
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