Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
8b16e3ea
Commit
8b16e3ea
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
fix issue where deleting a DashboardCard wasn't properly cascading to DashboardCardSeries as well.
parent
5cf426f6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/api/dashboard.clj
+6
-7
6 additions, 7 deletions
src/metabase/api/dashboard.clj
src/metabase/models/dashboard_card.clj
+16
-0
16 additions, 0 deletions
src/metabase/models/dashboard_card.clj
test/metabase/api/dashboard_test.clj
+24
-6
24 additions, 6 deletions
test/metabase/api/dashboard_test.clj
with
46 additions
and
13 deletions
src/metabase/api/dashboard.clj
+
6
−
7
View file @
8b16e3ea
...
...
@@ -9,7 +9,7 @@
[
card
:refer
[
Card
]]
[
common
:as
common
]
[
dashboard
:refer
[
Dashboard
]]
[
dashboard-card
:refer
[
DashboardCard
create-dashboard-card
update-dashboard-card
]])))
[
dashboard-card
:refer
[
DashboardCard
create-dashboard-card
update-dashboard-card
delete-dashboard-card
]])))
(
defendpoint
GET
"/"
"Get `Dashboards`. With filter option `f` (default `all`), restrict results as follows:
...
...
@@ -107,11 +107,10 @@
"Remove a `DashboardCard` from a `Dashboard`."
[
id
dashcardId
]
{
dashcardId
[
Required
String->Integer
]}
(
write-check
Dashboard
id
)
;; TODO - it would be nicer to do this if `del` returned the object that was deleted instead of an api response
(
let
[
dashcard
(
db/sel
:one
DashboardCard
:id
dashcardId
)
result
(
db/del
DashboardCard
:id
dashcardId
:dashboard_id
id
)]
(
events/publish-event
:dashboard-remove-cards
{
:id
id
:actor_id
*current-user-id*
:dashcards
[
dashcard
]})
result
))
(
let-404
[
dashboard
(
Dashboard
id
)]
(
write-check
Dashboard
id
)
(
when-let
[
dashboard-card
(
DashboardCard
dashcardId
)]
(
check-500
(
delete-dashboard-card
dashboard-card
*current-user-id*
))
{
:success
true
})))
(
define-routes
)
This diff is collapsed.
Click to expand it.
src/metabase/models/dashboard_card.clj
+
16
−
0
View file @
8b16e3ea
...
...
@@ -35,6 +35,13 @@
;;; ## ---------------------------------------- HYDRATION ----------------------------------------
(
defn
^
:hydrate
dashboard
"Return the `Dashboard` associated with the `DashboardCard`."
[{
:keys
[
dashboard_id
]}]
{
:pre
[(
integer?
dashboard_id
)]}
(
db/sel
:one
'metabase.models.dashboard/Dashboard
:id
dashboard_id
))
(
defn
^
:hydrate
series
"Return the `Cards` associated as additional series on this `DashboardCard`."
[{
:keys
[
id
]}]
...
...
@@ -118,4 +125,13 @@
(
->>
(
events/publish-event
:dashboard-card-create
))
(
dissoc
:actor_id
))))))
(
defn
delete-dashboard-card
"Delete a `DashboardCard`."
[
dashboard-card
user-id
]
{
:pre
[(
map?
dashboard-card
)
(
integer?
user-id
)]}
(
let
[{
:keys
[
id
]}
(
dashboard
dashboard-card
)]
(
db/cascade-delete
DashboardCard
:id
(
:id
dashboard-card
))
(
events/publish-event
:dashboard-remove-cards
{
:id
id
:actor_id
user-id
:dashcards
[
dashboard-card
]})))
(
u/require-dox-in-this-namespace
)
This diff is collapsed.
Click to expand it.
test/metabase/api/dashboard_test.clj
+
24
−
6
View file @
8b16e3ea
...
...
@@ -261,7 +261,7 @@
;; ## DELETE /api/dashboard/:id/cards
(
expect
[
1
nil
{
:success
true
}
0
]
;; fetch a dashboard WITH a dashboard card on it
(
tu/with-temp
Dashboard
[{
dashboard-id
:id
}
{
:name
"Test Dashboard"
...
...
@@ -273,11 +273,29 @@
:display
"scalar"
:dataset_query
{
:something
"simple"
}
:visualization_settings
{
:global
{
:title
nil
}}}]
(
tu/with-temp
DashboardCard
[{
dashcard-id
:id
}
{
:dashboard_id
dashboard-id
:card_id
card-id
}]
[(
count
(
db/sel
:many
:field
[
DashboardCard
:id
]
:dashboard_id
dashboard-id
))
((
user->client
:rasta
)
:delete
204
(
format
"dashboard/%d/cards"
dashboard-id
)
:dashcardId
dashcard-id
)
(
count
(
db/sel
:many
:field
[
DashboardCard
:id
]
:dashboard_id
dashboard-id
))]))))
(
tu/with-temp
Card
[{
series-id1
:id
}
{
:name
"Additional Series Card 1"
:creator_id
(
user->id
:rasta
)
:public_perms
0
:display
"scalar"
:dataset_query
{
:something
"simple"
}
:visualization_settings
{
:global
{
:title
nil
}}}]
(
tu/with-temp
Card
[{
series-id2
:id
}
{
:name
"Additional Series Card 2"
:creator_id
(
user->id
:rasta
)
:public_perms
0
:display
"scalar"
:dataset_query
{
:something
"simple"
}
:visualization_settings
{
:global
{
:title
nil
}}}]
(
tu/with-temp
DashboardCard
[{
dashcard-id
:id
}
{
:dashboard_id
dashboard-id
:card_id
card-id
}]
(
tu/with-temp
DashboardCardSeries
[
_
{
:dashboardcard_id
dashcard-id
:card_id
series-id1
:position
0
}]
(
tu/with-temp
DashboardCardSeries
[
_
{
:dashboardcard_id
dashcard-id
:card_id
series-id2
:position
1
}]
[(
count
(
db/sel
:many
:field
[
DashboardCard
:id
]
:dashboard_id
dashboard-id
))
((
user->client
:rasta
)
:delete
200
(
format
"dashboard/%d/cards"
dashboard-id
)
:dashcardId
dashcard-id
)
(
count
(
db/sel
:many
:field
[
DashboardCard
:id
]
:dashboard_id
dashboard-id
))]))))))))
;; ## PUT /api/dashboard/:id/cards
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment