feat: move session sharing and collab rooms into a plugin (B12)

This commit is contained in:
LukeGus committed 2026-09-23 23:42:46 -05:00
1 parent 791d8656a1
commit a276f6898c
207 files changed
+35771 -11072

No files matched your search

@@ -0,0 +1,107 @@
/**
* Moves session sharing's two settings into the session-sharing plugin:
* the instance-wide switch (settings.session_sharing_globally_enabled) into
* its admin setting, and ssh_data.allow_session_sharing into its host setting.
*
* Idempotent: nothing is written where the plugin already has a row, so it is
* safe on every boot. Both default to on, so only a switch that was turned off
* needs a row. The legacy settings row is left in place for a release.
*/
import { sql } from "drizzle-orm";
import { databaseLogger } from "../logger.js";
import { getDb } from "../../database/db/index.js";
import {
createCurrentPluginSettingsRepository,
createCurrentSettingsRepository,
} from "../../database/repositories/factory.js";
const PLUGIN_ID = "session-sharing";
const LEGACY_GLOBAL_KEY = "session_sharing_globally_enabled";
export interface SessionSharingSettingsMigrationResult {
movedGlobal: boolean;
movedHosts: number;
skipped: number;
}
interface LegacyHostRow {
id: number;
}
export async function runSessionSharingSettingsMigration(): Promise<SessionSharingSettingsMigrationResult> {
const result: SessionSharingSettingsMigrationResult = {
movedGlobal: false,
movedHosts: 0,
skipped: 0,
};
try {
const pluginSettings = createCurrentPluginSettingsRepository();
const legacy =
await createCurrentSettingsRepository().get(LEGACY_GLOBAL_KEY);
if (legacy === "false") {
const existing = await pluginSettings.get(
PLUGIN_ID,
"admin",
null,
"globallyEnabled",
);
if (existing && existing.value !== null) {
result.skipped++;
} else {
await pluginSettings.set(
PLUGIN_ID,
"admin",
null,
"globallyEnabled",
JSON.stringify(false),
);
result.movedGlobal = true;
}
}
// Raw SQL, so this keeps working once schema.ts stops declaring the column.
const rows = await getDb().all<LegacyHostRow>(sql`
SELECT id FROM ssh_data WHERE allow_session_sharing = 0
`);
for (const row of rows) {
const scopeId = String(row.id);
const existing = await pluginSettings.get(
PLUGIN_ID,
"host",
scopeId,
"allowSessionSharing",
);
if (existing && existing.value !== null) {
result.skipped++;
continue;
}
await pluginSettings.set(
PLUGIN_ID,
"host",
scopeId,
"allowSessionSharing",
JSON.stringify(false),
);
result.movedHosts++;
}
if (result.movedGlobal || result.movedHosts > 0) {
databaseLogger.info("Moved session sharing settings into the plugin", {
operation: "session_sharing_settings_migration",
movedGlobal: result.movedGlobal,
movedHosts: result.movedHosts,
});
}
} catch (error) {
// Never stops the backend. Sharing then stays on, the plugin's default.
databaseLogger.warn("Session sharing settings migration failed", {
operation: "session_sharing_settings_migration",
error: error instanceof Error ? error.message : String(error),
});
}
return result;
}
+5 -1
View File
@@ -145,7 +145,11 @@ const swaggerOptions: SwaggerJSDocOptions = {
},
{
name: "Session Sharing",
description: "Live terminal session collaboration",
description: "Share live sessions by link or with another user",
},
{
name: "Collab",
description: "Collaboration rooms that present a live session",
},
{
name: "Session Logs",