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

feat(core): Implement project:viewer role #9611

Merged
merged 8 commits into from
Jun 6, 2024

Conversation

despairblue
Copy link
Contributor

@despairblue despairblue commented Jun 4, 2024

Summary

Add a project viewer role.

This role only allows the user to view workflows, credentials and executions within a project, but not to create or modify them.

Related tickets and issues

https://linear.app/n8n/issue/PAY-1423/add-new-project-viewer-role

Review / Merge checklist

  • PR title and summary are descriptive. Remember, the title automatically goes into the changelog. Use (no-changelog) otherwise. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.

    A bug is not considered fixed, unless a test is added to prevent it from happening again.
    A feature is not complete without tests.

They both test the same endoint but different features and just by
reading the suites name it was not distinguishable.
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jun 4, 2024
@despairblue despairblue force-pushed the pay-1423-add-new-project-viewer-role branch from 23921d4 to e14d421 Compare June 4, 2024 09:32
@despairblue despairblue marked this pull request as ready for review June 4, 2024 11:57
@@ -275,7 +275,7 @@ export class CredentialsService {

if (typeof projectId === 'string' && project === null) {
throw new BadRequestError(
"You don't have the permissions to save the workflow in this project.",
"You don't have the permissions to save the credential in this project.",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unrelated fix

@@ -685,7 +685,7 @@ describe('POST /credentials', () => {
//
.expect(400, {
code: 400,
message: "You don't have the permissions to save the workflow in this project.",
message: "You don't have the permissions to save the credential in this project.",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unrelated fix

expect(tp2Relations.find((p) => p.userId === ownerUser.id)?.role).toBe('project:editor');
});

test('should not add from a project adding user with an unlicensed role', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't know what this means, but judging from the body this tests that you can't assign a role that isn't licensed.

I changed the title and amended the implementation to test editors and viewers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sure to ignore white space when reviewing this PR.

I combined all the PATCH suites into one describe block.

@despairblue despairblue force-pushed the pay-1423-add-new-project-viewer-role branch from d58b228 to fd41447 Compare June 4, 2024 12:32
@despairblue despairblue force-pushed the pay-1423-add-new-project-viewer-role branch from b954ce6 to d3ab534 Compare June 4, 2024 13:29
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sure to ignore white space when reviewing this PR.

I combined all the PATCH suites into one describe block.

krynble
krynble previously approved these changes Jun 6, 2024
.get(`/credentials/${savedCredential.id}`);

expect(response.statusCode).toBe(200);
expect(response.body.data).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether we should return this or not, as the UI only shows the fields if the credential:update scope exists, so the fields won't be visible in the UI, and returning the data is just more potential to leakage wdyt? Maybe we can remove the data attribute

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I'm thinking that this might be the top-level data and not the actual credential information, so it should be fine. I'll approve in this case.

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 amended the assertions, it now asserts that the viewer cannot see the data.data attribute.

Copy link

cypress bot commented Jun 6, 2024

2 flaky tests on run #5335 ↗︎

0 356 0 0 Flakiness 2

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Project: n8n Commit: 861d97f566
Status: Passed Duration: 04:45 💡
Started: Jun 6, 2024 9:11 AM Ended: Jun 6, 2024 9:15 AM
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 #9611 ↗︎

Copy link
Contributor

github-actions bot commented Jun 6, 2024

✅ All Cypress E2E specs passed

also making sure that the viewer cannot read credential data
Copy link
Contributor

github-actions bot commented Jun 6, 2024

✅ All Cypress E2E specs passed

@despairblue despairblue merged commit 6187cc5 into master Jun 6, 2024
35 checks passed
@despairblue despairblue deleted the pay-1423-add-new-project-viewer-role branch June 6, 2024 09:55
@github-actions github-actions bot mentioned this pull request Jun 12, 2024
@janober
Copy link
Member

janober commented Jun 12, 2024

Got released with n8n@1.46.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.

None yet

3 participants