Skip to content

refactor: move organization to service layer#9973

Open
xiaodemen wants to merge 1 commit into
developfrom
refactor/organization
Open

refactor: move organization to service layer#9973
xiaodemen wants to merge 1 commit into
developfrom
refactor/organization

Conversation

@xiaodemen
Copy link
Copy Markdown
Contributor

@xiaodemen xiaodemen commented May 28, 2026

INS-2682

  • The domain main logic should be in the service
  • Action reuse functions can be moved to common

Copilot AI review requested due to automatic review settings May 28, 2026 03:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors organization and project migration/sync logic out of UI utilities and into common/service layers, aligning organization-related behavior with the data service architecture.

Changes:

  • Replaces ~/ui/organization-utils imports with ~/common/organization.
  • Moves project migration, cloud project sync, and workspace commit/push helpers into insomnia-data services.
  • Removes old UI/sync migration utility modules and updates route callers to use service methods.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/insomnia/src/ui/organization-utils.ts Removes the old UI organization utility module.
packages/insomnia/src/sync/vcs/migrate-projects-into-organization.ts Removes the old migration helper module.
packages/insomnia/src/sync/vcs/initialize-backend-project.ts Delegates snapshot creation to workspace services and renames push org parameter.
packages/insomnia/src/common/organization.ts Adds common organization sync exports and project sync wrapper.
packages/insomnia/src/insomnia-data/node-src/services/project.ts Adds project migration, backend project sync, local project push, and lookup service methods.
packages/insomnia/src/insomnia-data/node-src/services/workspace.ts Adds workspace lookup, commit, commit-and-push, and git metadata helpers.
packages/insomnia/src/insomnia-data/node-src/services/vcs.ts Adds shared VCS-related service types.
packages/insomnia/src/insomnia-data/node-src/services/organization.ts Adds organization scratchpad check and project sync service wrapper.
packages/insomnia/src/routes/trial.start.tsx Inlines current plan sync after trial start.
packages/insomnia/src/routes/organization.sync.tsx Updates organization sync import.
packages/insomnia/src/routes/organization.sync-organizations-and-projects.tsx Uses service-layer migration and project lookup.
packages/insomnia/src/routes/organization.$organizationId.sync-projects.tsx Updates project sync import.
packages/insomnia/src/routes/organization.$organizationId.storage-rules.tsx Updates storage rule import.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.tsx Updates storage rules constant import.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.tsx Updates storage rules constant import.
packages/insomnia/src/routes/organization.$organizationId.project.$projectId._index.tsx Updates storage rules constant import.
packages/insomnia/src/routes/organization.$organizationId.project._index.tsx Updates storage rules constant import.
packages/insomnia/src/routes/organization.$organizationId._index.tsx Updates project sync import.
packages/insomnia/src/routes/organization._index.tsx Uses service-layer migration.
packages/insomnia/src/routes/onboarding.migrate.tsx Uses service-layer migration detection.
packages/insomnia/src/ui/components/dropdowns/git-project-sync-dropdown.tsx Updates storage rules constant import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +255 to +268
export async function migrateProjectsUnderOrganization(orgId: string, preferredProjectType: string | null) {
if (await hasProjectsToMigrate()) {
await migrateProjectsIntoOrganization(orgId);

if (preferredProjectType === 'remote') {
const localProjects = await getLocalProjectsOfOrg(orgId);

// If any of those fail projects will still be under the organization as local projects
for (const project of localProjects) {
try {
await pushLocalProject({
project,
organizationId: orgId,
vcs: window.main.sync,
Comment on lines +89 to +95
await commitAll({ workspace, vcs, message });
// Mark for pushing to the active project
await updateMetaByParentId(workspace._id, { pushSnapshotOnInitialize: true });
const hasProject = await vcs.hasBackendProject();
if (projectId === workspace.parentId && hasProject && projectRemoteId) {
await updateMetaByParentId(workspace._id, { pushSnapshotOnInitialize: false }); // after below?
await vcs.push({ teamId: orgId, teamProjectId: projectRemoteId });
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

✅ Circular References Report

Generated at: 2026-05-28T06:27:22.165Z
Status: ✅ NO CHANGE

Summary

Metric Base (develop) PR Change
Total Circular References 18 18 0 (0.00%)
Click to view all circular references in PR (18)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts -> insomnia/src/scripting/require-interceptor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/concurrency.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts -> insomnia/src/templating/index.ts -> insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/store.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/misc.ts
insomnia/src/templating/base-extension-worker.ts -> insomnia/src/templating/worker.ts
insomnia/src/templating/index.ts -> insomnia/src/templating/base-extension.ts
insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/templating/types.ts -> insomnia/src/templating/utils.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx
Click to view all circular references in base branch (18)
insomnia-inso/src/db/models/types.ts -> insomnia-inso/src/db/types.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/cancellation.ts -> insomnia/src/script-executor.ts -> insomnia/src/scripting/require-interceptor.ts
insomnia-scripting-environment/src/objects/index.ts -> insomnia-scripting-environment/src/objects/collection.ts -> insomnia-scripting-environment/src/objects/response.ts -> insomnia/src/network/network.ts -> insomnia/src/network/concurrency.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts
insomnia/src/network/network.ts -> insomnia/src/common/render.ts -> insomnia/src/templating/index.ts -> insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/context/app.ts -> insomnia/src/templating/types.ts -> insomnia/src/plugins/context/store.ts
insomnia/src/plugins/index.ts -> insomnia/src/plugins/misc.ts
insomnia/src/templating/base-extension-worker.ts -> insomnia/src/templating/worker.ts
insomnia/src/templating/index.ts -> insomnia/src/templating/base-extension.ts
insomnia/src/templating/types.ts -> insomnia/src/plugins/context/network.ts
insomnia/src/templating/types.ts -> insomnia/src/templating/utils.ts
insomnia/src/ui/components/settings/import-export.tsx -> insomnia/src/ui/components/modals/export-requests-modal.tsx
insomnia/src/ui/components/tabs/tab-list.tsx -> insomnia/src/ui/components/tabs/tab.tsx
insomnia/src/ui/components/templating/tag-editor-arg-sub-form.tsx -> insomnia/src/ui/components/templating/external-vault/external-vault-form.tsx
insomnia/src/ui/components/viewers/response-viewer.tsx -> insomnia/src/ui/components/viewers/response-multipart-viewer.tsx

Analysis

No Change: This PR does not introduce or remove any circular references.


This report was generated automatically by comparing against the develop branch.

@xiaodemen xiaodemen force-pushed the refactor/organization branch from 62507fa to d943b0b Compare May 28, 2026 05:23
@xiaodemen xiaodemen requested review from ZxBing0066 and cwangsmv May 28, 2026 06:13
@xiaodemen xiaodemen force-pushed the refactor/organization branch from d943b0b to 0062ec4 Compare May 28, 2026 06:18
@xiaodemen xiaodemen force-pushed the refactor/organization branch from 0062ec4 to dba4640 Compare May 28, 2026 06:20
vcs: SyncVCSLike;
message: string;
}) {
if (!vcs.hasBackendProject()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!vcs.hasBackendProject()) {
if (!(await vcs.hasBackendProject())) {

message: string;
project: Project;
}) {
if (!vcs.hasBackendProject()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!vcs.hasBackendProject()) {
if (!(await vcs.hasBackendProject())) {

Comment on lines +48 to +54
export interface SyncVCSLike {
hasBackendProject: () => boolean | Promise<boolean>;
push: (options: { teamId: string; teamProjectId: string }) => Promise<void>;
stage: (stageEntries: StageEntry[]) => Promise<Stage>;
status: (candidates: StatusCandidate[]) => Promise<Status>;
switchAndCreateBackendProjectIfNotExist: (rootDocumentId: string, name: string) => Promise<void>;
takeSnapshot: (name: string) => Promise<void>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicate with packages/insomnia/src/sync/vcs/initialize-backend-project.ts#L6-L13


export async function syncProjectsOfOrg(organizationId: string) {
const user = await userSessionService.get();
const teamProjects = await getAllTeamProjects(organizationId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getAllTeamProjects is only used here. Maybe it's unnecessary to extract as a service at this moment. As well as syncProjectsWithBackend.

const user = await userSessionService.get();
const teamProjects = await getAllTeamProjects(organizationId);
// ensure we don't sync projects in the wrong place
if (Array.isArray(teamProjects) && user.id && !isScratchpad(organizationId)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can check scratch and user id before calling getAllTeamProjects. It introduce unnecessary api calls.

});
}

export async function pushLocalProject({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is only used in this file, shouldn't be exported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants