diff --git a/packages/insomnia/src/account/session.ts b/packages/insomnia/src/account/session.ts index 3b9a7f9c585..56c1cf1a083 100644 --- a/packages/insomnia/src/account/session.ts +++ b/packages/insomnia/src/account/session.ts @@ -26,11 +26,7 @@ export async function absorbKey(sessionId: string, key: string) { getUserProfile({ sessionId: sessionIdResolved }), getEncryptionKeys({ sessionId: sessionIdResolved }), ]); - const { - public_key: publicKey, - enc_private_key: encPrivateKey, - enc_symmetric_key: encSymmetricKey, - } = keys; + const { public_key: publicKey, enc_private_key: encPrivateKey, enc_symmetric_key: encSymmetricKey } = keys; const { email, id: accountId, first_name: firstName, last_name: lastName } = profile; const symmetricKeyStr = crypt.decryptAES(key, JSON.parse(encSymmetricKey)); @@ -224,7 +220,7 @@ async function _removeAllCredentials() { * each model instance individually to clear them all out. * */ -async function _removeGitRepository(repo: GitRepository) { +export async function _removeGitRepository(repo: GitRepository) { const queryIds = models.project.getQueryableGitRepositoryIds(repo._id); const projects = await database.find(models.project.type, { gitRepositoryId: { $in: queryIds } }); for (const p of projects) { diff --git a/packages/insomnia/src/routes/git-credentials.$id.delete.tsx b/packages/insomnia/src/routes/git-credentials.$id.delete.tsx index 284e3045697..02820ef15bf 100644 --- a/packages/insomnia/src/routes/git-credentials.$id.delete.tsx +++ b/packages/insomnia/src/routes/git-credentials.$id.delete.tsx @@ -1,5 +1,6 @@ import { href } from 'react-router'; +import { _removeGitRepository } from '~/account/session'; import { services } from '~/insomnia-data'; import { invariant } from '~/utils/invariant'; import { createFetcherSubmitHook } from '~/utils/router'; @@ -15,7 +16,7 @@ export async function clientAction({ params }: Route.ClientActionArgs) { const connectedRepositories = await services.gitRepository.getAllByCredentialId(id); for (const repo of connectedRepositories) { - await services.gitRepository.update(repo, { credentialsId: null }); + await _removeGitRepository(repo); } await services.gitCredentials.remove(credential); diff --git a/packages/insomnia/src/routes/git-credentials.$id.related-projects.tsx b/packages/insomnia/src/routes/git-credentials.$id.related-projects.tsx index 2992a99becc..89ca839d79c 100644 --- a/packages/insomnia/src/routes/git-credentials.$id.related-projects.tsx +++ b/packages/insomnia/src/routes/git-credentials.$id.related-projects.tsx @@ -1,6 +1,7 @@ +import type { Organization } from 'insomnia-api'; import { href } from 'react-router'; -import { services } from '~/insomnia-data'; +import { models, services } from '~/insomnia-data'; import { createFetcherLoadHook } from '~/utils/router'; import type { Route } from './+types/git-credentials.$id.related-projects'; @@ -14,8 +15,17 @@ export async function clientLoader({ params }: Route.ClientLoaderArgs) { const relatedProjects = await services.project.getAllByGitRepositoryIds(gitRepositoryIds); + const { accountId } = await services.userSession.getOrCreate(); + const organizations = JSON.parse(localStorage.getItem(`${accountId}:organizations`) || '[]') as Organization[]; + const currentUserOrganizationIds = new Set([ + ...organizations.map(o => o.id), + models.organization.SCRATCHPAD_ORGANIZATION_ID, + ]); + + const currentUserProjects = relatedProjects.filter(p => currentUserOrganizationIds.has(p.parentId)); + return { - projects: relatedProjects, + projects: currentUserProjects, }; }