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
e6d09b32
Commit
e6d09b32
authored
Aug 12, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(db): remove stars and tags when removing user or dashboard, fixes #2016
parent
8fcaa499
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
11 deletions
+35
-11
pkg/services/sqlstore/dashboard.go
+21
-4
pkg/services/sqlstore/org.go
+2
-4
pkg/services/sqlstore/user.go
+12
-3
No files found.
pkg/services/sqlstore/dashboard.go
View file @
e6d09b32
...
...
@@ -198,11 +198,28 @@ func GetDashboardTags(query *m.GetDashboardTagsQuery) error {
}
func
DeleteDashboard
(
cmd
*
m
.
DeleteDashboardCommand
)
error
{
sess
:=
x
.
NewSession
()
defer
sess
.
Close
()
return
inTransaction2
(
func
(
sess
*
session
)
error
{
dashboard
:=
m
.
Dashboard
{
Slug
:
cmd
.
Slug
,
OrgId
:
cmd
.
OrgId
}
has
,
err
:=
x
.
Get
(
&
dashboard
)
if
err
!=
nil
{
return
err
}
else
if
has
==
false
{
return
m
.
ErrDashboardNotFound
}
rawSql
:=
"DELETE FROM dashboard WHERE org_id=? and slug=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
OrgId
,
cmd
.
Slug
)
deletes
:=
[]
string
{
"DELETE FROM dashboard_tag WHERE dashboard_id = ? "
,
"DELETE FROM star WHERE dashboard_id = ? "
,
"DELETE FROM dashboard WHERE id = ?"
,
}
for
_
,
sql
:=
range
deletes
{
_
,
err
:=
sess
.
Exec
(
sql
,
dashboard
.
Id
)
if
err
!=
nil
{
return
err
}
}
return
nil
})
}
pkg/services/sqlstore/org.go
View file @
e6d09b32
...
...
@@ -5,7 +5,6 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
)
...
...
@@ -123,8 +122,8 @@ func DeleteOrg(cmd *m.DeleteOrgCommand) error {
return
inTransaction2
(
func
(
sess
*
session
)
error
{
deletes
:=
[]
string
{
"DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?)"
,
"DELETE FROM dashboard_tag WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?)"
,
"DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?
AND star.dashboard_id = dashboard.id
)"
,
"DELETE FROM dashboard_tag WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ?
AND dashboard_tag.dashboard_id = dashboard.id
)"
,
"DELETE FROM dashboard WHERE org_id = ?"
,
"DELETE FROM api_key WHERE org_id = ?"
,
"DELETE FROM data_source WHERE org_id = ?"
,
...
...
@@ -134,7 +133,6 @@ func DeleteOrg(cmd *m.DeleteOrgCommand) error {
}
for
_
,
sql
:=
range
deletes
{
log
.
Trace
(
sql
)
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
Id
)
if
err
!=
nil
{
return
err
...
...
pkg/services/sqlstore/user.go
View file @
e6d09b32
package
sqlstore
import
(
"fmt"
"strings"
"time"
...
...
@@ -309,9 +308,19 @@ func SearchUsers(query *m.SearchUsersQuery) error {
func
DeleteUser
(
cmd
*
m
.
DeleteUserCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
fmt
.
Sprintf
(
"DELETE FROM %s WHERE id=?"
,
x
.
Dialect
()
.
Quote
(
"user"
))
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
UserId
)
deletes
:=
[]
string
{
"DELETE FROM star WHERE user_id = ?"
,
"DELETE FROM user WHERE id = ?"
,
}
for
_
,
sql
:=
range
deletes
{
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
UserId
)
if
err
!=
nil
{
return
err
}
}
return
nil
})
}
...
...
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