-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
feat(charts): security perm simplification #11981
Merged
dpgaspar
merged 15 commits into
apache:master
from
preset-io:feat/security-converge-charts
Dec 15, 2020
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6a3c268
feat(charts): security perm simplification
dpgaspar 295a16d
fix superset explore
dpgaspar 64214f4
fix JS test
dpgaspar e9a3bae
fix cypress test
dpgaspar a92a0a9
fix split heads
dpgaspar db91389
fix favorite permission
dpgaspar bc7dacb
fix permission
dpgaspar b2ccb95
Merge branch 'master' into feat/security-converge-charts
dpgaspar 2d2291a
Merge branch 'master' into feat/security-converge-charts
dpgaspar 8d9ba51
Merge branch 'feat/security-converge-charts' of github.com:preset-io/…
dpgaspar 457e63b
update with new async permission
dpgaspar c5fd494
fix new permission coming from master
dpgaspar 981b905
fix core permission assert
dpgaspar af4fb92
black
dpgaspar e10bc0b
update alembic down revision
dpgaspar 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
86 changes: 86 additions & 0 deletions
86
superset/migrations/versions/ccb74baaa89b_security_converge_charts.py
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""security converge charts | ||
|
||
Revision ID: ccb74baaa89b | ||
Revises: 811494c0cc23 | ||
Create Date: 2020-12-09 14:13:48.058003 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ccb74baaa89b" | ||
down_revision = "811494c0cc23" | ||
|
||
|
||
from alembic import op | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import Session | ||
|
||
from superset.migrations.shared.security_converge import ( | ||
add_pvms, | ||
get_reversed_new_pvms, | ||
get_reversed_pvm_map, | ||
migrate_roles, | ||
Pvm, | ||
) | ||
|
||
NEW_PVMS = {"Chart": ("can_read", "can_write",)} | ||
PVM_MAP = { | ||
Pvm("SliceModelView", "can_list"): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceModelView", "can_show"): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceModelView", "can_edit",): (Pvm("Chart", "can_write"),), | ||
Pvm("SliceModelView", "can_delete",): (Pvm("Chart", "can_write"),), | ||
Pvm("SliceModelView", "can_add",): (Pvm("Chart", "can_write"),), | ||
Pvm("SliceModelView", "can_download",): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceModelView", "muldelete",): (Pvm("Chart", "can_write"),), | ||
Pvm("SliceModelView", "can_mulexport",): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceModelView", "can_favorite_status",): (Pvm("Chart", "can_write"),), | ||
Pvm("SliceModelView", "can_cache_screenshot",): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceModelView", "can_screenshot",): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceAsync", "can_list",): (Pvm("Chart", "can_read"),), | ||
Pvm("SliceAsync", "muldelete",): (Pvm("Chart", "can_read"),), | ||
} | ||
|
||
|
||
def upgrade(): | ||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
# Add the new permissions on the migration itself | ||
add_pvms(session, NEW_PVMS) | ||
migrate_roles(session, PVM_MAP) | ||
try: | ||
session.commit() | ||
except SQLAlchemyError as ex: | ||
print(f"An error occurred while upgrading permissions: {ex}") | ||
session.rollback() | ||
|
||
|
||
def downgrade(): | ||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
# Add the old permissions on the migration itself | ||
add_pvms(session, get_reversed_new_pvms(PVM_MAP)) | ||
migrate_roles(session, get_reversed_pvm_map(PVM_MAP)) | ||
try: | ||
session.commit() | ||
except SQLAlchemyError as ex: | ||
print(f"An error occurred while downgrading permissions: {ex}") | ||
session.rollback() | ||
pass |
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
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.
Hmm...should this be "can_read"? Does favoriting a chart do anything other than create a record of the favorite?
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.
it should, actually that's a GET so it's really a mistake. Very nice catch