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

Few bugfixes #2320

Merged
merged 6 commits into from
Feb 20, 2018
Merged

Few bugfixes #2320

merged 6 commits into from
Feb 20, 2018

Conversation

kravets-levko
Copy link
Collaborator

  1. https://discuss.redash.io/t/v4-beta-public-sharing-blank/1533
  2. After generating "Invite user" link and "Reset password" link, UI showed relative link (only path fragment), and UI was inconsistent (one of them was shown in textarea and another - as link). Now it looks like this:

image
image

@@ -27,9 +27,9 @@ const layouts = {
function selectLayout(route) {
let layout = layouts.default;
if (route.layout) {
layout = layouts[route.layout];
layout = layouts[route.layout] || layouts.default;
Copy link
Member

Choose a reason for hiding this comment

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

👌

} else if (!route.authenticated) {
layout = layout.defaultSignedOut;
layout = layouts.defaultSignedOut;
Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️

@@ -0,0 +1,18 @@
function fullUrl($location, url) {
const scheme = $location.protocol().toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

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

Why not use window.location and drop the dependency on Angular?

return serializers.public_dashboard(dashboard)
return project(
dashboard.to_dict(with_widgets=True, user=self.current_user),
('name', 'layout', 'dashboard_filters_enabled', 'updated_at', 'created_at', 'widgets')
Copy link
Member

Choose a reason for hiding this comment

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

The serializer does more than that: it removes fields we don't want to expose publicly (like the query text) and includes fields we usually don't like the query result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can agree with you, but my opinion (based on my experience) is that such code is very error-prone - when database schema or data structures (like dashboard layout in this case) changes - such code most likely will not be updated (like in in this case :-) ). So, can we implement this in some different way? say, id field is sensitive (BTW - is it really sensitive?) - maybe it's simpler just omit few fields? WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

How is it different when using project? The call to project will not be updated the same way the serializer wasn't updated. :-)

Some context on serializers: the idea is to stop putting serialization logic in the models code (the to_dict methods). It's not a concern of the models and it makes code harder to write, as we can't assume state we usually have when we serialize data (like current_user).

The mistake here (aside from not having good UI tests that could've caught this) was to duplicate widgets layout logic in the public dashboards serializer. As you suggested we need to call the non public serializer (currently the Dashboard#to_dict method), and omit data from the returned object (along with adding the query result). But we need to do it in the serializer.

Copy link
Member

Choose a reason for hiding this comment

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

I realized that we suggested the same thing. The only difference is that current implementation missing the update of the widgets' properties and the location of the code (directly in handler or in serializer).

Copy link
Collaborator Author

@kravets-levko kravets-levko Feb 16, 2018

Choose a reason for hiding this comment

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

I actually don't clearly understand why we need that serializer at all. Let me explain.

I see two reasons why we may need to transform data for public dashboards:

  1. protect sensitive data - in this case, I think it's better not to pick "safe" fields (with project), but remove "unsafe" ones with omit. both options are error-prone; but we also should remember that front-end code expects data in some format, and when some fields are missing - it may lead to strange bugs.
  2. save some traffic via removing unused fields - I think it's not a reason at all - we will save, say, 500 bytes, or even 1000 bytes (but it should be really large dashboard), but will make our code potentially buggy.

I addition, one day we're going to merge dashboard and public dashboard code, and in this case we (probably) will need the same data format for both (#2076).

If I'm missing something - just explain me please. I really want to make this better :-)

P.S. The only this I missed (noticed while typing this comment) - I removed code that processed hidden text boxes. It definitely should be restored.
P.P.S. Can't find code that processes hidden text widgets at all. Will check more carefully when working on changes to this PR - it's possible that we have one more bug here

Copy link
Member

Choose a reason for hiding this comment

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

The main reason for omitting the fields is security concerns, because of that I actually think that project is the right choice. While both are error prone, it's better to have a bug than a data leak.

As for why put this in a serializer function rather inline in this handler:

  • Better separation of concerns.
  • To be able to reuse the code (the way we serialize visualizations/query can be reused in embed API calls for a visualization).

Hidden text boxes: I think we can drop this code. It was added by someone to allow adding <script> tags into the dashboard. That's not functionality that we want to keep supporting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, got it. I'll amend this commit - it will be easier to restore code. But GitHub should keep our discussion.

About hidden textboxes - should we also remove the checkbox (and related JS) from UI?

@kravets-levko
Copy link
Collaborator Author

@arikfr Updated this PR: restored serializers (but fixed them), removed code related to hidden text widgets (that flag is not used anywhere)

}

export default function init(ngModule) {
ngModule.factory('Utils', () => ({
Copy link
Member

Choose a reason for hiding this comment

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

We don't need Angular's DI here. We can just export absoluteUrl and then where we need to use it:

import { absoluteUrl } from '@/services/utils';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great idea, it's definitely better 👍 Will do in few minutes

@arikfr arikfr added this to the v4 milestone Feb 20, 2018
@arikfr arikfr merged commit bd13b78 into getredash:master Feb 20, 2018
@kravets-levko kravets-levko deleted the bug/few-bugfixes branch February 11, 2019 16:48
dairyo pushed a commit to KiiCorp/redash that referenced this pull request Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants