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(core): Allow owner and admin to edit nodes with credentials that haven't been shared with them explicitly #9922

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

despairblue
Copy link
Contributor

Summary

Previously, the owners and admins were not allowed to use credentials in workflows that they did not own. They first had to share them with themselves, and then they could use them in workflows.

With #9718 we started showing credentials in the dropdown that they did not own and haven't been shared with them, but when choosing them the node edit view would turn read only.

With this PR the node edit view now stays editable.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/PAY-1296/bug-owner-user-cant-edit-workflow

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jul 3, 2024
@despairblue despairblue marked this pull request as ready for review July 3, 2024 09:44
@@ -428,28 +428,38 @@ describe('GET /workflows/:workflowId', () => {
expect(responseWorkflow.sharedWithProjects).toHaveLength(0);
});

test('should return workflow with credentials saying owner does not have access when not shared', async () => {
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
test.each([
Copy link
Contributor

Choose a reason for hiding this comment

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

This converted the existing test rather than adding to it. I'd expect we'd want to keep a test for the member scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the next test is covering the scenario for members.

test('should return workflow with credentials for all users with or without access', async () => {
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
const workflowPayload = makeWorkflow({
withPinData: false,
withCredential: { id: savedCredential.id, name: savedCredential.name },
});
const workflow = await createWorkflow(workflowPayload, member);
await shareWorkflowWithUsers(workflow, [anotherMember]);
const responseMember1 = await authMemberAgent.get(`/workflows/${workflow.id}`).expect(200);
const member1Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember1.body.data;
expect(member1Workflow.usedCredentials).toMatchObject([
{
id: savedCredential.id,
name: savedCredential.name,
currentUserHasAccess: true, // one user has access
},
]);
expect(member1Workflow.sharedWithProjects).toHaveLength(1);
const responseMember2 = await authAnotherMemberAgent
.get(`/workflows/${workflow.id}`)
.expect(200);
const member2Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember2.body.data;
expect(member2Workflow.usedCredentials).toMatchObject([
{
id: savedCredential.id,
name: savedCredential.name,
currentUserHasAccess: false, // the other one doesn't
},
]);
expect(member2Workflow.sharedWithProjects).toHaveLength(1);
});

This test was only checking the owner scenario.

test('should return workflow with credentials saying owner does not have access when not shared', async () => {
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
test.each([
['owner', () => owner],
Copy link
Contributor

Choose a reason for hiding this comment

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

For learning, why does this need to be a function? I'd've passed the actor directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's evaluated before the beforeAll block and thus it would just evaluate to undefined and pass this to each, whereas using a function creates a closure to the original binding and evaluates this only when called from inside the test. At that point beforeAll already ran.

I hope that makes sense.

@despairblue despairblue requested a review from ivov July 5, 2024 09:12
ivov
ivov previously approved these changes Jul 5, 2024
Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

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

🙏🏻

Copy link
Contributor

github-actions bot commented Jul 5, 2024

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

Copy link

cypress bot commented Jul 5, 2024

2 flaky tests on run #5849 ↗︎

0 399 0 0 Flakiness 2

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Project: n8n Commit: 26078058cb
Status: Passed Duration: 04:56 💡
Started: Jul 9, 2024 1:42 PM Ended: Jul 9, 2024 1:47 PM
Flakiness  5-ndv.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Screenshots Video
Flakiness  24-ndv-paired-item.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > resolves expression with default item when input node is not parent, while still pairing items Test Replay Screenshots Video

Review all test suite changes for PR #9922 ↗︎

Copy link
Contributor

github-actions bot commented Jul 8, 2024

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

Copy link
Contributor

github-actions bot commented Jul 9, 2024

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

@despairblue despairblue force-pushed the pay-1296-bug-owner-user-cant-edit-workflow branch from c49bdd9 to 2607805 Compare July 9, 2024 08:03
@despairblue despairblue requested a review from ivov July 9, 2024 08:03
Copy link
Contributor

github-actions bot commented Jul 9, 2024

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

2 similar comments
Copy link
Contributor

github-actions bot commented Jul 9, 2024

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

Copy link
Contributor

github-actions bot commented Jul 9, 2024

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

Copy link
Contributor

github-actions bot commented Jul 9, 2024

✅ All Cypress E2E specs passed

@despairblue despairblue merged commit 0f49598 into master Jul 9, 2024
27 checks passed
@despairblue despairblue deleted the pay-1296-bug-owner-user-cant-edit-workflow branch July 9, 2024 14:25
@janober
Copy link
Member

janober commented Jul 10, 2024

Got released with n8n@1.50.0

jeanpaul pushed a commit that referenced this pull request Jul 11, 2024
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 Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants