Skip to content
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

fix(dashboard): draft dashboards should be viewable #14207

Merged
merged 2 commits into from
Apr 21, 2021

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Apr 16, 2021

SUMMARY

Temp fix for #14175 with some light refactoring:

  1. Rename DashboardFilter to DashboardAccessFilter to be more specific---we should do the same for other filters too (ChartFilter, DatasetFilter, etc)
  2. Replace get_by_id_or_slug in Dashboard DAO with the same logics used previously by the dashboard view.
  3. Added a new inferred column status to replace published, but published is kept for backward compatibility.

TODO: we should replace the boolean column published with a enum column status to support the long-term solution mentioned in #14175 (comment)

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before

Gamma user visiting a draft dashboard throws unexpected JS error

deleted-dashboard

After

Users with Superset -> dashboard view access should be able to open a draft dashboard created by other users.

draft-dashboard-viewable

But they won't be able to view it in the dashboard list.

dashboard-list

TEST PLAN

CI

For manual verification, see #14175 for details.

ADDITIONAL INFORMATION

@ktmud ktmud force-pushed the dashboard-draft-open-access branch from 10d7c27 to 695e151 Compare April 16, 2021 21:18
@@ -105,6 +108,7 @@ class DashboardRestApi(BaseSupersetModelRestApi):
list_columns = [
"id",
"published",
"status",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A-Z

Copy link
Member

@pkdotson pkdotson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve this. Frontend code looks good. Looks like the python unit test needs to be updated.

@ktmud ktmud force-pushed the dashboard-draft-open-access branch 2 times, most recently from 2c5b8fb to e8520d4 Compare April 16, 2021 22:58
@@ -57,16 +58,16 @@ class DashboardFavoriteFilter(BaseFavoriteFilter):
model = Dashboard


class DashboardFilter(BaseFilter):
class DashboardAccessFilter(BaseFilter):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 more semantic, I was always a bit confused what DashboardFilter was really doing

@ktmud ktmud force-pushed the dashboard-draft-open-access branch from e8520d4 to aaf88e2 Compare April 17, 2021 00:59
db.session.query(Dashboard)
.filter(id_or_slug_filter(id_or_slug))
.outerjoin(Slice, Dashboard.slices)
.outerjoin(Slice.table)
.outerjoin(Dashboard.owners)
.outerjoin(Dashboard.roles)
)
# Apply dashboard base filters
query = DashboardFilter("id", SQLAInterface(Dashboard, db.session)).apply(
query, None
)
dashboard = query.one_or_none()
dashboard = Dashboard.get(id_or_slug)
if not dashboard:
raise DashboardNotFoundError()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this exposes a new security risk: it would be easy to know if a dashboard exists or not even if user doesn't have access to begin with

Copy link
Member Author

@ktmud ktmud Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's just the same as before right? The goal of this PR is to revert the behavior of non-owners having access to draft dashboards. Whether this is a risk that worth further actions is another topic.

@suddjian
Copy link
Member

suddjian commented Apr 19, 2021

I wonder if it would be more appropriate to change DashboardAccessFilter so that it respects draft dashboards. Seems like there could be other bugs lurking because of that.

Thank you for addressing this, by the way. There have been a couple of regressions due to this so I've made a ticket for myself to write some e2e tests around drafts.

@ktmud ktmud force-pushed the dashboard-draft-open-access branch 2 times, most recently from d577a74 to 0386f47 Compare April 19, 2021 21:23
@codecov
Copy link

codecov bot commented Apr 19, 2021

Codecov Report

Merging #14207 (87d2801) into master (ff665fa) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 87d2801 differs from pull request most recent head 6496f89. Consider uploading reports for the commit 6496f89 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14207      +/-   ##
==========================================
- Coverage   76.74%   76.73%   -0.01%     
==========================================
  Files         952      954       +2     
  Lines       48043    48055      +12     
  Branches     5978     5972       -6     
==========================================
+ Hits        36870    36877       +7     
- Misses      10971    10976       +5     
  Partials      202      202              
Flag Coverage Δ
javascript 72.08% <100.00%> (+0.03%) ⬆️
mysql 80.72% <100.00%> (-0.01%) ⬇️
postgres 80.75% <100.00%> (-0.01%) ⬇️
python 80.80% <100.00%> (-0.04%) ⬇️
sqlite ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...perset-frontend/src/views/CRUD/alert/AlertList.tsx 75.75% <ø> (ø)
...perset-frontend/src/views/CRUD/chart/ChartList.tsx 72.38% <ø> (ø)
...t-frontend/src/views/CRUD/data/query/QueryList.tsx 71.84% <ø> (ø)
superset-frontend/src/components/ListView/types.ts 100.00% <100.00%> (ø)
...ews/CRUD/annotationlayers/AnnotationLayersList.tsx 77.35% <100.00%> (ø)
...d/src/views/CRUD/csstemplates/CssTemplatesList.tsx 78.26% <100.00%> (ø)
...rontend/src/views/CRUD/dashboard/DashboardList.tsx 74.78% <100.00%> (+0.21%) ⬆️
...uperset-frontend/src/views/CRUD/dashboard/types.ts 100.00% <100.00%> (ø)
...tend/src/views/CRUD/data/database/DatabaseList.tsx 80.00% <100.00%> (ø)
...ontend/src/views/CRUD/data/dataset/DatasetList.tsx 69.93% <100.00%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff665fa...6496f89. Read the comment docs.

@ktmud
Copy link
Member Author

ktmud commented Apr 19, 2021

@suddjian previously the list view already filters out draft dashboards for non-owners/admins, so as long as we use DashboardAccessFilter only for the list view, it's OK to let DashboardAccessFilter filer out drafts. There are a couple of unit tests on the API with drafts but they don't seem to align with the original behavior which this PR tries to revert back to.

@ktmud ktmud force-pushed the dashboard-draft-open-access branch 3 times, most recently from bfb4a73 to 7a9036e Compare April 20, 2021 04:21
@ktmud ktmud force-pushed the dashboard-draft-open-access branch from 7a9036e to 6496f89 Compare April 20, 2021 22:44
uri = DASHBOARD_API_URL_FORMAT.format(dashboard.id)
rv = self.client.get(uri)
self.assert404(rv)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktmud
Copy link
Member Author

ktmud commented Apr 21, 2021

@suddjian @pkdotson @amitmiran137 I finally fixed all the test cases but had to change some expected values because the behavior of the API endpoints has changed (what returns 404 before would now return 200---like it does before for the Dashboard page). Would appreciate an extra pair of eyes if you have time.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for the fix!

@@ -24,3 +24,8 @@ export type DashboardObject = {
position?: string;
metadata?: string;
};

export enum DashboardStatus {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay, new types!

@ktmud ktmud merged commit 2dd20df into apache:master Apr 21, 2021
@ktmud ktmud deleted the dashboard-draft-open-access branch April 21, 2021 16:54
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
* fix(dashboard): draft dashboards should have open access

* Remove a duplicate test
@mistercrunch mistercrunch added the 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants