-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Query Result API response shouldn't include query information for non authenticated users #3985
Conversation
…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
@@ -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: |
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'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.
redash/serializers/query_result.py
Outdated
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} |
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.
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.
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.
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
… 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
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.