diff --git a/backend/src/db/entity-migrations/v3.0-initial-setup.ts b/backend/src/db/entity-migrations/v3.0-initial-setup.ts index 340ade663d..9771e2adcf 100644 --- a/backend/src/db/entity-migrations/v3.0-initial-setup.ts +++ b/backend/src/db/entity-migrations/v3.0-initial-setup.ts @@ -2,7 +2,6 @@ import { Knex } from 'knex'; import { LOG_LEVELS } from '../../../../shared/model/engine.model'; import { ENGINES_TABLE } from '../../repository/engine.repository'; import { USERS_TABLE } from '../../repository/user.repository'; -import { EXTERNAL_SOURCES_TABLE } from '../../repository/external-source.repository'; import { IP_FILTERS_TABLE } from '../../repository/ip-filter.repository'; import { SCAN_MODES_TABLE } from '../../repository/scan-mode.repository'; import { HISTORY_QUERIES_TABLE } from '../../repository/history-query.repository'; @@ -11,7 +10,10 @@ import { SOUTH_CONNECTORS_TABLE } from '../../repository/south-connector.reposit import { SOUTH_ITEMS_TABLE } from '../../repository/south-item.repository'; import { NORTH_CONNECTORS_TABLE } from '../../repository/north-connector.repository'; import CreateTableBuilder = Knex.CreateTableBuilder; -import { EXTERNAL_SUBSCRIPTION_TABLE, SUBSCRIPTION_TABLE } from '../../repository/subscription.repository'; +import { SUBSCRIPTION_TABLE } from '../../repository/subscription.repository'; + +const EXTERNAL_SOURCES_TABLE = 'external_sources'; +const EXTERNAL_SUBSCRIPTION_TABLE = 'external_subscription'; export async function up(knex: Knex): Promise { await createEnginesTable(knex); diff --git a/backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.ts b/backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.ts index 90fd1ac9be..25500fb28a 100644 --- a/backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.ts +++ b/backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.ts @@ -6,9 +6,13 @@ import { filesExists } from '../../service/utils'; import fs from 'node:fs/promises'; import { HISTORY_ITEMS_TABLE } from '../../repository/history-query-item.repository'; +const EXTERNAL_SOURCES_TABLE = 'external_sources'; +const EXTERNAL_SUBSCRIPTION_TABLE = 'external_subscription'; + export async function up(knex: Knex): Promise { await removeNorthOIBusConnectors(knex); await removeNorthOIBusHistoryQueries(knex); + await removeExternalSubscriptions(knex); } async function removeNorthOIBusConnectors(knex: Knex): Promise { @@ -39,4 +43,9 @@ async function removeNorthOIBusHistoryQueries(knex: Knex): Promise { await knex(HISTORY_QUERIES_TABLE).delete().where('north_type', 'oibus'); } +async function removeExternalSubscriptions(knex: Knex): Promise { + await knex.schema.dropTableIfExists(EXTERNAL_SUBSCRIPTION_TABLE); + await knex.schema.dropTableIfExists(EXTERNAL_SOURCES_TABLE); +} + export async function down(): Promise {} diff --git a/backend/src/north/north-connector.spec.ts b/backend/src/north/north-connector.spec.ts index d7854d6928..4cf6e1e14a 100644 --- a/backend/src/north/north-connector.spec.ts +++ b/backend/src/north/north-connector.spec.ts @@ -353,36 +353,18 @@ describe('NorthConnector enabled', () => { expect(north.isSubscribed('southId')).toBeTruthy(); }); - it('should check if North is subscribed to all external sources', async () => { - (repositoryService.subscriptionRepository.getExternalNorthSubscriptions as jest.Mock).mockReturnValue([]); - await north.start(); - expect(north.isSubscribedToExternalSource('externalSourceId')).toBeTruthy(); - }); - it('should check if North is subscribed to South', async () => { (repositoryService.subscriptionRepository.getNorthSubscriptions as jest.Mock).mockReturnValue(['southId']); await north.start(); expect(north.isSubscribed('southId')).toBeTruthy(); }); - it('should check if North is subscribed to external source', async () => { - (repositoryService.subscriptionRepository.getExternalNorthSubscriptions as jest.Mock).mockReturnValue(['externalSourceId']); - await north.start(); - expect(north.isSubscribedToExternalSource('externalSourceId')).toBeTruthy(); - }); - it('should check if North is not subscribed to South', async () => { (repositoryService.subscriptionRepository.getNorthSubscriptions as jest.Mock).mockReturnValue(['southId1']); await north.start(); expect(north.isSubscribed('southId2')).toBeFalsy(); }); - it('should check if North is not subscribed to external source', async () => { - (repositoryService.subscriptionRepository.getExternalNorthSubscriptions as jest.Mock).mockReturnValue(['externalSourceId1']); - await north.start(); - expect(north.isSubscribedToExternalSource('externalSourceId2')).toBeFalsy(); - }); - it('should get error files', async () => { const result = await north.getErrorFiles('2022-11-11T11:11:11.111Z', '2022-11-12T11:11:11.111Z', 'file'); expect(result).toEqual([ diff --git a/backend/src/north/north-connector.ts b/backend/src/north/north-connector.ts index b2bda72551..fcfa3c246c 100644 --- a/backend/src/north/north-connector.ts +++ b/backend/src/north/north-connector.ts @@ -11,7 +11,7 @@ import { EventEmitter } from 'node:events'; import { ScanModeDTO } from '../../../shared/model/scan-mode.model'; import DeferredPromise from '../service/deferred-promise'; import { OIBusContent, OIBusError, OIBusRawContent, OIBusTimeValue, OIBusTimeValueContent } from '../../../shared/model/engine.model'; -import { ExternalSubscriptionDTO, SubscriptionDTO } from '../../../shared/model/subscription.model'; +import { SubscriptionDTO } from '../../../shared/model/subscription.model'; import { DateTime } from 'luxon'; import { PassThrough } from 'node:stream'; import { ReadStream } from 'node:fs'; @@ -45,7 +45,6 @@ export default class NorthConnector { private fileCacheService: FileCacheService; protected metricsService: NorthConnectorMetricsService | null = null; private subscribedTo: Array = []; - private subscribedToExternalSources: Array = []; private cacheSize = 0; private fileBeingSent: string | null = null; @@ -142,7 +141,6 @@ export default class NorthConnector { cacheSize: this.cacheSize }); this.subscribedTo = this.repositoryService.subscriptionRepository.getNorthSubscriptions(this.connector.id); - this.subscribedToExternalSources = this.repositoryService.subscriptionRepository.getExternalNorthSubscriptions(this.connector.id); } await this.valueCacheService.start(); await this.fileCacheService.start(); @@ -394,14 +392,6 @@ export default class NorthConnector { return this.subscribedTo.length === 0 || this.subscribedTo.includes(southId); } - /** - * Check whether the North is subscribed to an external source. - * If subscribedToExternalSources is not defined or an empty array, the subscription is true. - */ - isSubscribedToExternalSource(externalSourceId: string): boolean { - return this.subscribedToExternalSources.length === 0 || this.subscribedToExternalSources.includes(externalSourceId); - } - /** * Check appropriate caches emptiness */ diff --git a/backend/src/repository/external-source.repository.spec.ts b/backend/src/repository/external-source.repository.spec.ts deleted file mode 100644 index aa01335d42..0000000000 --- a/backend/src/repository/external-source.repository.spec.ts +++ /dev/null @@ -1,100 +0,0 @@ -import SqliteDatabaseMock, { all, get, run } from '../tests/__mocks__/database.mock'; -import { generateRandomId } from '../service/utils'; -import ExternalSourceRepository from './external-source.repository'; -import { ExternalSourceCommandDTO, ExternalSourceDTO } from '../../../shared/model/external-sources.model'; -import { Database } from 'better-sqlite3'; - -jest.mock('../service/utils', () => ({ - generateRandomId: jest.fn(() => '123456') -})); - -let database: Database; -let repository: ExternalSourceRepository; -describe('External source repository', () => { - beforeEach(() => { - jest.clearAllMocks(); - database = new SqliteDatabaseMock(); - database.prepare = jest.fn().mockReturnValue({ - run, - get, - all - }); - repository = new ExternalSourceRepository(database); - }); - - it('should properly get all external sources', () => { - const expectedValue: Array = [ - { - id: 'id1', - reference: 'ref1', - description: 'my first external source' - }, - { - id: 'id2', - reference: 'ref2', - description: 'my second external source' - } - ]; - all.mockReturnValueOnce(expectedValue); - const externalSources = repository.getExternalSources(); - expect(database.prepare).toHaveBeenCalledWith('SELECT id, reference, description FROM external_sources;'); - expect(externalSources).toEqual(expectedValue); - }); - - it('should properly get an external source', () => { - const expectedValue: ExternalSourceDTO = { - id: 'id1', - reference: 'ref1', - description: 'my first external source' - }; - get.mockReturnValueOnce(expectedValue); - const externalSource = repository.getExternalSource('id1'); - expect(database.prepare).toHaveBeenCalledWith('SELECT id, reference, description FROM external_sources WHERE id = ?;'); - expect(get).toHaveBeenCalledWith('id1'); - expect(externalSource).toEqual(expectedValue); - }); - - it('should properly get an external source by reference', () => { - const expectedValue: ExternalSourceDTO = { - id: 'id1', - reference: 'ref1', - description: 'my first external source' - }; - get.mockReturnValueOnce(expectedValue); - const externalSource = repository.findExternalSourceByReference('ref1'); - expect(database.prepare).toHaveBeenCalledWith('SELECT id, reference, description FROM external_sources WHERE reference = ?;'); - expect(get).toHaveBeenCalledWith('ref1'); - expect(externalSource).toEqual(expectedValue); - }); - - it('should create an external source', () => { - run.mockReturnValueOnce({ lastInsertRowid: 1 }); - - const command: ExternalSourceCommandDTO = { - reference: 'ref1', - description: 'my first external source' - }; - repository.createExternalSource(command); - expect(generateRandomId).toHaveBeenCalledWith(6); - expect(database.prepare).toHaveBeenCalledWith('INSERT INTO external_sources (id, reference, description) VALUES (?, ?, ?);'); - expect(run).toHaveBeenCalledWith('123456', command.reference, command.description); - - expect(database.prepare).toHaveBeenCalledWith('SELECT id, reference, description FROM external_sources WHERE ROWID = ?;'); - }); - - it('should update an external source', () => { - const command: ExternalSourceCommandDTO = { - reference: 'ref1', - description: 'my first external source' - }; - repository.updateExternalSource('id1', command); - expect(database.prepare).toHaveBeenCalledWith('UPDATE external_sources SET reference = ?, description = ? WHERE id = ?;'); - expect(run).toHaveBeenCalledWith(command.reference, command.description, 'id1'); - }); - - it('should delete an external source', () => { - repository.deleteExternalSource('id1'); - expect(database.prepare).toHaveBeenCalledWith('DELETE FROM external_sources WHERE id = ?;'); - expect(run).toHaveBeenCalledWith('id1'); - }); -}); diff --git a/backend/src/repository/external-source.repository.ts b/backend/src/repository/external-source.repository.ts deleted file mode 100644 index b403d9cf36..0000000000 --- a/backend/src/repository/external-source.repository.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { generateRandomId } from '../service/utils'; -import { ExternalSourceCommandDTO, ExternalSourceDTO } from '../../../shared/model/external-sources.model'; -import { Database } from 'better-sqlite3'; - -export const EXTERNAL_SOURCES_TABLE = 'external_sources'; - -/** - * Repository used for external sources (remote data source that send values directly to the API) - */ -export default class ExternalSourceRepository { - constructor(private readonly database: Database) {} - - /** - * Retrieve all external sources - */ - getExternalSources(): Array { - const query = `SELECT id, reference, description FROM ${EXTERNAL_SOURCES_TABLE};`; - return this.database.prepare(query).all() as Array; - } - - /** - * Retrieve an external source by its ID - */ - getExternalSource(id: string): ExternalSourceDTO | null { - const query = `SELECT id, reference, description FROM ${EXTERNAL_SOURCES_TABLE} WHERE id = ?;`; - return this.database.prepare(query).get(id) as ExternalSourceDTO | null; - } - - /** - * Retrieve an external source by its reference - */ - findExternalSourceByReference(reference: string): ExternalSourceDTO | null { - const query = `SELECT id, reference, description FROM ${EXTERNAL_SOURCES_TABLE} WHERE reference = ?;`; - return this.database.prepare(query).get(reference) as ExternalSourceDTO | null; - } - - /** - * Create an external source with a random generated ID - */ - createExternalSource(command: ExternalSourceCommandDTO): ExternalSourceDTO { - const id = generateRandomId(6); - const insertQuery = `INSERT INTO ${EXTERNAL_SOURCES_TABLE} (id, reference, description) ` + `VALUES (?, ?, ?);`; - const result = this.database.prepare(insertQuery).run(id, command.reference, command.description); - - const query = `SELECT id, reference, description FROM ${EXTERNAL_SOURCES_TABLE} WHERE ROWID = ?;`; - return this.database.prepare(query).get(result.lastInsertRowid) as ExternalSourceDTO; - } - - /** - * Update an external source by its ID - */ - updateExternalSource(id: string, command: ExternalSourceCommandDTO): void { - const query = `UPDATE ${EXTERNAL_SOURCES_TABLE} SET reference = ?, description = ? WHERE id = ?;`; - this.database.prepare(query).run(command.reference, command.description, id); - } - - /** - * Delete an external source by its ID - */ - deleteExternalSource(id: string): void { - const query = `DELETE FROM ${EXTERNAL_SOURCES_TABLE} WHERE id = ?;`; - this.database.prepare(query).run(id); - } -} diff --git a/backend/src/repository/subscription.repository.spec.ts b/backend/src/repository/subscription.repository.spec.ts index d1de4e15ad..cbadc4a3c9 100644 --- a/backend/src/repository/subscription.repository.spec.ts +++ b/backend/src/repository/subscription.repository.spec.ts @@ -1,7 +1,7 @@ import SubscriptionRepository from './subscription.repository'; -import SqliteDatabaseMock, { run, all, get } from '../tests/__mocks__/database.mock'; +import SqliteDatabaseMock, { all, get, run } from '../tests/__mocks__/database.mock'; import { Database } from 'better-sqlite3'; -import { ExternalSubscriptionDTO, SubscriptionDTO } from '../../../shared/model/subscription.model'; +import { SubscriptionDTO } from '../../../shared/model/subscription.model'; jest.mock('../tests/__mocks__/database.mock'); @@ -29,16 +29,6 @@ describe('Subscription repository', () => { expect(subscriptions).toEqual(expectedValue); }); - it('should properly get all external subscriptions', () => { - const expectedValue: Array = ['external1', 'external2']; - all.mockReturnValueOnce(expectedValue.map(sourceId => ({ externalSourceId: sourceId }))); - const subscriptions = repository.getExternalNorthSubscriptions('north1'); - expect(database.prepare).toHaveBeenCalledWith( - 'SELECT external_source_id AS externalSourceId FROM external_subscription WHERE north_connector_id = ?;' - ); - expect(subscriptions).toEqual(expectedValue); - }); - it('should properly get all subscribed North connectors', () => { const expectedValue = ['north1', 'north2']; all.mockReturnValueOnce(expectedValue.map(northId => ({ northConnectorId: northId }))); @@ -59,16 +49,6 @@ describe('Subscription repository', () => { expect(get).toHaveBeenCalledWith('north1', 'south1'); }); - it('should check an external subscription', () => { - get.mockReturnValueOnce({ externalSourceId: 'external1' }); - - repository.checkExternalNorthSubscription('north1', 'external1'); - expect(database.prepare).toHaveBeenCalledWith( - 'SELECT external_source_id AS externalSourceId FROM external_subscription WHERE north_connector_id = ? AND external_source_id = ?;' - ); - expect(get).toHaveBeenCalledWith('north1', 'external1'); - }); - it('should create a subscription', () => { run.mockReturnValueOnce({ lastInsertRowid: 1 }); @@ -77,39 +57,15 @@ describe('Subscription repository', () => { expect(run).toHaveBeenCalledWith('north1', 'south1'); }); - it('should create an external subscription', () => { - run.mockReturnValueOnce({ lastInsertRowid: 1 }); - - repository.createExternalNorthSubscription('north1', 'external1'); - expect(database.prepare).toHaveBeenCalledWith( - 'INSERT INTO external_subscription (north_connector_id, external_source_id) VALUES (?, ?);' - ); - expect(run).toHaveBeenCalledWith('north1', 'external1'); - }); - it('should delete a subscription', () => { repository.deleteNorthSubscription('north1', 'south1'); expect(database.prepare).toHaveBeenCalledWith('DELETE FROM subscription WHERE north_connector_id = ? AND south_connector_id = ?;'); expect(run).toHaveBeenCalledWith('north1', 'south1'); }); - it('should delete an external subscription', () => { - repository.deleteExternalNorthSubscription('north1', 'external1'); - expect(database.prepare).toHaveBeenCalledWith( - 'DELETE FROM external_subscription WHERE north_connector_id = ? AND external_source_id = ?;' - ); - expect(run).toHaveBeenCalledWith('north1', 'external1'); - }); - it('should delete all North subscriptions', () => { repository.deleteNorthSubscriptions('north1'); expect(database.prepare).toHaveBeenCalledWith('DELETE FROM subscription WHERE north_connector_id = ?;'); expect(run).toHaveBeenCalledWith('north1'); }); - - it('should delete all external North subscriptions', () => { - repository.deleteExternalNorthSubscriptions('north1'); - expect(database.prepare).toHaveBeenCalledWith('DELETE FROM external_subscription WHERE north_connector_id = ?;'); - expect(run).toHaveBeenCalledWith('north1'); - }); }); diff --git a/backend/src/repository/subscription.repository.ts b/backend/src/repository/subscription.repository.ts index 4d118d14ef..797f6f37f9 100644 --- a/backend/src/repository/subscription.repository.ts +++ b/backend/src/repository/subscription.repository.ts @@ -1,8 +1,7 @@ import { Database } from 'better-sqlite3'; -import { ExternalSubscriptionDTO, SubscriptionDTO } from '../../../shared/model/subscription.model'; +import { SubscriptionDTO } from '../../../shared/model/subscription.model'; export const SUBSCRIPTION_TABLE = 'subscription'; -export const EXTERNAL_SUBSCRIPTION_TABLE = 'external_subscription'; /** * Repository used for subscriptions @@ -21,17 +20,6 @@ export default class SubscriptionRepository { .map((row: any) => row.southConnectorId); } - /** - * Retrieve all external subscriptions for a given North connector - */ - getExternalNorthSubscriptions(northId: string): Array { - const query = `SELECT external_source_id AS externalSourceId FROM ${EXTERNAL_SUBSCRIPTION_TABLE} WHERE north_connector_id = ?;`; - return this.database - .prepare(query) - .all(northId) - .map((row: any) => row.externalSourceId); - } - /** * Retrieve all subscribed North connectors for a given South connector */ @@ -51,14 +39,6 @@ export default class SubscriptionRepository { return !!this.database.prepare(query).get(northId, southId); } - /** - * Check whether an external subscription exists for a given North connector - */ - checkExternalNorthSubscription(northId: string, externalSourceId: string): boolean { - const query = `SELECT external_source_id AS externalSourceId FROM ${EXTERNAL_SUBSCRIPTION_TABLE} WHERE north_connector_id = ? AND external_source_id = ?;`; - return !!this.database.prepare(query).get(northId, externalSourceId); - } - /** * Create a subscription for a given North connector */ @@ -67,14 +47,6 @@ export default class SubscriptionRepository { this.database.prepare(query).run(northId, southId); } - /** - * Create an external subscription for a given North connector - */ - createExternalNorthSubscription(northId: string, externalSourceId: string): void { - const query = `INSERT INTO ${EXTERNAL_SUBSCRIPTION_TABLE} (north_connector_id, external_source_id) ` + 'VALUES (?, ?);'; - this.database.prepare(query).run(northId, externalSourceId); - } - /** * Delete a subscription for a given North connector */ @@ -83,14 +55,6 @@ export default class SubscriptionRepository { this.database.prepare(query).run(northId, southId); } - /** - * Delete an external subscription for a given North connector - */ - deleteExternalNorthSubscription(northId: string, externalSourceId: string): void { - const query = `DELETE FROM ${EXTERNAL_SUBSCRIPTION_TABLE} WHERE north_connector_id = ? AND external_source_id = ?;`; - this.database.prepare(query).run(northId, externalSourceId); - } - /** * Delete all subscriptions for a given North connector */ @@ -98,12 +62,4 @@ export default class SubscriptionRepository { const query = `DELETE FROM ${SUBSCRIPTION_TABLE} WHERE north_connector_id = ?;`; this.database.prepare(query).run(northId); } - - /** - * Delete all external subscriptions for a given North connector - */ - deleteExternalNorthSubscriptions(northId: string): void { - const query = `DELETE FROM ${EXTERNAL_SUBSCRIPTION_TABLE} WHERE north_connector_id = ?;`; - this.database.prepare(query).run(northId); - } } diff --git a/backend/src/service/reload.service.spec.ts b/backend/src/service/reload.service.spec.ts index ef8a119f58..3872f0832c 100644 --- a/backend/src/service/reload.service.spec.ts +++ b/backend/src/service/reload.service.spec.ts @@ -576,24 +576,6 @@ describe('reload service', () => { expect(oibusEngine.startNorth).toHaveBeenCalledWith('northId', { id: 'northId', enabled: true }); }); - it('should create external North subscription', async () => { - (repositoryService.northConnectorRepository.getNorthConnector as jest.Mock).mockReturnValue(null); - - await service.onCreateExternalNorthSubscription('northId', 'externalId'); - expect(oibusEngine.stopNorth).toHaveBeenCalledWith('northId'); - expect(repositoryService.subscriptionRepository.createExternalNorthSubscription).toHaveBeenCalledWith('northId', 'externalId'); - expect(oibusEngine.startNorth).not.toHaveBeenCalled(); - }); - - it('should create external North subscription and restart', async () => { - (repositoryService.northConnectorRepository.getNorthConnector as jest.Mock).mockReturnValue({ id: 'northId', enabled: true }); - - await service.onCreateExternalNorthSubscription('northId', 'externalId'); - expect(oibusEngine.stopNorth).toHaveBeenCalledWith('northId'); - expect(repositoryService.subscriptionRepository.createExternalNorthSubscription).toHaveBeenCalledWith('northId', 'externalId'); - expect(oibusEngine.startNorth).toHaveBeenCalledWith('northId', { id: 'northId', enabled: true }); - }); - it('should delete North subscription', async () => { (repositoryService.northConnectorRepository.getNorthConnector as jest.Mock).mockReturnValue(null); @@ -612,24 +594,6 @@ describe('reload service', () => { expect(oibusEngine.startNorth).toHaveBeenCalledWith('northId', { id: 'northId', enabled: true }); }); - it('should delete external North subscription', async () => { - (repositoryService.northConnectorRepository.getNorthConnector as jest.Mock).mockReturnValue(null); - - await service.onDeleteExternalNorthSubscription('northId', 'externalId'); - expect(oibusEngine.stopNorth).toHaveBeenCalledWith('northId'); - expect(repositoryService.subscriptionRepository.deleteExternalNorthSubscription).toHaveBeenCalledWith('northId', 'externalId'); - expect(oibusEngine.startNorth).not.toHaveBeenCalled(); - }); - - it('should delete external North subscription and restart', async () => { - (repositoryService.northConnectorRepository.getNorthConnector as jest.Mock).mockReturnValue({ id: 'northId', enabled: true }); - - await service.onDeleteExternalNorthSubscription('northId', 'externalId'); - expect(oibusEngine.stopNorth).toHaveBeenCalledWith('northId'); - expect(repositoryService.subscriptionRepository.deleteExternalNorthSubscription).toHaveBeenCalledWith('northId', 'externalId'); - expect(oibusEngine.startNorth).toHaveBeenCalledWith('northId', { id: 'northId', enabled: true }); - }); - it('should retrieve error file from north', async () => { await service.getErrorFiles('northId', '2020-02-02T02:02:02.222Z', '2022-02-02T02:02:02.222Z', 'file'); expect(oibusEngine.getErrorFiles).toHaveBeenCalledWith('northId', '2020-02-02T02:02:02.222Z', '2022-02-02T02:02:02.222Z', 'file'); diff --git a/backend/src/service/reload.service.ts b/backend/src/service/reload.service.ts index 76219f99b5..db8dcb9f88 100644 --- a/backend/src/service/reload.service.ts +++ b/backend/src/service/reload.service.ts @@ -286,15 +286,6 @@ export default class ReloadService { } } - async onCreateExternalNorthSubscription(northId: string, externalSourceId: string): Promise { - await this.oibusEngine.stopNorth(northId); - this.repositoryService.subscriptionRepository.createExternalNorthSubscription(northId, externalSourceId); - const settings = this.repositoryService.northConnectorRepository.getNorthConnector(northId); - if (settings && settings.enabled) { - await this.oibusEngine.startNorth(northId, settings); - } - } - async onDeleteNorthSubscription(northId: string, southId: string): Promise { await this.oibusEngine.stopNorth(northId); this.repositoryService.subscriptionRepository.deleteNorthSubscription(northId, southId); @@ -304,15 +295,6 @@ export default class ReloadService { } } - async onDeleteExternalNorthSubscription(northId: string, externalSourceId: string): Promise { - await this.oibusEngine.stopNorth(northId); - this.repositoryService.subscriptionRepository.deleteExternalNorthSubscription(northId, externalSourceId); - const settings = this.repositoryService.northConnectorRepository.getNorthConnector(northId); - if (settings && settings.enabled) { - await this.oibusEngine.startNorth(northId, settings); - } - } - async onCreateHistoryQuery(command: HistoryQueryCommandDTO, southItems: Array): Promise { const historyQuery = this.repositoryService.historyQueryRepository.createHistoryQuery(command); for (const item of southItems) { diff --git a/backend/src/service/repository.service.spec.ts b/backend/src/service/repository.service.spec.ts index 97394f34eb..b8aded046e 100644 --- a/backend/src/service/repository.service.spec.ts +++ b/backend/src/service/repository.service.spec.ts @@ -3,7 +3,6 @@ import db from 'better-sqlite3'; import RepositoryService from './repository.service'; import EngineRepository from '../repository/engine.repository'; -import ExternalSourceRepository from '../repository/external-source.repository'; import IpFilterRepository from '../repository/ip-filter.repository'; import ScanModeRepository from '../repository/scan-mode.repository'; import SouthConnectorRepository from '../repository/south-connector.repository'; @@ -24,7 +23,6 @@ import RegistrationRepository from '../repository/registration.repository'; import CommandRepository from '../repository/command.repository'; jest.mock('better-sqlite3', () => jest.fn(() => 'sqlite database')); -jest.mock('../repository/external-source.repository'); jest.mock('../repository/crypto.repository'); jest.mock('../repository/ip-filter.repository'); jest.mock('../repository/scan-mode.repository'); @@ -54,7 +52,6 @@ describe('Repository service', () => { expect(db).toHaveBeenCalledWith('myCacheDatabase'); expect(EngineRepository).toHaveBeenCalledWith('sqlite database'); expect(CryptoRepository).toHaveBeenCalledWith('sqlite database'); - expect(ExternalSourceRepository).toHaveBeenCalledWith('sqlite database'); expect(IpFilterRepository).toHaveBeenCalledWith('sqlite database'); expect(ScanModeRepository).toHaveBeenCalledWith('sqlite database'); expect(NorthConnectorRepository).toHaveBeenCalledWith('sqlite database'); @@ -75,7 +72,6 @@ describe('Repository service', () => { expect(repositoryService.engineRepository).toBeDefined(); expect(repositoryService.cryptoRepository).toBeDefined(); - expect(repositoryService.externalSourceRepository).toBeDefined(); expect(repositoryService.ipFilterRepository).toBeDefined(); expect(repositoryService.scanModeRepository).toBeDefined(); expect(repositoryService.northConnectorRepository).toBeDefined(); diff --git a/backend/src/service/repository.service.ts b/backend/src/service/repository.service.ts index 3c754b5aab..c1189bd328 100644 --- a/backend/src/service/repository.service.ts +++ b/backend/src/service/repository.service.ts @@ -1,7 +1,6 @@ import Database from 'better-sqlite3'; import EngineRepository from '../repository/engine.repository'; -import ExternalSourceRepository from '../repository/external-source.repository'; import IpFilterRepository from '../repository/ip-filter.repository'; import ScanModeRepository from '../repository/scan-mode.repository'; import SouthConnectorRepository from '../repository/south-connector.repository'; @@ -24,7 +23,6 @@ import CommandRepository from '../repository/command.repository'; export default class RepositoryService { private readonly _engineRepository: EngineRepository; private readonly _cryptoRepository: CryptoRepository; - private readonly _externalSourceRepository: ExternalSourceRepository; private readonly _ipFilterRepository: IpFilterRepository; private readonly _scanModeRepository: ScanModeRepository; private readonly _certificateRepository: CertificateRepository; @@ -49,7 +47,6 @@ export default class RepositoryService { const cryptoDatabase = Database(cryptoDatabasePath); const cacheDatabase = Database(cacheDatabasePath); - this._externalSourceRepository = new ExternalSourceRepository(oibusDatabase); this._ipFilterRepository = new IpFilterRepository(oibusDatabase); this._scanModeRepository = new ScanModeRepository(oibusDatabase); this._certificateRepository = new CertificateRepository(oibusDatabase); @@ -112,10 +109,6 @@ export default class RepositoryService { return this._engineRepository; } - get externalSourceRepository(): ExternalSourceRepository { - return this._externalSourceRepository; - } - get ipFilterRepository(): IpFilterRepository { return this._ipFilterRepository; } diff --git a/backend/src/tests/__mocks__/repository-service.mock.ts b/backend/src/tests/__mocks__/repository-service.mock.ts index d8f7211943..84ebca8233 100644 --- a/backend/src/tests/__mocks__/repository-service.mock.ts +++ b/backend/src/tests/__mocks__/repository-service.mock.ts @@ -134,16 +134,11 @@ export default jest.fn().mockImplementation(() => ({ }, subscriptionRepository: { getNorthSubscriptions: jest.fn(), - getExternalNorthSubscriptions: jest.fn(), getSubscribedNorthConnectors: jest.fn(), checkNorthSubscription: jest.fn(), - checkExternalNorthSubscription: jest.fn(), createNorthSubscription: jest.fn(), - createExternalNorthSubscription: jest.fn(), deleteNorthSubscription: jest.fn(), - deleteExternalNorthSubscription: jest.fn(), - deleteNorthSubscriptions: jest.fn(), - deleteExternalNorthSubscriptions: jest.fn() + deleteNorthSubscriptions: jest.fn() }, southMetricsRepository: new SouthMetricsRepositoryMock(), northMetricsRepository: new NorthMetricsRepositoryMock(), diff --git a/backend/src/web-server/controllers/content.controller.spec.ts b/backend/src/web-server/controllers/content.controller.spec.ts index e3eca137ea..c38d733c38 100644 --- a/backend/src/web-server/controllers/content.controller.spec.ts +++ b/backend/src/web-server/controllers/content.controller.spec.ts @@ -32,47 +32,18 @@ describe('Content controller', () => { it('should add values', async () => { ctx.request.body = content; - ctx.request.query = { name: 'source', northId: 'northId' }; - ctx.app.repositoryService.externalSourceRepository.findExternalSourceByReference.mockReturnValue({ - id: '1', - reference: 'source', - description: 'description' - }); + ctx.request.query = { northId: 'northId' }; await oibusController.addContent(ctx); expect(ctx.noContent).toHaveBeenCalled(); expect(ctx.app.oibusService.addExternalContent).toHaveBeenCalledWith('northId', content); }); - it('should add values with null as external source', async () => { - ctx.request.body = content; - ctx.request.query = { name: 'source', northId: 'northId' }; - ctx.app.repositoryService.externalSourceRepository.findExternalSourceByReference.mockReturnValue(null); - await oibusController.addContent(ctx); - expect(ctx.badRequest).toHaveBeenCalled(); - expect(ctx.noContent).not.toHaveBeenCalled(); - expect(ctx.app.oibusService.addExternalContent).not.toHaveBeenCalled(); - }); - - it('should not add values if no source name provided', async () => { - ctx.request.body = content; - ctx.request.query = { northId: 'northId' }; - - await oibusController.addContent(ctx); - expect(ctx.badRequest).toHaveBeenCalled(); - expect(ctx.app.oibusService.addExternalContent).not.toHaveBeenCalled(); - }); - it('should properly manage internal error when adding values', async () => { (ctx.app.oibusService.addExternalContent as jest.Mock).mockImplementationOnce(() => { throw new Error('internal error'); }); - ctx.app.repositoryService.externalSourceRepository.findExternalSourceByReference.mockReturnValue({ - id: '1', - reference: 'source', - description: 'description' - }); ctx.request.body = content; - ctx.request.query = { name: 'source', northId: ['northId1', 'northId2'] }; + ctx.request.query = { northId: ['northId1', 'northId2'] }; await oibusController.addContent(ctx); expect(ctx.internalServerError).toHaveBeenCalled(); expect(ctx.badRequest).not.toHaveBeenCalled(); @@ -80,14 +51,9 @@ describe('Content controller', () => { }); it('should add file', async () => { - ctx.request.query = { name: 'source', northId: 'northId' }; + ctx.request.query = { northId: 'northId' }; ctx.request.body = fileContent; ctx.request.file = { path: 'filePath' }; - ctx.app.repositoryService.externalSourceRepository.findExternalSourceByReference.mockReturnValue({ - id: '1', - reference: 'source', - description: 'description' - }); await oibusController.addContent(ctx); expect(ctx.noContent).toHaveBeenCalled(); expect(ctx.app.oibusService.addExternalContent).toHaveBeenCalledWith('northId', { type: 'raw', filePath: 'filePath' }); diff --git a/backend/src/web-server/controllers/content.controller.ts b/backend/src/web-server/controllers/content.controller.ts index 1ec971e4b8..505104876f 100644 --- a/backend/src/web-server/controllers/content.controller.ts +++ b/backend/src/web-server/controllers/content.controller.ts @@ -4,15 +4,7 @@ import AbstractController from './abstract.controller'; export default class ContentController extends AbstractController { async addContent(ctx: KoaContext): Promise { - const { name, northId } = ctx.request.query; - if (!name) { - return ctx.badRequest(); - } - const externalSource = ctx.app.repositoryService.externalSourceRepository.findExternalSourceByReference(name as string); - if (!externalSource) { - ctx.app.logger.info(`External source "${name}" not found`); - return ctx.badRequest(); - } + const { northId } = ctx.request.query; const ids = []; if (typeof northId === 'string') { diff --git a/backend/src/web-server/controllers/external-source.controller.spec.ts b/backend/src/web-server/controllers/external-source.controller.spec.ts deleted file mode 100644 index 18335ecc6c..0000000000 --- a/backend/src/web-server/controllers/external-source.controller.spec.ts +++ /dev/null @@ -1,134 +0,0 @@ -import Joi from 'joi'; - -import ExternalSourceController from './external-source.controller'; -import JoiValidator from './validators/joi.validator'; -import KoaContextMock from '../../tests/__mocks__/koa-context.mock'; - -jest.mock('./validators/joi.validator'); - -const validator = new JoiValidator(); -const schema = Joi.object({}); -const externalSourceController = new ExternalSourceController(validator, schema); - -const ctx = new KoaContextMock(); -const externalSourceCommand = { - reference: 'reference', - description: 'description' -}; -const externalSource = { - id: '1', - ...externalSourceCommand -}; - -describe('External source controller', () => { - beforeEach(async () => { - jest.resetAllMocks(); - }); - - it('getExternalSources() should return external sources', async () => { - ctx.app.repositoryService.externalSourceRepository.getExternalSources.mockReturnValue([externalSource]); - - await externalSourceController.getExternalSources(ctx); - - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSources).toHaveBeenCalled(); - expect(ctx.ok).toHaveBeenCalledWith([externalSource]); - }); - - it('getExternalSource() should return external source', async () => { - const id = 'id'; - - ctx.params.id = id; - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue(externalSource); - - await externalSourceController.getExternalSource(ctx); - - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(id); - expect(ctx.ok).toHaveBeenCalledWith(externalSource); - }); - - it('getExternalSource() should return not found', async () => { - const id = 'id'; - ctx.params.id = id; - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue(null); - - await externalSourceController.getExternalSource(ctx); - - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(id); - expect(ctx.notFound).toHaveBeenCalledWith(); - }); - - it('createExternalSource() should create external source', async () => { - ctx.request.body = externalSourceCommand; - ctx.app.repositoryService.externalSourceRepository.createExternalSource.mockReturnValue(externalSource); - - await externalSourceController.createExternalSource(ctx); - - expect(validator.validate).toHaveBeenCalledWith(schema, externalSourceCommand); - expect(ctx.app.repositoryService.externalSourceRepository.createExternalSource).toHaveBeenCalledWith(externalSourceCommand); - expect(ctx.created).toHaveBeenCalledWith(externalSource); - }); - - it('createExternalSource() should return bad request', async () => { - ctx.request.body = externalSourceCommand; - const validationError = new Error('invalid body'); - validator.validate = jest.fn().mockImplementationOnce(() => { - throw validationError; - }); - - await externalSourceController.createExternalSource(ctx); - - expect(validator.validate).toHaveBeenCalledWith(schema, externalSourceCommand); - expect(ctx.app.repositoryService.externalSourceRepository.createExternalSource).not.toHaveBeenCalledWith(); - expect(ctx.badRequest).toHaveBeenCalledWith(validationError.message); - }); - - it('updateExternalSource() should update external source', async () => { - const id = 'id'; - ctx.params.id = id; - ctx.request.body = externalSourceCommand; - - await externalSourceController.updateExternalSource(ctx); - - expect(validator.validate).toHaveBeenCalledWith(schema, externalSourceCommand); - expect(ctx.app.repositoryService.externalSourceRepository.updateExternalSource).toHaveBeenCalledWith(id, externalSourceCommand); - expect(ctx.noContent).toHaveBeenCalled(); - }); - - it('updateExternalSource() should return bad request', async () => { - ctx.request.body = externalSourceCommand; - const validationError = new Error('invalid body'); - validator.validate = jest.fn().mockImplementationOnce(() => { - throw validationError; - }); - - await externalSourceController.updateExternalSource(ctx); - - expect(validator.validate).toHaveBeenCalledWith(schema, externalSourceCommand); - expect(ctx.app.repositoryService.externalSourceRepository.updateExternalSource).not.toHaveBeenCalledWith(); - expect(ctx.badRequest).toHaveBeenCalledWith(validationError.message); - }); - - it('deleteExternalSource() should delete external source', async () => { - const id = 'id'; - ctx.params.id = id; - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue(externalSource); - - await externalSourceController.deleteExternalSource(ctx); - - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(id); - expect(ctx.app.repositoryService.externalSourceRepository.deleteExternalSource).toHaveBeenCalledWith(id); - expect(ctx.noContent).toHaveBeenCalled(); - }); - - it('deleteExternalSource() should return not found', async () => { - const id = 'id'; - ctx.params.id = id; - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue(null); - - await externalSourceController.deleteExternalSource(ctx); - - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(id); - expect(ctx.app.repositoryService.externalSourceRepository.deleteExternalSource).not.toHaveBeenCalled(); - expect(ctx.notFound).toHaveBeenCalled(); - }); -}); diff --git a/backend/src/web-server/controllers/external-source.controller.ts b/backend/src/web-server/controllers/external-source.controller.ts deleted file mode 100644 index 9238f29289..0000000000 --- a/backend/src/web-server/controllers/external-source.controller.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { KoaContext } from '../koa'; -import { ExternalSourceCommandDTO, ExternalSourceDTO } from '../../../../shared/model/external-sources.model'; -import AbstractController from './abstract.controller'; - -export default class ExternalSourceController extends AbstractController { - async getExternalSources(ctx: KoaContext>): Promise { - const externalSources = ctx.app.repositoryService.externalSourceRepository.getExternalSources(); - ctx.ok(externalSources); - } - - async getExternalSource(ctx: KoaContext): Promise { - const externalSource = ctx.app.repositoryService.externalSourceRepository.getExternalSource(ctx.params.id); - if (externalSource) { - ctx.ok(externalSource); - } else { - ctx.notFound(); - } - } - - async createExternalSource(ctx: KoaContext): Promise { - try { - await this.validate(ctx.request.body); - const externalSource = ctx.app.repositoryService.externalSourceRepository.createExternalSource( - ctx.request.body as ExternalSourceCommandDTO - ); - ctx.created(externalSource); - } catch (error: any) { - ctx.badRequest(error.message); - } - } - - async updateExternalSource(ctx: KoaContext): Promise { - try { - await this.validate(ctx.request.body); - ctx.app.repositoryService.externalSourceRepository.updateExternalSource(ctx.params.id, ctx.request.body as ExternalSourceCommandDTO); - ctx.noContent(); - } catch (error: any) { - ctx.badRequest(error.message); - } - } - - async deleteExternalSource(ctx: KoaContext): Promise { - const externalSource = ctx.app.repositoryService.externalSourceRepository.getExternalSource(ctx.params.id); - if (externalSource) { - ctx.app.repositoryService.externalSourceRepository.deleteExternalSource(ctx.params.id); - ctx.noContent(); - } else { - ctx.notFound(); - } - } -} diff --git a/backend/src/web-server/controllers/north-connector.controller.spec.ts b/backend/src/web-server/controllers/north-connector.controller.spec.ts index 6266f8a5d7..f2bad7d4d0 100644 --- a/backend/src/web-server/controllers/north-connector.controller.spec.ts +++ b/backend/src/web-server/controllers/north-connector.controller.spec.ts @@ -280,19 +280,13 @@ describe('North connector controller', () => { north: { ...northConnectorCommand }, subscriptions: [ { type: 'south', subscription: { id: 'id1' } }, - { type: 'south', subscription: { id: 'id2' } }, - { type: 'external-source', externalSubscription: { id: 'id3' } }, - { type: 'external-source', externalSubscription: { id: 'id4' } } + { type: 'south', subscription: { id: 'id2' } } ], - subscriptionsToDelete: [ - { type: 'south', subscription: { id: 'id5' } }, - { type: 'external-source', externalSubscription: { id: 'id6' } } - ] + subscriptionsToDelete: [{ type: 'south', subscription: { id: 'id5' } }] }; ctx.params.id = 'id'; ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue(northConnector); ctx.app.repositoryService.subscriptionRepository.getNorthSubscriptions.mockReturnValue(['id1']); - ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions.mockReturnValue(['id3']); ctx.app.encryptionService.encryptConnectorSecrets.mockReturnValue(northConnectorCommand.settings); await northConnectorController.updateNorthConnector(ctx); @@ -300,16 +294,13 @@ describe('North connector controller', () => { expect(validator.validateSettings).toHaveBeenCalledWith(northTestManifest.settings, northConnectorCommand.settings); expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith('id'); expect(ctx.app.repositoryService.subscriptionRepository.getNorthSubscriptions).toHaveBeenCalledWith('id'); - expect(ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions).toHaveBeenCalledWith('id'); expect(ctx.app.encryptionService.encryptConnectorSecrets).toHaveBeenCalledWith( northConnectorCommand.settings, northConnector.settings, northTestManifest.settings ); expect(ctx.app.repositoryService.subscriptionRepository.createNorthSubscription).toHaveBeenCalledWith('id', 'id2'); - expect(ctx.app.repositoryService.subscriptionRepository.createExternalNorthSubscription).toHaveBeenCalledWith('id', 'id4'); expect(ctx.app.repositoryService.subscriptionRepository.deleteNorthSubscription).toHaveBeenCalledWith('id', 'id5'); - expect(ctx.app.repositoryService.subscriptionRepository.deleteExternalNorthSubscription).toHaveBeenCalledWith('id', 'id6'); expect(ctx.app.reloadService.onUpdateNorthSettings).toHaveBeenCalledWith('id', northConnectorCommand); expect(ctx.noContent).toHaveBeenCalled(); }); @@ -389,7 +380,6 @@ describe('North connector controller', () => { await northConnectorController.deleteNorthConnector(ctx); expect(ctx.app.repositoryService.subscriptionRepository.deleteNorthSubscriptions).toHaveBeenCalledWith('id'); - expect(ctx.app.repositoryService.subscriptionRepository.deleteExternalNorthSubscriptions).toHaveBeenCalledWith('id'); expect(ctx.app.reloadService.onDeleteNorth).toHaveBeenCalledWith('id'); expect(ctx.noContent).toHaveBeenCalled(); }); diff --git a/backend/src/web-server/controllers/north-connector.controller.ts b/backend/src/web-server/controllers/north-connector.controller.ts index 57ccbdd829..767e5a5d59 100644 --- a/backend/src/web-server/controllers/north-connector.controller.ts +++ b/backend/src/web-server/controllers/north-connector.controller.ts @@ -89,18 +89,12 @@ export default class NorthConnectorController { const subscriptionsToAdd = ctx.request.body.subscriptions .filter(element => element.type === 'south') .map(element => element.subscription!.id); - const externalSubscriptionsToAdd = ctx.request.body.subscriptions - .filter(element => element.type === 'external-source') - .map(element => element.externalSubscription!.id); const northConnector = await ctx.app.reloadService.onCreateNorth(command); for (const subscription of subscriptionsToAdd) { ctx.app.repositoryService.subscriptionRepository.createNorthSubscription(northConnector.id, subscription); } - for (const subscription of externalSubscriptionsToAdd) { - ctx.app.repositoryService.subscriptionRepository.createExternalNorthSubscription(northConnector.id, subscription); - } if (command.enabled) { await ctx.app.reloadService.onStartNorth(northConnector.id); @@ -137,7 +131,6 @@ export default class NorthConnectorController { ); const existingSubscriptions = ctx.app.repositoryService.subscriptionRepository.getNorthSubscriptions(ctx.params.id); - const existingExternalSubscriptions = ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions(ctx.params.id); const subscriptionsToAdd = ctx.request.body.subscriptions .filter( element => @@ -145,32 +138,16 @@ export default class NorthConnectorController { !existingSubscriptions.find(existingSubscription => existingSubscription === element.subscription!.id) ) .map(element => element.subscription!.id); - const externalSubscriptionsToAdd = ctx.request.body.subscriptions - .filter( - element => - element.type === 'external-source' && - !existingExternalSubscriptions.find(existingSubscription => existingSubscription === element.externalSubscription!.id) - ) - .map(element => element.externalSubscription!.id); const subscriptionsToRemove = ctx.request.body.subscriptionsToDelete .filter(element => element.type === 'south') .map(element => element.subscription!.id); - const externalSubscriptionsToRemove = ctx.request.body.subscriptionsToDelete - .filter(element => element.type === 'external-source') - .map(element => element.externalSubscription!.id); for (const subscription of subscriptionsToAdd) { ctx.app.repositoryService.subscriptionRepository.createNorthSubscription(ctx.params.id, subscription); } - for (const subscription of externalSubscriptionsToAdd) { - ctx.app.repositoryService.subscriptionRepository.createExternalNorthSubscription(ctx.params.id, subscription); - } for (const subscription of subscriptionsToRemove) { ctx.app.repositoryService.subscriptionRepository.deleteNorthSubscription(ctx.params.id, subscription); } - for (const subscription of externalSubscriptionsToRemove) { - ctx.app.repositoryService.subscriptionRepository.deleteExternalNorthSubscription(ctx.params.id, subscription); - } await ctx.app.reloadService.onUpdateNorthSettings(ctx.params.id, command); ctx.noContent(); } catch (error: any) { @@ -182,7 +159,6 @@ export default class NorthConnectorController { const northConnector = ctx.app.repositoryService.northConnectorRepository.getNorthConnector(ctx.params.id); if (northConnector) { await ctx.app.repositoryService.subscriptionRepository.deleteNorthSubscriptions(ctx.params.id); - await ctx.app.repositoryService.subscriptionRepository.deleteExternalNorthSubscriptions(ctx.params.id); await ctx.app.reloadService.onDeleteNorth(ctx.params.id); ctx.noContent(); } else { diff --git a/backend/src/web-server/controllers/subscription.controller.spec.ts b/backend/src/web-server/controllers/subscription.controller.spec.ts index a4e82188f3..01644688e4 100644 --- a/backend/src/web-server/controllers/subscription.controller.spec.ts +++ b/backend/src/web-server/controllers/subscription.controller.spec.ts @@ -23,20 +23,6 @@ describe('Subscription controller', () => { expect(ctx.ok).toHaveBeenCalledWith(['south1', 'south2']); }); - it('getExternalNorthSubscriptions() should return external subscriptions', async () => { - const northId = 'northId'; - - ctx.params.northId = northId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue({ id: northId }); - ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions.mockReturnValue(['external1', 'external2']); - - await subscriptionController.getExternalNorthSubscriptions(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions).toHaveBeenCalledWith(northId); - expect(ctx.ok).toHaveBeenCalledWith(['external1', 'external2']); - }); - it('getNorthSubscriptions() should return not found', async () => { const northId = 'northId'; @@ -50,19 +36,6 @@ describe('Subscription controller', () => { expect(ctx.notFound).toHaveBeenCalled(); }); - it('getExternalNorthSubscriptions() should return not found', async () => { - const northId = 'northId'; - - ctx.params.northId = northId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue(null); - - await subscriptionController.getExternalNorthSubscriptions(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions).not.toHaveBeenCalled(); - expect(ctx.notFound).toHaveBeenCalled(); - }); - it('createNorthSubscription() should create subscription', async () => { const northId = 'northId'; const southId = 'southId'; @@ -136,79 +109,6 @@ describe('Subscription controller', () => { expect(ctx.throw).toHaveBeenCalledWith(409, 'Subscription already exists'); }); - it('createExternalNorthSubscription() should create subscription', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue({ id: northId }); - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue({ id: externalSourceId }); - ctx.app.repositoryService.subscriptionRepository.checkExternalNorthSubscription.mockReturnValue(false); - - await subscriptionController.createExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(externalSourceId); - expect(ctx.app.repositoryService.subscriptionRepository.checkExternalNorthSubscription).toHaveBeenCalledWith(northId, externalSourceId); - expect(ctx.app.reloadService.onCreateExternalNorthSubscription).toHaveBeenCalledWith(northId, externalSourceId); - expect(ctx.noContent).toHaveBeenCalled(); - }); - - it('createExternalNorthSubscription() return not found when North is not found', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue(null); - - await subscriptionController.createExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).not.toHaveBeenCalled(); - expect(ctx.app.repositoryService.subscriptionRepository.checkExternalNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.app.reloadService.onCreateNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.notFound).toHaveBeenCalled(); - }); - - it('createExternalNorthSubscription() return not found when external south is not found', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue({ id: northId }); - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue(null); - - await subscriptionController.createExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(externalSourceId); - expect(ctx.app.repositoryService.subscriptionRepository.checkNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.app.reloadService.onCreateNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.notFound).toHaveBeenCalled(); - }); - - it('createExternalNorthSubscription() return bad request when subscription already exists', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue({ id: northId }); - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue({ id: externalSourceId }); - ctx.app.repositoryService.subscriptionRepository.checkExternalNorthSubscription.mockReturnValue(true); - - await subscriptionController.createExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(externalSourceId); - expect(ctx.app.repositoryService.subscriptionRepository.checkExternalNorthSubscription).toHaveBeenCalledWith(northId, externalSourceId); - expect(ctx.app.reloadService.onCreateNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.throw).toHaveBeenCalledWith(409, 'Subscription already exists'); - }); - it('deleteNorthSubscription() should delete subscription', async () => { const northId = 'northId'; const southId = 'southId'; @@ -258,54 +158,4 @@ describe('Subscription controller', () => { expect(ctx.app.reloadService.onDeleteNorthSubscription).not.toHaveBeenCalled(); expect(ctx.notFound).toHaveBeenCalled(); }); - - it('deleteExternalNorthSubscription() should delete external subscription', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue({ id: northId }); - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue({ id: externalSourceId }); - - await subscriptionController.deleteExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(externalSourceId); - expect(ctx.app.reloadService.onDeleteExternalNorthSubscription).toHaveBeenCalledWith(northId, externalSourceId); - expect(ctx.noContent).toHaveBeenCalled(); - }); - - it('deleteExternalNorthSubscription() should return not found when North is not found', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue(null); - - await subscriptionController.deleteExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).not.toHaveBeenCalled(); - expect(ctx.app.reloadService.onDeleteExternalNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.notFound).toHaveBeenCalled(); - }); - - it('deleteExternalNorthSubscription() should return not found when external source is not found', async () => { - const northId = 'northId'; - const externalSourceId = 'externalSourceId'; - - ctx.params.northId = northId; - ctx.params.externalSourceId = externalSourceId; - ctx.app.repositoryService.northConnectorRepository.getNorthConnector.mockReturnValue({ id: northId }); - ctx.app.repositoryService.externalSourceRepository.getExternalSource.mockReturnValue(null); - - await subscriptionController.deleteExternalNorthSubscription(ctx); - - expect(ctx.app.repositoryService.northConnectorRepository.getNorthConnector).toHaveBeenCalledWith(northId); - expect(ctx.app.repositoryService.externalSourceRepository.getExternalSource).toHaveBeenCalledWith(externalSourceId); - expect(ctx.app.reloadService.onDeleteExternalNorthSubscription).not.toHaveBeenCalled(); - expect(ctx.notFound).toHaveBeenCalled(); - }); }); diff --git a/backend/src/web-server/controllers/subscription.controller.ts b/backend/src/web-server/controllers/subscription.controller.ts index e9dc7bd896..c98688283f 100644 --- a/backend/src/web-server/controllers/subscription.controller.ts +++ b/backend/src/web-server/controllers/subscription.controller.ts @@ -1,5 +1,5 @@ import { KoaContext } from '../koa'; -import { ExternalSubscriptionDTO, SubscriptionDTO } from '../../../../shared/model/subscription.model'; +import { SubscriptionDTO } from '../../../../shared/model/subscription.model'; export default class SubscriptionController { async getNorthSubscriptions(ctx: KoaContext>): Promise { @@ -12,16 +12,6 @@ export default class SubscriptionController { ctx.ok(subscriptions); } - async getExternalNorthSubscriptions(ctx: KoaContext>): Promise { - const northConnector = ctx.app.repositoryService.northConnectorRepository.getNorthConnector(ctx.params.northId); - if (!northConnector) { - return ctx.notFound(); - } - - const subscriptions = ctx.app.repositoryService.subscriptionRepository.getExternalNorthSubscriptions(ctx.params.northId); - ctx.ok(subscriptions); - } - async createNorthSubscription(ctx: KoaContext): Promise { const northConnector = ctx.app.repositoryService.northConnectorRepository.getNorthConnector(ctx.params.northId); if (!northConnector) { @@ -41,25 +31,6 @@ export default class SubscriptionController { return ctx.noContent(); } - async createExternalNorthSubscription(ctx: KoaContext): Promise { - const northConnector = ctx.app.repositoryService.northConnectorRepository.getNorthConnector(ctx.params.northId); - if (!northConnector) { - return ctx.notFound(); - } - - const externalSource = ctx.app.repositoryService.externalSourceRepository.getExternalSource(ctx.params.externalSourceId); - if (!externalSource) { - return ctx.notFound(); - } - - if (ctx.app.repositoryService.subscriptionRepository.checkExternalNorthSubscription(ctx.params.northId, ctx.params.externalSourceId)) { - return ctx.throw(409, 'Subscription already exists'); - } - - await ctx.app.reloadService.onCreateExternalNorthSubscription(ctx.params.northId, ctx.params.externalSourceId); - return ctx.noContent(); - } - async deleteNorthSubscription(ctx: KoaContext): Promise { const northConnector = ctx.app.repositoryService.northConnectorRepository.getNorthConnector(ctx.params.northId); if (!northConnector) { @@ -74,19 +45,4 @@ export default class SubscriptionController { await ctx.app.reloadService.onDeleteNorthSubscription(ctx.params.northId, ctx.params.southId); return ctx.noContent(); } - - async deleteExternalNorthSubscription(ctx: KoaContext): Promise { - const northConnector = ctx.app.repositoryService.northConnectorRepository.getNorthConnector(ctx.params.northId); - if (!northConnector) { - return ctx.notFound(); - } - - const externalSource = ctx.app.repositoryService.externalSourceRepository.getExternalSource(ctx.params.externalSourceId); - if (!externalSource) { - return ctx.notFound(); - } - - await ctx.app.reloadService.onDeleteExternalNorthSubscription(ctx.params.northId, ctx.params.externalSourceId); - return ctx.noContent(); - } } diff --git a/backend/src/web-server/routes/index.ts b/backend/src/web-server/routes/index.ts index 8a74f6a364..30d6972bf6 100644 --- a/backend/src/web-server/routes/index.ts +++ b/backend/src/web-server/routes/index.ts @@ -4,7 +4,6 @@ import multer from '@koa/multer'; import LogController from '../controllers/log.controller'; import ScanModeController from '../controllers/scan-mode.controller'; -import ExternalSourceController from '../controllers/external-source.controller'; import EngineController from '../controllers/engine.controller'; import IpFilterController from '../controllers/ip-filter.controller'; import NorthConnectorController from '../controllers/north-connector.controller'; @@ -21,7 +20,6 @@ import { commandSchema, contentSchema, engineSchema, - externalSourceSchema, historyQuerySchema, ipFilterSchema, logSchema, @@ -36,7 +34,6 @@ const joiValidator = new JoiValidator(); const scanModeController = new ScanModeController(joiValidator, scanModeSchema); const certificateController = new CertificateController(joiValidator, certificateSchema); const commandController = new CommandController(joiValidator, commandSchema); -const externalSourceController = new ExternalSourceController(joiValidator, externalSourceSchema); const engineController = new EngineController(joiValidator, engineSchema); const contentController = new ContentController(joiValidator, contentSchema); const registrationController = new RegistrationController(joiValidator, registrationSchema); @@ -77,12 +74,6 @@ router.post('/api/certificates', (ctx: KoaContext) => certificateContr router.put('/api/certificates/:id', (ctx: KoaContext) => certificateController.update(ctx)); router.delete('/api/certificates/:id', (ctx: KoaContext) => certificateController.delete(ctx)); -router.get('/api/external-sources', (ctx: KoaContext) => externalSourceController.getExternalSources(ctx)); -router.get('/api/external-sources/:id', (ctx: KoaContext) => externalSourceController.getExternalSource(ctx)); -router.post('/api/external-sources', (ctx: KoaContext) => externalSourceController.createExternalSource(ctx)); -router.put('/api/external-sources/:id', (ctx: KoaContext) => externalSourceController.updateExternalSource(ctx)); -router.delete('/api/external-sources/:id', (ctx: KoaContext) => externalSourceController.deleteExternalSource(ctx)); - router.get('/api/engine', (ctx: KoaContext) => engineController.getEngineSettings(ctx)); router.put('/api/engine', (ctx: KoaContext) => engineController.updateEngineSettings(ctx)); router.put('/api/engine/reset-metrics', (ctx: KoaContext) => engineController.resetEngineMetrics(ctx)); @@ -119,15 +110,6 @@ router.post('/api/north/:northId/subscriptions/:southId', (ctx: KoaContext) => subscriptionController.deleteNorthSubscription(ctx) ); -router.get('/api/north/:northId/external-subscriptions', (ctx: KoaContext) => - subscriptionController.getExternalNorthSubscriptions(ctx) -); -router.post('/api/north/:northId/external-subscriptions/:externalSourceId', (ctx: KoaContext) => - subscriptionController.createExternalNorthSubscription(ctx) -); -router.delete('/api/north/:northId/external-subscriptions/:externalSourceId', (ctx: KoaContext) => - subscriptionController.deleteExternalNorthSubscription(ctx) -); router.get('/api/north/:northId/cache/file-errors', (ctx: KoaContext) => northConnectorController.getFileErrors(ctx)); router.get('/api/north/:northId/cache/file-errors/:filename', (ctx: KoaContext) => northConnectorController.getFileErrorContent(ctx) diff --git a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.html b/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.html deleted file mode 100644 index 93b1fcdfb2..0000000000 --- a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.html +++ /dev/null @@ -1,24 +0,0 @@ - - - diff --git a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.scss b/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.spec.ts b/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.spec.ts deleted file mode 100644 index 29352b2a63..0000000000 --- a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.spec.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { EditExternalSourceModalComponent } from './edit-external-source-modal.component'; -import { ComponentTester, createMock } from 'ngx-speculoos'; -import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; -import { fakeAsync, TestBed } from '@angular/core/testing'; -import { of } from 'rxjs'; -import { DefaultValidationErrorsComponent } from '../../shared/default-validation-errors/default-validation-errors.component'; -import { ExternalSourceService } from '../../services/external-source.service'; -import { ExternalSourceCommandDTO, ExternalSourceDTO } from '../../../../../shared/model/external-sources.model'; -import { provideI18nTesting } from '../../../i18n/mock-i18n'; - -class EditExternalSourceModalComponentTester extends ComponentTester { - constructor() { - super(EditExternalSourceModalComponent); - } - - get reference() { - return this.input('#reference')!; - } - - get description() { - return this.textarea('#description')!; - } - - get validationErrors() { - return this.elements('val-errors div'); - } - - get save() { - return this.button('#save-button')!; - } - - get cancel() { - return this.button('#cancel-button')!; - } -} - -describe('EditExternalSourceModalComponent', () => { - let tester: EditExternalSourceModalComponentTester; - let fakeActiveModal: NgbActiveModal; - let externalSourceService: jasmine.SpyObj; - - beforeEach(() => { - fakeActiveModal = createMock(NgbActiveModal); - externalSourceService = createMock(ExternalSourceService); - - TestBed.configureTestingModule({ - providers: [ - provideI18nTesting(), - { provide: NgbActiveModal, useValue: fakeActiveModal }, - { provide: ExternalSourceService, useValue: externalSourceService } - ] - }); - - TestBed.createComponent(DefaultValidationErrorsComponent).detectChanges(); - - tester = new EditExternalSourceModalComponentTester(); - }); - - describe('create mode', () => { - beforeEach(() => { - tester.componentInstance.prepareForCreation(); - tester.detectChanges(); - }); - - it('should have an empty form', () => { - expect(tester.reference).toHaveValue(''); - expect(tester.description).toHaveValue(''); - }); - - it('should not save if invalid', () => { - tester.save.click(); - - // reference - expect(tester.validationErrors.length).toBe(1); - expect(fakeActiveModal.close).not.toHaveBeenCalled(); - }); - - it('should save if valid', fakeAsync(() => { - tester.reference.fillWith('ref'); - tester.description.fillWith('desc'); - - tester.detectChanges(); - - const createdExternalSource = { - id: 'id1' - } as ExternalSourceDTO; - externalSourceService.create.and.returnValue(of(createdExternalSource)); - - tester.save.click(); - - const expectedCommand: ExternalSourceCommandDTO = { - reference: 'ref', - description: 'desc' - }; - - expect(externalSourceService.create).toHaveBeenCalledWith(expectedCommand); - expect(fakeActiveModal.close).toHaveBeenCalledWith(createdExternalSource); - })); - - it('should cancel', () => { - tester.cancel.click(); - expect(fakeActiveModal.dismiss).toHaveBeenCalled(); - }); - }); - - describe('edit mode', () => { - const externalSourceToUpdate: ExternalSourceDTO = { - id: 'id1', - reference: 'ref1', - description: 'My External source 1' - }; - - beforeEach(() => { - externalSourceService.get.and.returnValue(of(externalSourceToUpdate)); - - tester.componentInstance.prepareForEdition(externalSourceToUpdate); - tester.detectChanges(); - }); - - it('should have a populated form', () => { - expect(tester.reference).toHaveValue(externalSourceToUpdate.reference); - expect(tester.description).toHaveValue(externalSourceToUpdate.description); - }); - - it('should not save if invalid', () => { - tester.reference.fillWith(''); - tester.save.click(); - - // reference - expect(tester.validationErrors.length).toBe(1); - expect(fakeActiveModal.close).not.toHaveBeenCalled(); - }); - - it('should save if valid', fakeAsync(() => { - externalSourceService.update.and.returnValue(of(undefined)); - - tester.reference.fillWith('External source 1 (updated)'); - tester.description.fillWith('A longer and updated description of my external source'); - - tester.save.click(); - - const expectedCommand: ExternalSourceCommandDTO = { - reference: 'External source 1 (updated)', - description: 'A longer and updated description of my external source' - }; - - expect(externalSourceService.update).toHaveBeenCalledWith('id1', expectedCommand); - expect(externalSourceService.get).toHaveBeenCalledWith('id1'); - expect(fakeActiveModal.close).toHaveBeenCalledWith(externalSourceToUpdate); - })); - - it('should cancel', () => { - tester.cancel.click(); - expect(fakeActiveModal.dismiss).toHaveBeenCalled(); - }); - }); -}); diff --git a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.ts b/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.ts deleted file mode 100644 index fb0072520b..0000000000 --- a/frontend/src/app/engine/edit-external-source-modal/edit-external-source-modal.component.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Component } from '@angular/core'; -import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; -import { FormBuilder, Validators } from '@angular/forms'; -import { Observable, switchMap } from 'rxjs'; -import { ObservableState, SaveButtonComponent } from '../../shared/save-button/save-button.component'; -import { TranslateModule } from '@ngx-translate/core'; -import { ExternalSourceCommandDTO, ExternalSourceDTO } from '../../../../../shared/model/external-sources.model'; -import { ExternalSourceService } from '../../services/external-source.service'; -import { formDirectives } from '../../shared/form-directives'; - -@Component({ - selector: 'oib-edit-external-source-modal', - templateUrl: './edit-external-source-modal.component.html', - styleUrl: './edit-external-source-modal.component.scss', - imports: [...formDirectives, TranslateModule, SaveButtonComponent], - standalone: true -}) -export class EditExternalSourceModalComponent { - mode: 'create' | 'edit' = 'create'; - state = new ObservableState(); - externalSource: ExternalSourceDTO | null = null; - form = this.fb.group({ - reference: ['', Validators.required], - description: '' - }); - - constructor( - private modal: NgbActiveModal, - private fb: FormBuilder, - private externalSourceService: ExternalSourceService - ) {} - - /** - * Prepares the component for creation. - */ - prepareForCreation() { - this.mode = 'create'; - } - - /** - * Prepares the component for edition. - */ - prepareForEdition(externalSource: ExternalSourceDTO) { - this.mode = 'edit'; - this.externalSource = externalSource; - - this.form.patchValue({ - reference: externalSource.reference, - description: externalSource.description - }); - } - - cancel() { - this.modal.dismiss(); - } - - save() { - if (!this.form.valid) { - return; - } - - const formValue = this.form.value; - - const command: ExternalSourceCommandDTO = { - reference: formValue.reference!, - description: formValue.description! - }; - - let obs: Observable; - if (this.mode === 'create') { - obs = this.externalSourceService.create(command); - } else { - obs = this.externalSourceService - .update(this.externalSource!.id, command) - .pipe(switchMap(() => this.externalSourceService.get(this.externalSource!.id))); - } - obs.pipe(this.state.pendingUntilFinalization()).subscribe(externalSource => { - this.modal.close(externalSource); - }); - } -} diff --git a/frontend/src/app/engine/engine-detail.component.html b/frontend/src/app/engine/engine-detail.component.html index 5856117475..8c5fa80acc 100644 --- a/frontend/src/app/engine/engine-detail.component.html +++ b/frontend/src/app/engine/engine-detail.component.html @@ -115,9 +115,6 @@

-
- -
diff --git a/frontend/src/app/engine/engine-detail.component.spec.ts b/frontend/src/app/engine/engine-detail.component.spec.ts index 1d12a76ccc..e796afca00 100644 --- a/frontend/src/app/engine/engine-detail.component.spec.ts +++ b/frontend/src/app/engine/engine-detail.component.spec.ts @@ -9,13 +9,11 @@ import { provideI18nTesting } from '../../i18n/mock-i18n'; import { provideHttpClient } from '@angular/common/http'; import { provideRouter } from '@angular/router'; import { ScanModeListComponent } from './scan-mode-list/scan-mode-list.component'; -import { ExternalSourceListComponent } from './external-source-list/external-source-list.component'; import { IpFilterListComponent } from './ip-filter-list/ip-filter-list.component'; import { ConfirmationService } from '../shared/confirmation.service'; import { NotificationService } from '../shared/notification.service'; import { ScanModeService } from '../services/scan-mode.service'; import { IpFilterService } from '../services/ip-filter.service'; -import { ExternalSourceService } from '../services/external-source.service'; class EngineComponentTester extends ComponentTester { constructor() { @@ -34,10 +32,6 @@ class EngineComponentTester extends ComponentTester { return this.element(ScanModeListComponent); } - get externalSourceList() { - return this.element(ExternalSourceListComponent); - } - get ipFilterList() { return this.element(IpFilterListComponent); } @@ -56,7 +50,6 @@ describe('EngineDetailComponent', () => { let engineService: jasmine.SpyObj; let scanModeService: jasmine.SpyObj; let ipFilterService: jasmine.SpyObj; - let externalSourceService: jasmine.SpyObj; let confirmationService: jasmine.SpyObj; let notificationService: jasmine.SpyObj; @@ -89,7 +82,6 @@ describe('EngineDetailComponent', () => { engineService = createMock(EngineService); scanModeService = createMock(ScanModeService); ipFilterService = createMock(IpFilterService); - externalSourceService = createMock(ExternalSourceService); confirmationService = createMock(ConfirmationService); notificationService = createMock(NotificationService); @@ -101,7 +93,6 @@ describe('EngineDetailComponent', () => { { provide: EngineService, useValue: engineService }, { provide: ScanModeService, useValue: scanModeService }, { provide: IpFilterService, useValue: ipFilterService }, - { provide: ExternalSourceService, useValue: externalSourceService }, { provide: ConfirmationService, useValue: confirmationService }, { provide: NotificationService, useValue: notificationService } ] @@ -110,7 +101,6 @@ describe('EngineDetailComponent', () => { engineService.getEngineSettings.and.returnValue(of(engineSettings)); scanModeService.list.and.returnValue(of([])); ipFilterService.list.and.returnValue(of([])); - externalSourceService.list.and.returnValue(of([])); tester = new EngineComponentTester(); tester.detectChanges(); @@ -132,7 +122,6 @@ describe('EngineDetailComponent', () => { expect(table[3]).toContainText('Proxy serverEnabled on port 8888'); expect(tester.scanModeList).toBeDefined(); - expect(tester.externalSourceList).toBeDefined(); expect(tester.ipFilterList).toBeDefined(); }); diff --git a/frontend/src/app/engine/engine-detail.component.ts b/frontend/src/app/engine/engine-detail.component.ts index e3c8445d1e..fe3b778c19 100644 --- a/frontend/src/app/engine/engine-detail.component.ts +++ b/frontend/src/app/engine/engine-detail.component.ts @@ -4,7 +4,6 @@ import { EngineService } from '../services/engine.service'; import { EngineMetrics, EngineSettingsDTO } from '../../../../shared/model/engine.model'; import { AsyncPipe, NgForOf, NgIf } from '@angular/common'; import { ScanModeListComponent } from './scan-mode-list/scan-mode-list.component'; -import { ExternalSourceListComponent } from './external-source-list/external-source-list.component'; import { IpFilterListComponent } from './ip-filter-list/ip-filter-list.component'; import { NotificationService } from '../shared/notification.service'; import { ConfirmationService } from '../shared/confirmation.service'; @@ -24,7 +23,6 @@ import { CertificateListComponent } from './certificate-list/certificate-list.co TranslateModule, ScanModeListComponent, CertificateListComponent, - ExternalSourceListComponent, IpFilterListComponent, AsyncPipe, NgForOf, diff --git a/frontend/src/app/engine/external-source-list/external-source-list.component.html b/frontend/src/app/engine/external-source-list/external-source-list.component.html deleted file mode 100644 index 35c6bfcfc5..0000000000 --- a/frontend/src/app/engine/external-source-list/external-source-list.component.html +++ /dev/null @@ -1,50 +0,0 @@ - - -
-
- - ({{this.externalSources.length}}) -
-
- - -
-
-
-
- - -
- - - - - - - - - - - - - - - -
{{ externalSource.reference }}{{ externalSource.description }} -
- - - - -
-
-
- -
-
diff --git a/frontend/src/app/engine/external-source-list/external-source-list.component.scss b/frontend/src/app/engine/external-source-list/external-source-list.component.scss deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/frontend/src/app/engine/external-source-list/external-source-list.component.spec.ts b/frontend/src/app/engine/external-source-list/external-source-list.component.spec.ts deleted file mode 100644 index c8e2272a26..0000000000 --- a/frontend/src/app/engine/external-source-list/external-source-list.component.spec.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { TestBed } from '@angular/core/testing'; - -import { ExternalSourceListComponent } from './external-source-list.component'; -import { provideI18nTesting } from '../../../i18n/mock-i18n'; -import { ComponentTester, createMock, TestButton } from 'ngx-speculoos'; -import { of } from 'rxjs'; -import { ExternalSourceService } from '../../services/external-source.service'; -import { ExternalSourceDTO } from '../../../../../shared/model/external-sources.model'; -import { ConfirmationService } from '../../shared/confirmation.service'; -import { NotificationService } from '../../shared/notification.service'; - -class ExternalSourceListComponentTester extends ComponentTester { - constructor() { - super(ExternalSourceListComponent); - } - - get title() { - return this.element('#title')!; - } - - get deleteButtons() { - return this.elements('.delete-external-source') as Array; - } - - get editButtons() { - return this.elements('.edit-external-source') as Array; - } - - get addExternalSource() { - return this.button('#add-external-source')!; - } - - get noExternalSource() { - return this.element('#no-external-source'); - } - - get externalSources() { - return this.elements('tbody tr'); - } -} - -describe('ExternalSourceListComponent', () => { - let tester: ExternalSourceListComponentTester; - let externalSourceService: jasmine.SpyObj; - let confirmationService: jasmine.SpyObj; - let notificationService: jasmine.SpyObj; - - let externalSources: Array; - - beforeEach(() => { - externalSourceService = createMock(ExternalSourceService); - confirmationService = createMock(ConfirmationService); - notificationService = createMock(NotificationService); - - TestBed.configureTestingModule({ - providers: [ - provideI18nTesting(), - { provide: ExternalSourceService, useValue: externalSourceService }, - { provide: ConfirmationService, useValue: confirmationService }, - { provide: NotificationService, useValue: notificationService } - ] - }); - - externalSources = [ - { - id: 'id1', - reference: 'ref1', - description: 'My external source 1' - }, - { - id: 'id2', - reference: 'ref2', - description: 'My external source 2' - } - ]; - - tester = new ExternalSourceListComponentTester(); - }); - - describe('with external source', () => { - beforeEach(() => { - externalSourceService.list.and.returnValue(of(externalSources)); - tester.detectChanges(); - }); - - it('should display a list of external sources', () => { - expect(tester.title).toContainText('External sources'); - expect(tester.externalSources.length).toEqual(2); - expect(tester.externalSources[0].elements('td').length).toEqual(3); - expect(tester.externalSources[1].elements('td')[0]).toContainText('ref2'); - expect(tester.externalSources[1].elements('td')[1]).toContainText('My external source 2'); - }); - }); - - describe('with no external source', () => { - it('should display an empty list', () => { - externalSourceService.list.and.returnValue(of([])); - tester.detectChanges(); - expect(tester.noExternalSource).toContainText('No external source'); - }); - }); -}); diff --git a/frontend/src/app/engine/external-source-list/external-source-list.component.ts b/frontend/src/app/engine/external-source-list/external-source-list.component.ts deleted file mode 100644 index f6db234551..0000000000 --- a/frontend/src/app/engine/external-source-list/external-source-list.component.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { NgForOf, NgIf } from '@angular/common'; -import { switchMap } from 'rxjs'; -import { Modal, ModalService } from '../../shared/modal.service'; -import { ConfirmationService } from '../../shared/confirmation.service'; -import { NotificationService } from '../../shared/notification.service'; -import { TranslateModule } from '@ngx-translate/core'; -import { ExternalSourceDTO } from '../../../../../shared/model/external-sources.model'; -import { ExternalSourceService } from '../../services/external-source.service'; -import { EditExternalSourceModalComponent } from '../edit-external-source-modal/edit-external-source-modal.component'; -import { BoxComponent, BoxTitleDirective } from '../../shared/box/box.component'; -import { OibHelpComponent } from '../../shared/oib-help/oib-help.component'; - -@Component({ - selector: 'oib-external-source-list', - standalone: true, - imports: [NgIf, NgForOf, TranslateModule, BoxComponent, BoxTitleDirective, OibHelpComponent], - templateUrl: './external-source-list.component.html', - styleUrl: './external-source-list.component.scss' -}) -export class ExternalSourceListComponent implements OnInit { - externalSources: Array = []; - - constructor( - private confirmationService: ConfirmationService, - private modalService: ModalService, - private notificationService: NotificationService, - private externalSourceService: ExternalSourceService - ) {} - - ngOnInit() { - this.externalSourceService.list().subscribe(externalSources => { - this.externalSources = externalSources; - }); - } - - /** - * Open a modal to edit an external source - */ - editExternalSource(externalSource: ExternalSourceDTO) { - const modalRef = this.modalService.open(EditExternalSourceModalComponent); - const component: EditExternalSourceModalComponent = modalRef.componentInstance; - component.prepareForEdition(externalSource); - this.refreshAfterEditExternalSourceModalClosed(modalRef, 'updated'); - } - - /** - * Open a modal to create an external source - */ - addExternalSource() { - const modalRef = this.modalService.open(EditExternalSourceModalComponent); - const component: EditExternalSourceModalComponent = modalRef.componentInstance; - component.prepareForCreation(); - this.refreshAfterEditExternalSourceModalClosed(modalRef, 'created'); - } - - /** - * Refresh the IP filter list when the external source is edited - */ - private refreshAfterEditExternalSourceModalClosed(modalRef: Modal, mode: 'created' | 'updated') { - modalRef.result.subscribe((ipFilter: ExternalSourceDTO) => { - this.externalSourceService.list().subscribe(externalSources => { - this.externalSources = externalSources; - }); - this.notificationService.success(`engine.external-source.${mode}`, { - reference: ipFilter.reference - }); - }); - } - - /** - * Delete an IP Filter by its ID - */ - deleteExternalSource(externalSource: ExternalSourceDTO) { - this.confirmationService - .confirm({ - messageKey: 'engine.external-source.confirm-deletion', - interpolateParams: { reference: externalSource.reference } - }) - .pipe( - switchMap(() => { - return this.externalSourceService.delete(externalSource.id); - }) - ) - .subscribe(() => { - this.externalSourceService.list().subscribe(externalSources => { - this.externalSources = externalSources; - }); - this.notificationService.success('engine.external-source.deleted', { - address: externalSource.reference - }); - }); - } -} diff --git a/frontend/src/app/north/create-north-subscription-modal/create-north-subscription-modal.component.html b/frontend/src/app/north/create-north-subscription-modal/create-north-subscription-modal.component.html index dd5e4ffe4c..9dfb471208 100644 --- a/frontend/src/app/north/create-north-subscription-modal/create-north-subscription-modal.component.html +++ b/frontend/src/app/north/create-north-subscription-modal/create-north-subscription-modal.component.html @@ -3,31 +3,13 @@