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): Return homeProject when filtering workflows by project id #12077

Conversation

despairblue
Copy link
Contributor

@despairblue despairblue commented Dec 6, 2024

Summary

When filtering workflows by project Id we'd not return the home project if the user was not the owner of the workflow. Without that the FE shows incorrect ownerships of WFs:

image

The reason for that is that that we're filtering the workflows based on workflow.shared.projectId which will also filter down the workflow.shared list to only contain the sharings matching that projectId:

if (typeof options?.filter?.projectId === 'string' && options.filter.projectId !== '') {
options.filter.shared = { projectId: options.filter.projectId };
delete options.filter.projectId;
}

Later we iterate of workflow.shared assuming it contains all sharings:

for (const sharedEntity of shared) {
const { project, role } = sharedEntity;
if (role === 'credential:owner' || role === 'workflow:owner') {
entity.homeProject = {
id: project.id,
type: project.type,
name: project.name,
};
} else {
entity.sharedWithProjects.push({
id: project.id,
type: project.type,
name: project.name,
});
}
}

In raw SQL and with a query builder this can be fixed using sub=queries, but it's not possible to have this behavior with TypeORM's repository interface.

For credentials this was fixed 3 months ago: #10144

This PR implements the same fix for workflows.

image

Related Linear tickets, Github issues, and Community forum posts

This does not address what's in the description, but what this comment mentions:
https://linear.app/n8n/issue/PAY-2271/community-issue-credentials-in-project-personal-are-not-just-my#comment-9fe3bc10

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)

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Dec 6, 2024
@despairblue despairblue marked this pull request as ready for review December 6, 2024 13:21
@despairblue despairblue requested a review from r00gm December 6, 2024 15:34
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.

Confirmed working, thanks for fixing 🙏🏻

Comment on lines +69 to +81
// Since we're filtering using project ID as part of the relation,
// we end up filtering out all the other relations, meaning that if
// it's shared to a project, it won't be able to find the home project.
// To solve this, we have to get all the relation now, even though
// we're deleting them later.
if (typeof options?.filter?.projectId === 'string' && options.filter.projectId !== '') {
const relations = await this.sharedWorkflowRepository.getAllRelationsForWorkflows(
workflows.map((c) => c.id),
);
workflows.forEach((c) => {
c.shared = relations.filter((r) => r.workflowId === c.id);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The facts that we're having to do two queries for this, in-memory processing and fetching things that we later discard makes me wish we could use the query builder, but that'd be a larger refactor. Maybe to improve in future.

Copy link

cypress bot commented Dec 6, 2024

n8n    Run #8242

Run Properties:  status check passed Passed #8242  •  git commit efafeed334: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Project n8n
Branch Review master
Run status status check passed Passed #8242
Run duration 04m 36s
Commit git commit efafeed334: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Committer Danny Martini
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 480
View all changes introduced in this branch ↗︎

Copy link
Contributor

github-actions bot commented Dec 6, 2024

✅ All Cypress E2E specs passed

@despairblue despairblue merged commit efafeed into master Dec 8, 2024
43 checks passed
@despairblue despairblue deleted the pay-2271-community-issue-credentials-in-project-personal-are-not-just branch December 8, 2024 18:45
@github-actions github-actions bot mentioned this pull request Dec 11, 2024
@janober
Copy link
Member

janober commented Dec 11, 2024

Got released with n8n@1.72.0

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.

4 participants