Skip to content

Commit

Permalink
fix extra code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace committed Feb 12, 2020
1 parent 1a048c3 commit 008ce3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ This file documents any backwards-incompatible changes in Superset and
assists people when migrating to a new version.

## Next
* [9109](https://github.com/apache/incubator-superset/pull/9109): Expire `filter_immune_slices` and
`filter_immune_filter_fields` to favor dashboard scoped filter metadata `filter_scopes`.

* [9046](https://github.com/apache/incubator-superset/pull/9046): Replaces `can_only_access_owned_queries` by
`all_query_access` favoring a white list approach. Since a new permission is introduced use `superset init`
to create and associate it by default to the `Admin` role. Note that, by default, all non `Admin` users will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,27 @@ def upgrade():
if "filter_scopes" in json_metadata:
continue

filter_scopes = {}
filters = [
slice for slice in dashboard.slices if slice.viz_type == "filter_box"
]

# if dashboard has filter_box
if filters:
filter_scopes = convert_filter_scopes(json_metadata, filters)

json_metadata.pop("filter_immune_slices", None)
json_metadata.pop("filter_immune_slice_fields", None)
if filter_scopes:
json_metadata["filter_scopes"] = filter_scopes
logging.info(
f"Adding filter_scopes for dashboard {dashboard.id}: {json.dumps(filter_scopes)}"
)

json_metadata.pop("filter_immune_slices", None)
json_metadata.pop("filter_immune_slice_fields", None)

if json_metadata:
dashboard.json_metadata = json.dumps(
json_metadata, indent=None, separators=(",", ":"), sort_keys=True
)
else:
dashboard.json_metadata = None

session.merge(dashboard)
except Exception as e:
Expand Down
5 changes: 2 additions & 3 deletions superset/utils/dashboard_filter_scopes_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
import json
import logging
from collections import defaultdict
from typing import Dict, List

from superset.models.slice import Slice
Expand All @@ -26,13 +27,11 @@
def convert_filter_scopes(json_metadata: Dict, filters: List[Slice]):
filter_scopes = {}
immuned_by_id: List[int] = json_metadata.get("filter_immune_slices") or []
immuned_by_column: Dict = {}
immuned_by_column: Dict = defaultdict(list)
for slice_id, columns in json_metadata.get(
"filter_immune_slice_fields", {}
).items():
for column in columns:
if immuned_by_column.get(column, None) is None:
immuned_by_column[column] = []
immuned_by_column[column].append(int(slice_id))

def add_filter_scope(filter_field, filter_id):
Expand Down

0 comments on commit 008ce3f

Please sign in to comment.