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

Refine gamma experience #883

Merged
merged 3 commits into from
Aug 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ def get_perms(self):
return perms


class TableSlice(CaravelFilter):
def apply(self, query, func): # noqa
if any([r.name in ('Admin', 'Alpha') for r in get_user_roles()]):
return query
perms = self.get_perms()
tables = []
for perm in perms:
match = re.search(r'\(id:(\d+)\)', perm)
tables.append(match.group(1))
qry = query.filter(self.model.id.in_(tables))
return qry


class FilterSlice(CaravelFilter):
def apply(self, query, func): # noqa
if any([r.name in ('Admin', 'Alpha') for r in get_user_roles()]):
Expand Down Expand Up @@ -157,6 +170,22 @@ def apply(self, query, func): # noqa
return query


class FilterDashboardSlices(CaravelFilter):
def apply(self, query, value): # noqa
if any([r.name in ('Admin', 'Alpha') for r in get_user_roles()]):
return query
qry = query.filter(self.model.perm.in_(self.get_perms()))
return qry


class FilterDashboardOwners(CaravelFilter):
def apply(self, query, value): # noqa
if any([r.name in ('Admin', 'Alpha') for r in get_user_roles()]):
return query
qry = query.filter_by(id=g.user.id)
return qry


def validate_json(form, field): # noqa
try:
json.loads(field.data)
Expand Down Expand Up @@ -447,6 +476,7 @@ class TableModelView(CaravelModelView, DeleteMixin): # noqa
"Supports <a href='https://daringfireball.net/projects/markdown/'>"
"markdown</a>"),
}
base_filters = [['id', TableSlice, lambda: []]]
label_columns = {
'table_link': _("Table"),
'changed_by_': _("Changed By"),
Expand Down Expand Up @@ -652,6 +682,14 @@ class DashboardModelView(CaravelModelView, DeleteMixin): # noqa
'owners': _("Owners is a list of users who can alter the dashboard."),
}
base_filters = [['slice', FilterDashboard, lambda: []]]
add_form_query_rel_fields = {
'slices': [['slices', FilterDashboardSlices, None]],
'owners': [['owners', FilterDashboardOwners, None]],
}
edit_form_query_rel_fields = {
'slices': [['slices', FilterDashboardSlices, None]],
'owners': [['owners', FilterDashboardOwners, None]],
}
label_columns = {
'dashboard_link': _("Dashboard"),
'dashboard_title': _("Title"),
Expand Down