diff --git a/backend/src/db/entity-migrations/v3.3.1-oia-registration.ts b/backend/src/db/entity-migrations/v3.3.1-oia-registration.ts new file mode 100644 index 0000000000..f7fc154cca --- /dev/null +++ b/backend/src/db/entity-migrations/v3.3.1-oia-registration.ts @@ -0,0 +1,58 @@ +import { Knex } from 'knex'; +import { REGISTRATIONS_TABLE } from '../../repository/registration.repository'; + +export async function up(knex: Knex): Promise { + await updateRegistrationSettings(knex); +} + +async function updateRegistrationSettings(knex: Knex) { + await knex.schema.raw(`create table ${REGISTRATIONS_TABLE}_dg_tmp + ( + id char(36) primary key, + created_at datetime default CURRENT_TIMESTAMP not null, + updated_at datetime default CURRENT_TIMESTAMP not null, + host varchar(255) not null, + use_proxy boolean default '0', + proxy_url varchar(255), + proxy_username varchar(255), + proxy_password varchar(255), + accept_unauthorized boolean default '0', + activation_code varchar(255), + check_url varchar(255), + activation_date varchar(255), + activation_expiration_date varchar(255), + token varchar(255), + status text check (status in ('NOT_REGISTERED', 'PENDING', 'REGISTERED')) not null default 'NOT_REGISTERED' +);`); + + await knex.schema + .raw(`insert into ${REGISTRATIONS_TABLE}_dg_tmp(id, created_at, updated_at, host, use_proxy, proxy_url, proxy_username, proxy_password, + accept_unauthorized, activation_code, check_url, activation_date, + activation_expiration_date, token, status) + select id, + created_at, + updated_at, + host, + use_proxy, + proxy_url, + proxy_username, + proxy_password, + accept_unauthorized, + activation_code, + check_url, + activation_date, + activation_expiration_date, + token, + status + from ${REGISTRATIONS_TABLE};`); + + await knex.schema.raw(`drop table ${REGISTRATIONS_TABLE};`); + + await knex.schema.raw(`alter table ${REGISTRATIONS_TABLE}_dg_tmp rename to ${REGISTRATIONS_TABLE};`); + + await knex.schema.alterTable(REGISTRATIONS_TABLE, table => { + table.unique(['activation_code', 'check_url', 'host']); + }); +} + +export async function down(_knex: Knex): Promise {} diff --git a/backend/src/service/oia/registration.service.spec.ts b/backend/src/service/oia/registration.service.spec.ts index dd5ef932c9..7dc0518b6d 100644 --- a/backend/src/service/oia/registration.service.spec.ts +++ b/backend/src/service/oia/registration.service.spec.ts @@ -114,7 +114,7 @@ describe('Registration service', () => { (generateRandomId as jest.Mock).mockReturnValue('1234'); const command: RegistrationSettingsCommandDTO = { - host: 'http://localhost:4200', + host: 'http://localhost:4200/', acceptUnauthorized: false, useProxy: true, proxyUrl: 'http://localhost:3128', diff --git a/backend/src/service/oia/registration.service.ts b/backend/src/service/oia/registration.service.ts index 7bb2ece0ce..b11ef3d963 100644 --- a/backend/src/service/oia/registration.service.ts +++ b/backend/src/service/oia/registration.service.ts @@ -66,6 +66,9 @@ export default class RegistrationService { }; let response; try { + if (command.host.endsWith('/')) { + command.host = command.host.slice(0, command.host.length - 1); + } const url = `${command.host}/api/oianalytics/oibus/registration`; const agent = createProxyAgent( command.useProxy,