diff --git a/addons/api/addon/handlers/sqlite-handler.js b/addons/api/addon/handlers/sqlite-handler.js index 01a361699..1456076ad 100644 --- a/addons/api/addon/handlers/sqlite-handler.js +++ b/addons/api/addon/handlers/sqlite-handler.js @@ -11,6 +11,10 @@ import { typeOf } from '@ember/utils'; import { hashCode } from '../utils/hash-code'; import { generateSQLExpressions } from '../utils/sqlite-query'; +const isISODateString = (str) => + typeOf(str) === 'string' && + /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z?$/.test(str); + export default class SqliteHandler { @service sqlite; @@ -138,7 +142,13 @@ export default class SqliteHandler { }); console.timeLog(`SQLite fetch ${type}`, 'count'); - const results = rows.map((item) => JSON.parse(item.data)); + const results = rows.map((item) => + JSON.parse(item.data, (key, value) => + // Reviver function to convert any ISO strings back to date objects + // as we had to initially convert them to strings when stored in SQLite + isISODateString(value) ? new Date(value) : value, + ), + ); // If we are not pushing to the store, use the raw data with id property const records = pushToStore diff --git a/addons/api/addon/services/sqlite.js b/addons/api/addon/services/sqlite.js index 07a292530..1567d5664 100644 --- a/addons/api/addon/services/sqlite.js +++ b/addons/api/addon/services/sqlite.js @@ -83,6 +83,22 @@ export const modelMapping = { scope_id: 'scope.scope_id', created_time: 'created_time', }, + 'session-recording': { + id: 'id', + type: 'type', + state: 'state', + start_time: 'start_time', + end_time: 'end_time', + duration: 'duration', + scope_id: 'scope.scope_id', + user_id: 'create_time_values.user.id', + user_name: 'create_time_values.user.name', + target_id: 'create_time_values.target.id', + target_name: 'create_time_values.target.name', + target_scope_id: 'create_time_values.target.scope.id', + target_scope_name: 'create_time_values.target.scope.name', + created_time: 'created_time', + }, }; // A list of tables that we support searching using FTS5 in SQLite. @@ -96,6 +112,7 @@ export const searchTables = new Set([ 'scope', 'auth-method', 'host-catalog', + 'session-recording', ]); export default class SqliteDbService extends Service { diff --git a/addons/api/addon/workers/utils/schema.js b/addons/api/addon/workers/utils/schema.js index 4603c10cf..501d887cb 100644 --- a/addons/api/addon/workers/utils/schema.js +++ b/addons/api/addon/workers/utils/schema.js @@ -337,6 +337,57 @@ CREATE TRIGGER IF NOT EXISTS host_catalog_ad AFTER DELETE ON host_catalog BEGIN VALUES('delete', old.rowid, old.id, old.type, old.name, old.description, old.plugin_name, old.scope_id, old.created_time); END;`; +const createSessionRecordingTables = ` +CREATE TABLE IF NOT EXISTS session_recording ( + id TEXT NOT NULL PRIMARY KEY, + type TEXT NOT NULL, + state TEXT, + start_time TEXT, + end_time TEXT, + duration TEXT, + scope_id TEXT NOT NULL, + user_id TEXT, + user_name TEXT, + target_id TEXT, + target_name TEXT, + target_scope_id TEXT, + target_scope_name TEXT, + created_time TEXT NOT NULL, + data TEXT NOT NULL +); +CREATE INDEX IF NOT EXISTS idx_session_recording_created_time ON session_recording(created_time DESC); + +CREATE VIRTUAL TABLE IF NOT EXISTS session_recording_fts USING fts5( + id, + type, + state, + start_time, + end_time, + duration, + scope_id, + user_id, + user_name, + target_id, + target_name, + target_scope_id, + target_scope_name, + created_time, + content='', +); + +CREATE TRIGGER IF NOT EXISTS session_recording_ai AFTER INSERT ON session_recording BEGIN + INSERT INTO session_recording_fts( + id, type, state, start_time, end_time, duration, scope_id, user_id, user_name, target_id, target_name, target_scope_id, target_scope_name, created_time + ) VALUES ( + new.id, new.type, new.state, new.start_time, new.end_time, new.duration, new.scope_id, new.user_id, new.user_name, new.target_id, new.target_name, new.target_scope_id, new.target_scope_name, new.created_time + ); +END; + +CREATE TRIGGER IF NOT EXISTS session_recording_ad AFTER DELETE ON session_recording BEGIN + INSERT INTO session_recording_fts(session_recording_fts, rowid, id, type, state, start_time, end_time, duration, scope_id, user_id, user_name, target_id, target_name, target_scope_id, target_scope_name, created_time) + VALUES('delete', old.rowid, old.id, old.type, old.state, old.start_time, old.end_time, old.duration, old.scope_id, old.user_id, old.user_name, old.target_id, old.target_name, old.target_scope_id, old.target_scope_name, old.created_time); +END;`; + export const CREATE_TABLES = (version) => ` BEGIN; @@ -356,6 +407,17 @@ ${createCredentialStoreTables} ${createScopeTables} ${createAuthMethodTables} ${createHostCatalogTables} +${createSessionRecordingTables} + +CREATE TABLE IF NOT EXISTS "group" ( + id TEXT NOT NULL PRIMARY KEY, + name TEXT, + description TEXT, + scope_id TEXT NOT NULL, + created_time TEXT NOT NULL, + data TEXT NOT NULL +); +CREATE INDEX IF NOT EXISTS idx_group_scope_id_created_time ON "group"(scope_id, created_time DESC); COMMIT;`; diff --git a/ui/admin/app/routes/scopes/scope/session-recordings/index.js b/ui/admin/app/routes/scopes/scope/session-recordings/index.js index 00a7d73dd..dd9f3f15d 100644 --- a/ui/admin/app/routes/scopes/scope/session-recordings/index.js +++ b/ui/admin/app/routes/scopes/scope/session-recordings/index.js @@ -96,19 +96,19 @@ export default class ScopesScopeSessionRecordingsIndexRoute extends Route { let doStorageBucketsExist = false; const filters = { created_time: [], - 'create_time_values.user.id': [], - 'create_time_values.target.scope.id': [], - 'create_time_values.target.id': [], + user_id: [], + target_scope_id: [], + target_id: [], }; if (time) filters.created_time.push({ gte: new Date(time) }); users.forEach((user) => { - filters['create_time_values.user.id'].push({ equals: user }); + filters['user_id'].push({ equals: user }); }); scopes.forEach((scope) => { - filters['create_time_values.target.scope.id'].push({ equals: scope }); + filters['target_scope_id'].push({ equals: scope }); }); targets.forEach((target) => { - filters['create_time_values.target.id'].push({ equals: target }); + filters['target_id'].push({ equals: target }); }); const stateMap = {