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

Stop Automatically Enabling Columns Added to a Table in its Views #13625

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Ghrehh
Copy link
Collaborator

@Ghrehh Ghrehh commented May 7, 2024

Noticed an issue/oversight where adding a column to a table with views would also automatically enable that column on the view. This not only seems a little insecure, but also wasn't reflected in the UI, which recognised the newly added column as disabled.

Though the field is marked disabled in the UI, a consumer of the view in the client has access to the new field, which can be seen by looking at the API response or doing some binding trickery.

This seems to be due to how columns being enabled or disabled in views is handled. For the backend, the presence of the column in the view schema denotes that it's enabled, and visible: true/false isn't respected. The code that was removed to fix the issue below actually enabled the field, which doesn't seem to be the intention.

I don't think this fix breaks anything else, but it would be good for someone on the backend team to look over this for me please 🙏 The code for views was very complex 🙃

@Ghrehh Ghrehh requested a review from a team as a code owner May 7, 2024 08:04
@Ghrehh Ghrehh requested review from adrinr, samwho, mike12345567, deanhannigan and aptkingston and removed request for a team May 7, 2024 08:04
Copy link
Contributor

@deanhannigan deanhannigan left a comment

Choose a reason for hiding this comment

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

You could also leave in the snippet you removed and just filter out the fields in the search request itself. Columns with config set to { visible : false } could be filtered out here:
https://github.com/Budibase/budibase/blob/master/packages/server/src/api/controllers/row/views.ts#L27

This wouldn't require any update to the view and should immediately hide the value in subsequent view requests.

@samwho
Copy link
Collaborator

samwho commented May 7, 2024

This appears to have broken some tests, and I'm not sure myself what the correct behaviour would be. @mike12345567?

@mike12345567
Copy link
Collaborator

This appears to have broken some tests, and I'm not sure myself what the correct behaviour would be. @mike12345567?

This is due to the way the tests are written - they depended on the syncSchema function which has been adjusted in this PR adding the columns to the view.

This functionality changes that logic so that columns are not added to views without a specific call to do so - therefore the tests will need to be updated to mimic this logic.

Everywhere in the views.spec.ts test that the syncSchema has been called, this will need to be adjusted to instead explicitly sync the schema and then update the schema with the columns. This is a more unit-test-y example of a test as it doesn't go through the API at all, which makes this a little more difficult.

This is a tough one because the test does appear to dependent on the functionality that this is changing, so the test does need a bit of reconfiguration to work in the flow that is now expected.

@aptkingston
Copy link
Member

Just to check - was the issue that you can see the field in the view schema, or that you actually get access to data in that field if you read a row through the view?

If it's just the former then I'm pretty sure that's by design - the schema isn't intended to be secret, and we want to be able to tell what fields exist but are invisible so we can do things like show them for the builder to toggle visible again, or warn users that there are hidden required fields (which is something the grid currently does).

If it's the latter then yea this definitely needs addressed.

@Ghrehh
Copy link
Collaborator Author

Ghrehh commented May 21, 2024

@aptkingston It was the latter, in the scenario I outlined in the main body of the PR a view could expose a value present in the base table that wasn't specified as a column in the view.

@adrinr adrinr added the feature-branch Release this PR code into a feature branch label May 24, 2024
@adrinr
Copy link
Collaborator

adrinr commented May 24, 2024

@Ghrehh I could not replicate the issue in master. I created a view, added a new column, but it's hidden in the views for both client and builder. Could you send a video or a step by step replication?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-branch Release this PR code into a feature branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants