From 82a8aab1e9a2985e9687d1ba1b711221f8869257 Mon Sep 17 00:00:00 2001 From: manu Date: Fri, 5 Jul 2024 17:24:03 +0200 Subject: [PATCH 1/2] Add feature to delete and resync playbooks A new feature called "deletePlaybooksModelAndResync" has been added to the advanced settings. This allows users to delete all playbooks and then resync again. Modifications were made to server routing, client services, and the Advanced Settings UI component to accommodate this change. --- client/src/components/Template/Title.tsx | 1 + .../Settings/components/AdvancedSettings.tsx | 38 ++++++++++++++++--- client/src/services/rest/settings.ts | 11 ++++++ server/src/routes/settings.ts | 3 +- server/src/services/settings/advanced.ts | 11 ++++++ 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/client/src/components/Template/Title.tsx b/client/src/components/Template/Title.tsx index 10c2c1bf..d23108b4 100644 --- a/client/src/components/Template/Title.tsx +++ b/client/src/components/Template/Title.tsx @@ -20,6 +20,7 @@ export enum SettingsSubTitleColors { SERVER = '#8e7d50', GIT = '#336048', LOCAL = '#4b4a4a', + DEBUG = '#b614b6', } export type PageContainerTitleProps = { diff --git a/client/src/pages/Admin/Settings/components/AdvancedSettings.tsx b/client/src/pages/Admin/Settings/components/AdvancedSettings.tsx index 7a8a52c0..86d2c8d9 100644 --- a/client/src/pages/Admin/Settings/components/AdvancedSettings.tsx +++ b/client/src/pages/Admin/Settings/components/AdvancedSettings.tsx @@ -8,14 +8,11 @@ import { deleteAnsibleLogs, deleteContainerStats, deleteDeviceStats, + deletePlaybooksAndResync, deleteServerLogs, postRestartServer, } from '@/services/rest/settings'; -import { - InfoCircleFilled, - RedoOutlined, - TableOutlined, -} from '@ant-design/icons'; +import { BugFilled, InfoCircleFilled, RedoOutlined } from '@ant-design/icons'; import { Button, Card, Flex, Popover, Space, Typography } from 'antd'; import { DeleteOutline } from 'antd-mobile-icons'; import React from 'react'; @@ -161,6 +158,37 @@ const AdvancedSettings: React.FC = () => { + } + /> + } + > + + + + {' '} + + + {' '} + Playbooks + {' '} + + + + + ); }; diff --git a/client/src/services/rest/settings.ts b/client/src/services/rest/settings.ts index 2a3ebc58..c1852d99 100644 --- a/client/src/services/rest/settings.ts +++ b/client/src/services/rest/settings.ts @@ -88,6 +88,17 @@ export async function deleteDeviceStats(options?: Record) { }); } +export async function deletePlaybooksAndResync(options?: Record) { + return request( + `/api/settings/advanced/playbooks-and-resync`, + { + method: 'DELETE', + ...{}, + ...(options || {}), + }, + ); +} + export async function postContainerStatsSettings( type: string, value: number, diff --git a/server/src/routes/settings.ts b/server/src/routes/settings.ts index 8db41508..b2f680bd 100644 --- a/server/src/routes/settings.ts +++ b/server/src/routes/settings.ts @@ -15,6 +15,7 @@ import { deleteContainerStats, deleteDeviceStats, deleteLogs, + deletePlaybooksModelAndResync, postRestartServer, } from '../services/settings/advanced'; @@ -36,5 +37,5 @@ router.delete('/advanced/logs', deleteLogs); router.delete('/advanced/ansible-logs', deleteAnsibleLogs); router.delete('/advanced/device-stats', deleteDeviceStats); router.delete('/advanced/container-stats', deleteContainerStats); - +router.delete('/advanced/playbooks-and-resync', deletePlaybooksModelAndResync); export default router; diff --git a/server/src/services/settings/advanced.ts b/server/src/services/settings/advanced.ts index 55572794..02697c93 100644 --- a/server/src/services/settings/advanced.ts +++ b/server/src/services/settings/advanced.ts @@ -1,10 +1,14 @@ +import { Promise } from 'mongoose'; +import { res } from 'pino-std-serializers'; import { SuccessResponse } from '../../core/api/ApiResponse'; +import { PlaybookModel } from '../../data/database/model/Playbook'; import AnsibleLogsRepo from '../../data/database/repository/AnsibleLogsRepo'; import ContainerStatsRepo from '../../data/database/repository/ContainerStatsRepo'; import DeviceStatRepo from '../../data/database/repository/DeviceStatRepo'; import LogsRepo from '../../data/database/repository/LogsRepo'; import asyncHandler from '../../helpers/AsyncHandler'; import { restart } from '../../index'; +import PlaybooksRepositoryEngine from '../../integrations/playbooks-repository/PlaybooksRepositoryEngine'; export const postRestartServer = asyncHandler(async (req, res) => { await restart(); @@ -29,3 +33,10 @@ export const deleteDeviceStats = asyncHandler(async (req, res) => { await DeviceStatRepo.deleteAll(); new SuccessResponse('Device stats Purged Successfully').send(res); }); + +export const deletePlaybooksModelAndResync = asyncHandler(async (req, res) => { + await PlaybookModel.db.collection('playbooks').drop(); + await PlaybooksRepositoryEngine.registerRepositories(); + await PlaybooksRepositoryEngine.syncAllRegistered(); + new SuccessResponse('All data purged successfully').send(res); +}); From 77841cb3846e75590f3fb404aca2ac1651acc152 Mon Sep 17 00:00:00 2001 From: manu Date: Fri, 5 Jul 2024 17:25:44 +0200 Subject: [PATCH 2/2] Refactor reference to playbook collection name In the advanced settings service, the hardcoded name of the 'playbooks' collection has been replaced with a variable. This variable, PlaybookCollectionName, is imported from the Playbook model. This change simplifies the update process and avoids potential discrepancies in collection naming across the server code. --- server/src/services/settings/advanced.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/src/services/settings/advanced.ts b/server/src/services/settings/advanced.ts index 02697c93..c05cc8fe 100644 --- a/server/src/services/settings/advanced.ts +++ b/server/src/services/settings/advanced.ts @@ -1,7 +1,8 @@ -import { Promise } from 'mongoose'; -import { res } from 'pino-std-serializers'; import { SuccessResponse } from '../../core/api/ApiResponse'; -import { PlaybookModel } from '../../data/database/model/Playbook'; +import { + COLLECTION_NAME as PlaybookCollectionName, + PlaybookModel, +} from '../../data/database/model/Playbook'; import AnsibleLogsRepo from '../../data/database/repository/AnsibleLogsRepo'; import ContainerStatsRepo from '../../data/database/repository/ContainerStatsRepo'; import DeviceStatRepo from '../../data/database/repository/DeviceStatRepo'; @@ -35,7 +36,7 @@ export const deleteDeviceStats = asyncHandler(async (req, res) => { }); export const deletePlaybooksModelAndResync = asyncHandler(async (req, res) => { - await PlaybookModel.db.collection('playbooks').drop(); + await PlaybookModel.db.collection(PlaybookCollectionName).drop(); await PlaybooksRepositoryEngine.registerRepositories(); await PlaybooksRepositoryEngine.syncAllRegistered(); new SuccessResponse('All data purged successfully').send(res);