-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Conversation
Codecov ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
CredentialsService.getMany()
(no-changelog)
Great PR! Please pay attention to the following items before merging: Files matching
Files matching
Make sure to check off this list before asking for review. |
There was a problem hiding this 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 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const credentials = await Db.collections.Credentials.find({ select, relations }); | |
const credentials = await Container.get(CredentialsRepository).find({ select, relations }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { OwnershipService } from '@/services/ownership.service'; | |
import { OwnershipService } from '@/services/ownership.service'; | |
import { CredentialsRepository } from '@/databases/repositories'; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 }) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is covered in the followup: https://github.com/n8n-io/n8n/pull/7041/files#diff-39f41209012fda27b308597ac9471c22beab53d2d0975bc0bb87e91b597c7c94
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks
|
Passing run #2069 ↗︎
Details:
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
|
✅ All Cypress E2E specs passed |
Got released with |
Consolidate
CredentialsService.getMany()
in preparation for adding list query middleware toGET /credentials
.