refactor(app-config): rename allow_custom_connection as custom_connection_allowed

This commit is contained in:
Ali BARIN
2024-10-09 10:10:40 +00:00
committed by Faruk AYDIN
parent a76bee51fc
commit 0bbe362660
15 changed files with 42 additions and 58 deletions

View File

@@ -10,11 +10,11 @@ export default async (request, response) => {
};
const appConfigParams = (request) => {
const { allowCustomConnection, shared, disabled } = request.body;
const { customConnectionAllowed, shared, disabled } = request.body;
return {
key: request.params.appKey,
allowCustomConnection,
customConnectionAllowed,
shared,
disabled,
};

View File

@@ -23,7 +23,7 @@ describe('POST /api/v1/admin/apps/:appKey/config', () => {
it('should return created app config', async () => {
const appConfig = {
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
disabled: false,
};
@@ -44,7 +44,7 @@ describe('POST /api/v1/admin/apps/:appKey/config', () => {
it('should return HTTP 422 for already existing app config', async () => {
const appConfig = {
key: 'gitlab',
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
disabled: false,
};

View File

@@ -14,10 +14,10 @@ export default async (request, response) => {
};
const appConfigParams = (request) => {
const { allowCustomConnection, shared, disabled } = request.body;
const { customConnectionAllowed, shared, disabled } = request.body;
return {
allowCustomConnection,
customConnectionAllowed,
shared,
disabled,
};

View File

@@ -24,7 +24,7 @@ describe('PATCH /api/v1/admin/apps/:appKey/config', () => {
it('should return updated app config', async () => {
const appConfig = {
key: 'gitlab',
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
disabled: false,
};
@@ -34,7 +34,7 @@ describe('PATCH /api/v1/admin/apps/:appKey/config', () => {
const newAppConfigValues = {
shared: false,
disabled: true,
allowCustomConnection: false,
customConnectionAllowed: false,
};
const response = await request(app)
@@ -55,7 +55,7 @@ describe('PATCH /api/v1/admin/apps/:appKey/config', () => {
const appConfig = {
shared: false,
disabled: true,
allowCustomConnection: false,
customConnectionAllowed: false,
};
await request(app)
@@ -68,7 +68,7 @@ describe('PATCH /api/v1/admin/apps/:appKey/config', () => {
it('should return HTTP 422 for invalid app config data', async () => {
const appConfig = {
key: 'gitlab',
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
disabled: false,
};

View File

@@ -155,7 +155,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => {
await createAppConfig({
key: 'gitlab',
disabled: false,
allowCustomConnection: true,
customConnectionAllowed: true,
});
});
@@ -218,7 +218,7 @@ describe('POST /api/v1/apps/:appKey/connections', () => {
await createAppConfig({
key: 'gitlab',
disabled: false,
allowCustomConnection: false,
customConnectionAllowed: false,
});
});

View File

@@ -17,7 +17,7 @@ describe('GET /api/v1/apps/:appKey/config', () => {
appConfig = await createAppConfig({
key: 'deepl',
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
disabled: false,
});

View File

@@ -0,0 +1,11 @@
export async function up(knex) {
return knex.schema.alterTable('app_configs', (table) => {
table.renameColumn('allow_custom_connection', 'custom_connection_allowed');
});
}
export async function down(knex) {
return knex.schema.alterTable('app_configs', (table) => {
table.renameColumn('custom_connection_allowed', 'allow_custom_connection');
});
}

View File

@@ -3,10 +3,6 @@
exports[`AppConfig model > jsonSchema should have correct validations 1`] = `
{
"properties": {
"allowCustomConnection": {
"default": false,
"type": "boolean",
},
"connectionAllowed": {
"default": false,
"type": "boolean",
@@ -14,6 +10,10 @@ exports[`AppConfig model > jsonSchema should have correct validations 1`] = `
"createdAt": {
"type": "string",
},
"customConnectionAllowed": {
"default": false,
"type": "boolean",
},
"disabled": {
"default": false,
"type": "boolean",
@@ -39,3 +39,5 @@ exports[`AppConfig model > jsonSchema should have correct validations 1`] = `
"type": "object",
}
`;
exports[`AppConfig model > virtualAttributes should return correct properties 1`] = `null`;

View File

@@ -13,7 +13,7 @@ class AppConfig extends Base {
id: { type: 'string', format: 'uuid' },
key: { type: 'string' },
connectionAllowed: { type: 'boolean', default: false },
allowCustomConnection: { type: 'boolean', default: false },
customConnectionAllowed: { type: 'boolean', default: false },
shared: { type: 'boolean', default: false },
disabled: { type: 'boolean', default: false },
createdAt: { type: 'string' },

View File

@@ -36,35 +36,6 @@ describe('AppConfig model', () => {
expect(AppConfig.virtualAttributes).toMatchSnapshot();
});
describe('allowCustomConnection', () => {
it('should return true when app is enabled and allows custom connection', async () => {
const appConfig = await createAppConfig({
disabled: false,
allowCustomConnection: true,
});
expect(appConfig.allowCustomConnection).toBe(true);
});
it('should return false when app is disabled', async () => {
const appConfig = await createAppConfig({
disabled: true,
allowCustomConnection: true,
});
expect(appConfig.allowCustomConnection).toBe(false);
});
it(`should return false when app doesn't allow custom connection`, async () => {
const appConfig = await createAppConfig({
disabled: false,
allowCustomConnection: false,
});
expect(appConfig.allowCustomConnection).toBe(false);
});
});
describe('connectionAllowed', () => {
it('should return true when app is enabled, shared and allows custom connection with an active app auth client at least', async () => {
await createAppAuthClient({
@@ -79,7 +50,7 @@ describe('AppConfig model', () => {
const appConfig = await createAppConfig({
disabled: false,
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
key: 'deepl',
});
@@ -95,7 +66,7 @@ describe('AppConfig model', () => {
const appConfig = await createAppConfig({
disabled: false,
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
key: 'deepl',
});
@@ -106,7 +77,7 @@ describe('AppConfig model', () => {
it('should return false when app is enabled, shared and allows custom connection without any app auth clients', async () => {
const appConfig = await createAppConfig({
disabled: false,
allowCustomConnection: true,
customConnectionAllowed: true,
shared: true,
key: 'deepl',
});
@@ -117,7 +88,7 @@ describe('AppConfig model', () => {
it('should return false when app is disabled', async () => {
const appConfig = await createAppConfig({
disabled: true,
allowCustomConnection: true,
customConnectionAllowed: true,
});
expect(appConfig.connectionAllowed).toBe(false);
@@ -126,7 +97,7 @@ describe('AppConfig model', () => {
it(`should return false when app doesn't allow custom connection`, async () => {
const appConfig = await createAppConfig({
disabled: false,
allowCustomConnection: false,
customConnectionAllowed: false,
});
expect(appConfig.connectionAllowed).toBe(false);

View File

@@ -89,7 +89,7 @@ class Connection extends Base {
}
if (this.appConfig) {
return !this.appConfig.disabled && this.appConfig.allowCustomConnection;
return !this.appConfig.disabled && this.appConfig.customConnectionAllowed;
}
return true;
@@ -144,7 +144,7 @@ class Connection extends Base {
);
}
if (!appConfig.allowCustomConnection && this.formattedData) {
if (!appConfig.customConnectionAllowed && this.formattedData) {
throw new NotAuthorizedError(
`New custom connections have been disabled for ${app.name}!`
);

View File

@@ -2,7 +2,7 @@ const appConfigSerializer = (appConfig) => {
return {
id: appConfig.id,
key: appConfig.key,
allowCustomConnection: appConfig.allowCustomConnection,
customConnectionAllowed: appConfig.customConnectionAllowed,
shared: appConfig.shared,
disabled: appConfig.disabled,
connectionAllowed: appConfig.connectionAllowed,

View File

@@ -13,7 +13,7 @@ describe('appConfig serializer', () => {
const expectedPayload = {
id: appConfig.id,
key: appConfig.key,
allowCustomConnection: appConfig.allowCustomConnection,
customConnectionAllowed: appConfig.customConnectionAllowed,
shared: appConfig.shared,
disabled: appConfig.disabled,
connectionAllowed: appConfig.connectionAllowed,

View File

@@ -2,7 +2,7 @@ const createAppConfigMock = (appConfig) => {
return {
data: {
key: appConfig.key,
allowCustomConnection: appConfig.allowCustomConnection,
customConnectionAllowed: appConfig.customConnectionAllowed,
shared: appConfig.shared,
disabled: appConfig.disabled,
},

View File

@@ -3,7 +3,7 @@ const getAppConfigMock = (appConfig) => {
data: {
id: appConfig.id,
key: appConfig.key,
allowCustomConnection: appConfig.allowCustomConnection,
customConnectionAllowed: appConfig.customConnectionAllowed,
shared: appConfig.shared,
disabled: appConfig.disabled,
connectionAllowed: appConfig.connectionAllowed,