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

chore(tags): Handle tagging as part of asset update call #28570

Merged
merged 2 commits into from
May 28, 2024

Conversation

Vitor-Avila
Copy link
Contributor

SUMMARY

Currently, if a change is made to the Tags configuration for an asset via the PropertiesModal, the modification is handled in a separate request. This causes two issues:

  • Content owners with write access on $asset_type have the impression they can change the tags configuration (since they can save it).
  • The operation silently fails -- no error in the UI.

This PR moves the tag handling to the API call to update asset, providing an error to the user if permissions are missing. The PR also introduces a new permission so that users that don't have can write on Tag can still add existing tags to the assets they own (and have permission to modify).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

BEFORE

Before.mov

AFTER

Had to add to GDrive due to filesize

https://drive.google.com/file/d/1141h-OqqvOFH4Ok4yXISwKCzIs3TP9gZ/view?usp=sharing

TESTING INSTRUCTIONS

Added both integration and unit tests. For manual testing:

  1. Log in with a role that doesn't have can write on Tag but has can write on Dashboard.
  2. Edit the properties for a dashboard, changing the Tags config.
  3. Validate the change happens in the same network call and that errors are properly displayed.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@github-actions github-actions bot added the api Related to the REST API label May 18, 2024
@dosubot dosubot bot added the dashboard:properties Related to the properties of the Dashboard label May 18, 2024
Copy link

codecov bot commented May 18, 2024

Codecov Report

Attention: Patch coverage is 86.74699% with 11 lines in your changes missing coverage. Please review.

Project coverage is 70.28%. Comparing base (76d897e) to head (31aeaae).
Report is 1094 commits behind head on master.

Files with missing lines Patch % Lines
...src/dashboard/components/PropertiesModal/index.tsx 42.85% 3 Missing and 1 partial ⚠️
...d/src/explore/components/PropertiesModal/index.tsx 40.00% 3 Missing ⚠️
superset/commands/chart/update.py 83.33% 2 Missing ⚠️
superset/commands/dashboard/update.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #28570      +/-   ##
==========================================
+ Coverage   60.48%   70.28%   +9.79%     
==========================================
  Files        1931     1949      +18     
  Lines       76236    77586    +1350     
  Branches     8568     8731     +163     
==========================================
+ Hits        46114    54530    +8416     
+ Misses      28017    20927    -7090     
- Partials     2105     2129      +24     
Flag Coverage Δ
hive 49.08% <33.80%> (-0.08%) ⬇️
javascript 57.86% <41.66%> (+0.14%) ⬆️
mysql 77.19% <90.14%> (?)
postgres 77.32% <90.14%> (?)
presto 53.63% <33.80%> (-0.18%) ⬇️
python 83.52% <94.36%> (+20.04%) ⬆️
sqlite 76.77% <90.14%> (?)
unit 58.98% <66.19%> (+1.35%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -284,7 +285,9 @@ class ChartPutSchema(Schema):
)
is_managed_externally = fields.Boolean(allow_none=True, dump_default=False)
external_url = fields.String(allow_none=True)
tags = fields.Nested(TagSchema, many=True)
Copy link
Member

Choose a reason for hiding this comment

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

Where are we removing the TagSchema reference here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good catch -- I scanned for un-used imports but didn't realize that TagSchema was actually defined in this same file. I'll remove its definition in a follow up commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll hold on committing this change ☝️ until I get your feedback on the other comment.

Copy link
Member

Choose a reason for hiding this comment

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

So we should prolly centralize TagSchema somewhere it could be used in all the resource update schemas



def validate_tags(
object_type: str,
Copy link
Member

@hughhhh hughhhh May 20, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

def could! I was already using ObjectType for the update_tags method, but here thought about going with string because I'm using security_manager.can_access to check if the user has the required perm, which is case sensitive. We have two options here:

  1. Create a new enum with:
class AssetTypes(enum.Enum):
    CHART = "Chart"
    DASHBOARD = "Dashboard"
  1. Use the existing ObjectType and then call can_access using capitalize():
if not security_manager.can_access("can_tag", object_type.name.capitalize()):

@hughhhh would you have any preferences?

Copy link
Member

Choose a reason for hiding this comment

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

Let's go with #2 using ObjectType enum

@hughhhh
Copy link
Member

hughhhh commented May 21, 2024

Also @Vitor-Avila we need to update the calls for Query and Dataset to make sure they have the same ability to update the tags as well

@Vitor-Avila
Copy link
Contributor Author

Also @Vitor-Avila we need to update the calls for Query and Dataset to make sure they have the same ability to update the tags as well

@hughhhh for Saved Queries I'm not sure if it makes sense since you can't really assign a Tag via the UI to a single query -- you can only assign tags to Saved Queries via the BULK SELECT (and in this case I think it makes sense to use the bulk_create approach which is already the case).

Tags are not fully supported with Datasets yet (not sure if the association works, but the Datasets list doesn't show Tags, the Datasets properties modal doesn't show tags, Datasets schemas don't have tags, etc) so this would be a bigger change a bit out of the scope of this PR.

@github-actions github-actions bot added risk:db-migration PRs that require a DB migration doc Namespace | Anything related to documentation plugins dependencies:npm github_actions Pull requests that update GitHub Actions code packages labels May 28, 2024
@github-actions github-actions bot removed risk:db-migration PRs that require a DB migration doc Namespace | Anything related to documentation labels May 28, 2024
@github-actions github-actions bot removed plugins dependencies:npm github_actions Pull requests that update GitHub Actions code packages labels May 28, 2024
Copy link
Member

@hughhhh hughhhh left a comment

Choose a reason for hiding this comment

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

🚢 LGTM

@hughhhh hughhhh merged commit 0fdb4b7 into apache:master May 28, 2024
35 checks passed
EnxDev pushed a commit to EnxDev/superset that referenced this pull request May 31, 2024
eschutho pushed a commit that referenced this pull request Jun 5, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.1.0 labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the REST API 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels dashboard:properties Related to the properties of the Dashboard size/XXL 🚢 4.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants