-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Migrate copy_dash endpoint to api v1 #23112
Merged
hughhhh
merged 7 commits into
apache:master
from
preset-io:jack/migrate-copy-dash-to-api-v1
Apr 6, 2023
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fe867d0
First draft
jfrag1 af3d0b7
Fix permission test to account for new endpoint
jfrag1 2ae3ab4
Fix test
jfrag1 5ae2a52
address concerns
hughhhh 6e988e9
Merge branch 'master' of https://github.com/apache/superset into jack…
hughhhh 5b9b493
Add copy_dash to constants.py
jfrag1 48f0782
Remove can_copy_dash from expected permission api result
jfrag1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from datetime import datetime | ||
from typing import Any, Dict, List, Optional, Union | ||
|
||
from flask import g | ||
from flask_appbuilder.models.sqla.interface import SQLAInterface | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
|
@@ -262,13 +263,6 @@ def set_dash_metadata( # pylint: disable=too-many-locals | |
# positions have its own column, no need to store it in metadata | ||
md.pop("positions", None) | ||
|
||
# The css and dashboard_title properties are not part of the metadata | ||
# TODO (geido): remove by refactoring/deprecating save_dash endpoint | ||
if data.get("css") is not None: | ||
dashboard.css = data.get("css") | ||
if data.get("dashboard_title") is not None: | ||
dashboard.dashboard_title = data.get("dashboard_title") | ||
|
||
if new_filter_scopes: | ||
md["filter_scopes"] = new_filter_scopes | ||
else: | ||
|
@@ -308,6 +302,41 @@ def favorited_ids(dashboards: List[Dashboard]) -> List[FavStar]: | |
.all() | ||
] | ||
|
||
@classmethod | ||
def copy_dashboard( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: how about just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to be explicit here |
||
cls, original_dash: Dashboard, data: Dict[str, Any] | ||
) -> Dashboard: | ||
dash = Dashboard() | ||
dash.owners = [g.user] if g.user else [] | ||
dash.dashboard_title = data["dashboard_title"] | ||
dash.css = data.get("css") | ||
|
||
metadata = json.loads(data["json_metadata"]) | ||
old_to_new_slice_ids: Dict[int, int] = {} | ||
if data.get("duplicate_slices"): | ||
# Duplicating slices as well, mapping old ids to new ones | ||
for slc in original_dash.slices: | ||
new_slice = slc.clone() | ||
new_slice.owners = [g.user] if g.user else [] | ||
db.session.add(new_slice) | ||
db.session.flush() | ||
new_slice.dashboards.append(dash) | ||
old_to_new_slice_ids[slc.id] = new_slice.id | ||
|
||
# update chartId of layout entities | ||
for value in metadata["positions"].values(): | ||
if isinstance(value, dict) and value.get("meta", {}).get("chartId"): | ||
old_id = value["meta"]["chartId"] | ||
new_id = old_to_new_slice_ids.get(old_id) | ||
value["meta"]["chartId"] = new_id | ||
else: | ||
dash.slices = original_dash.slices | ||
|
||
cls.set_dash_metadata(dash, metadata, old_to_new_slice_ids) | ||
db.session.add(dash) | ||
db.session.commit() | ||
return dash | ||
|
||
@staticmethod | ||
def add_favorite(dashboard: Dashboard) -> None: | ||
ids = DashboardDAO.favorited_ids([dashboard]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make this endpoint permission be
can write on Dashboard
add copy_dash to https://github.com/apache/superset/blob/master/superset/constants.py#L151