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

fix: When editing nodes only show the credentials in the dropdown that the user is allowed to use in that workflow #9718

Merged
merged 7 commits into from
Jun 14, 2024

Conversation

despairblue
Copy link
Contributor

@despairblue despairblue commented Jun 12, 2024

Summary

With the introduction of projects and RBAC we've been having issues with rendering the correct list of credentials for nodes in workflows in personal projects. We've patched GET /credentials multiple times to get it right and each time broke some edge case:
#9396
#9615
#9678

This PR introduces a new route that returns all credentials a user can use is a
specific workflow or project.

This route is used by the Node View and Node Credentials drop down.
They are not using the GET /credentials endpoint anymore, because they return

  • either all credentials a user have access to,
  • or all credentials a user have access to filtered by project.

But the credentials that a user can add to nodes in a workflow have further restrictions.
The new endpoint returns all credentials that the workflow can use when executing AND to which the user has access to.

For workflows in team project that's simple: It's only the credentials that exist in that project. Even having global read permissions does not circumvent this.

For workflows in personal projects it becomes more complex due to point to point sharing:
Untitled-2024-01-25-1160
The y axis is the global role of the user, the x axis describes their relation ship to the workflow, either they have no relationship, the workflow was shared with them, or they own the workflow.

The new endpoint first gets all credentials the user has access to, then all the credentials the workflow can use and then returns the intersection of both.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/PAY-1661/bug-cant-choose-the-right-credentials-in-a-personal-wf-as-an-owner-or

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@despairblue despairblue added the release/backport Changes that need to be backported to older releases. label Jun 12, 2024
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Jun 12, 2024
@despairblue despairblue force-pushed the filter-by-personal-project branch from a188f9c to 0b4459f Compare June 12, 2024 14:54
@despairblue despairblue marked this pull request as ready for review June 12, 2024 14:59
krynble
krynble previously approved these changes Jun 13, 2024
Copy link
Contributor

@krynble krynble left a comment

Choose a reason for hiding this comment

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

Thanks a lot for addressing this, I tested all the combinations I could think of manually as well and it's all working well.

@despairblue despairblue force-pushed the filter-by-personal-project branch from bc99637 to 71905be Compare June 13, 2024 19:24
@despairblue despairblue requested a review from krynble June 13, 2024 19:25
@despairblue
Copy link
Contributor Author

@krynble I had to rebase this. Could you re-approve? 🙏🏾

krynble
krynble previously approved these changes Jun 13, 2024
Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link

cypress bot commented Jun 13, 2024

1 failed and 4 flaky tests on run #5473 ↗︎

1 278 0 0 Flakiness 4

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Project: n8n Commit: 71905beff0
Status: Failed Duration: 04:49 💡
Started: Jun 14, 2024 7:53 AM Ended: Jun 14, 2024 7:58 AM
Failed  30-editor-after-route-changes.cy.ts • 1 failed test

View Output Video

Test Artifacts
Editor zoom should work after route changes > after switching between Editor and Workflow history and Workflow list Test Replay Screenshots Video
Failed  34-template-credentials-setup.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  25-stickies.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  24-ndv-paired-item.cy.ts • 0 failed tests

View Output

Test Artifacts
Failed  42-nps-survey.cy.ts • 0 failed tests

View Output

Test Artifacts

The first 5 failed specs are shown, see all 32 specs in Cypress Cloud.

Flakiness  5-ndv.cy.ts • 2 flaky tests

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Screenshots Video
NDV > Stop listening for trigger event from NDV Screenshots Video
Flakiness  10-undo-redo.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Undo/Redo > should undo/redo adding connected nodes Test Replay Screenshots Video
Flakiness  20-workflow-executions.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Current Workflow Executions > should auto load more items if there is space and auto scroll Test Replay Screenshots Video

Review all test suite changes for PR #9718 ↗︎

Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

@despairblue
Copy link
Contributor Author

I'll check the failing test locally.

@@ -102,7 +102,7 @@ const switchBetweenEditorAndHistory = () => {

const switchBetweenEditorAndWorkflowlist = () => {
cy.getByTestId('menu-item').first().click();
cy.wait(['@getUsers', '@getWorkflows', '@getActiveWorkflows', '@getCredentials']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to the home page does not actually load the credentials:
swappy-20240614_113801

swappy-20240614_113827

Maybe this worked before the new home page, but now the credentials are only loaded if you actually switch to the credentials tab.

On master this only works because the Node View calls GET /rest/credentials. With this PR that's not the case anymore.

I changed this cy.wait to do what I think the author intended, waiting until the workflow tab in the home page was completely loaded.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, ty for fixing!

@despairblue despairblue requested a review from krynble June 14, 2024 09:45
@despairblue
Copy link
Contributor Author

@krynble I fixed the test.

@despairblue despairblue merged commit 2cf4364 into master Jun 14, 2024
17 of 20 checks passed
@despairblue despairblue deleted the filter-by-personal-project branch June 14, 2024 12:48
adrian-martinez-onestic pushed a commit to onesdata/n8n-fork that referenced this pull request Jun 20, 2024
adrian-martinez-onestic pushed a commit to onesdata/n8n-fork that referenced this pull request Jun 20, 2024
This was referenced Jun 20, 2024
@janober
Copy link
Member

janober commented Jun 20, 2024

Got released with [email protected]

1 similar comment
@janober
Copy link
Member

janober commented Jun 20, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team release/backport Changes that need to be backported to older releases. Released ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants