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

Query Result API response shouldn't include query information for non authenticated users #3985

Merged
merged 9 commits into from
Jul 18, 2019

Conversation

rauchy
Copy link
Contributor

@rauchy rauchy commented Jul 16, 2019

Query Results API response should include the bare minimum fields if this is an API call (dashboard, query) and not an authenticated user.

We need to move the serialization logic into redash.serializers and apply the relevant checks.

@arikfr arikfr added the Backend label Jul 15, 2019
Omer Lachish added 2 commits July 16, 2019 09:12
…isualization and therefore do not return any promise
…se something needs to be done with it at a later time, and it's the right thing to do anyway
@rauchy rauchy self-assigned this Jul 16, 2019
@rauchy rauchy requested a review from arikfr July 16, 2019 08:17
@@ -57,6 +57,14 @@ def _get_column_lists(columns):
return fieldnames, special_columns


def serialize_query_result(query_result, is_api_user):
if is_api_user:
Copy link
Member

Choose a reason for hiding this comment

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

It's safe to use current_user in the serialization code instead of passing is_api_user. It's not a big deal for this PR, but #3782 will extend this method to apply other checks anyway.

client/app/pages/dashboards/public-dashboard-page.js Outdated Show resolved Hide resolved
def serialize_query_result(query_result, is_api_user):
if is_api_user:
publicly_needed_keys = ['data', 'retrieved_at']
return {key: query_result.to_dict()[key] for key in publicly_needed_keys}
Copy link
Member

Choose a reason for hiding this comment

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

Current implementation will call to_dict multiple times, which will result in calling json_loads multiple times.

You should make sure to call to_dict only once, and you can also use project instead of "manual" extraction.

Copy link
Contributor Author

@rauchy rauchy Jul 16, 2019

Choose a reason for hiding this comment

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

You've shown me project before, and I was looking for it with the wrong search term (looked for dict masking in Python, but all examples were soooo complicated). Thanks! 371ecd2

@arikfr arikfr merged commit d1edd3d into master Jul 18, 2019
@arikfr arikfr deleted the reduce-query-data-shape-for-unauthenticated-users branch July 18, 2019 09:12
harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
… authenticated users (getredash#3985)

* avoid catching errors on text widgets' load(), as they don't have a visualization and therefore do not return any promise

* throw error when failing to load widgets on public dashboards - in case something needs to be done with it at a later time, and it's the right thing to do anyway

* use Promise.resolve instead of checking for undefined

* call serialize_query_result instead of directly calling to_dict

* filter unneeded query result fields for unauthenticated users

* test for serialization filtering

* lint

* use project instead of list comprehension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants