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

refactor(core): Consolidate CredentialsService.getMany() (no-changelog) #7028

Merged
merged 39 commits into from
Sep 4, 2023

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Aug 28, 2023

Consolidate CredentialsService.getMany() in preparation for adding list query middleware to GET /credentials.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Aug 28, 2023
@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01% ⚠️

Comparison is base (9dd5f0e) 32.11% compared to head (90ed65e) 32.11%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7028      +/-   ##
==========================================
- Coverage   32.11%   32.11%   -0.01%     
==========================================
  Files        3188     3188              
  Lines      195892   195897       +5     
  Branches    21363    21362       -1     
==========================================
  Hits        62908    62908              
- Misses     131951   131957       +6     
+ Partials     1033     1032       -1     
Files Changed Coverage Δ
packages/cli/src/WorkflowHelpers.ts 50.25% <ø> (ø)
...ages/cli/src/credentials/credentials.service.ee.ts 93.93% <ø> (+0.75%) ⬆️
packages/cli/src/requests.ts 100.00% <ø> (ø)
...s/cli/src/credentials/credentials.controller.ee.ts 78.08% <100.00%> (+0.58%) ⬆️
...ages/cli/src/credentials/credentials.controller.ts 85.71% <100.00%> (ø)
...ackages/cli/src/credentials/credentials.service.ts 77.30% <100.00%> (+2.11%) ⬆️
packages/cli/src/services/ownership.service.ts 85.29% <100.00%> (+7.03%) ⬆️
...kages/cli/src/workflows/workflows.controller.ee.ts 77.04% <100.00%> (ø)
...ackages/cli/src/workflows/workflows.services.ee.ts 82.95% <100.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ivov ivov changed the title feat(core): Add filtering, selection and pagination to credentials refactor(core): Consolidate CredentialsService.getMany() (no-changelog) Aug 28, 2023
Base automatically changed from pay-646-allow-filtering-and-querying-for-users to master August 28, 2023 14:13
@github-actions
Copy link
Contributor

Great PR! Please pay attention to the following items before merging:

Files matching packages/**:

  • If fixing bug, added test to cover scenario.
  • If addressing forum or Github issue, added link to description.

Files matching packages/**/*.ts:

  • Added unit tests to cover new or updated functionality.

Make sure to check off this list before asking for review.

@ivov ivov marked this pull request as ready for review August 28, 2023 14:40
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.

Overall it looks great, I think there are some small improvements that can be made.

Container.get(OwnershipService).addOwnedByAndSharedWith(c);

if (returnAll) {
const credentials = await Db.collections.Credentials.find({ select, relations });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const credentials = await Db.collections.Credentials.find({ select, relations });
const credentials = await Container.get(CredentialsRepository).find({ select, relations });

Copy link
Contributor

Choose a reason for hiding this comment

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

We can try to remove references to Db.collections.Credentials and use the repository instead wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My reasoning for why this wasn't worth it is that, from what I understand, the root issue here is that CredentialsService (and many others like it) do not currently allow for dependency injection. This means, I can add calls to Container.get() but we'd have to touch this again when we refactor this properly, so it seems not worth it at this time.

@@ -24,6 +24,7 @@ import type { User } from '@db/entities/User';
import type { CredentialRequest } from '@/requests';
import { CredentialTypes } from '@/CredentialTypes';
import { RoleService } from '@/services/role.service';
import { OwnershipService } from '@/services/ownership.service';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { OwnershipService } from '@/services/ownership.service';
import { OwnershipService } from '@/services/ownership.service';
import { CredentialsRepository } from '@/databases/repositories';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, what do you mean? I don't see CredentialsRepository used in this file?

@@ -50,4 +51,25 @@ export class OwnershipService {
ownedBy: ownerId ? { id: ownerId } : null,
});
}

addOwnedByAndSharedWith(_credential: CredentialsEntity): Credentials.WithOwnedByAndSharedWith {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
addOwnedByAndSharedWith(_credential: CredentialsEntity): Credentials.WithOwnedByAndSharedWith {
addOwnedByAndSharedWithToCredentials(_credential: CredentialsEntity): Credentials.WithOwnedByAndSharedWith {

Simply because we might do the same for workflows, right? We have the addOwnedBy above that could be renamed to contain also clarification about what it applies to (maybe out of context of this PR)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also can we add some unit tests covering this function?

Copy link
Contributor Author

@ivov ivov Sep 1, 2023

Choose a reason for hiding this comment

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

Simply because we might do the same for workflows, right? We have the addOwnedBy above that could be renamed to contain also clarification about what it applies to (maybe out of context of this PR)

I think this is clear from the typing? Different entities require different fields, and the caller cannot misuse the methods - the typing will block them if they try to.

Also can we add some unit tests covering this function?

Will do! Edit: Done!

select: SELECT_FIELDS,
relations: options?.relations,
});
static async getMany(user: User, options?: { disableGlobalRole: boolean }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a good bit of logic in this function, can we add some tests to it? We need to assert that the repository is called with the correct relations, select dolumns and the correct query is performed depending on the user types and arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

LGTM! Thanks

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

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

@cypress
Copy link

cypress bot commented Sep 1, 2023

Passing run #2069 ↗︎

0 238 0 0 Flakiness 0

Details:

🌳 pay-647 🖥️ browsers:node18.12.0-chrome107 🤖 ivov 🗃️ e2e/*
Project: n8n Commit: 90ed65e28f
Status: Passed Duration: 08:27 💡
Started: Sep 4, 2023 8:28 AM Ended: Sep 4, 2023 8:36 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

✅ All Cypress E2E specs passed

@ivov ivov merged commit 442b910 into master Sep 4, 2023
18 checks passed
@ivov ivov deleted the pay-647 branch September 4, 2023 08:37
@janober
Copy link
Member

janober commented Sep 6, 2023

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

3 participants