refactor(app-config): rename canConnect as connectionAllowed

This commit is contained in:
Ali BARIN
2024-10-09 08:48:53 +00:00
committed by Faruk AYDIN
parent aed61209fa
commit 6e42b52414
11 changed files with 38 additions and 32 deletions

View File

@@ -7,7 +7,7 @@ exports[`AppConfig model > jsonSchema should have correct validations 1`] = `
"default": false,
"type": "boolean",
},
"canConnect": {
"connectionAllowed": {
"default": false,
"type": "boolean",
},

View File

@@ -63,7 +63,7 @@ class AppAuthClient extends Base {
async triggerAppConfigUpdate() {
const appConfig = await this.$relatedQuery('appConfig').select('*');
await appConfig?.updateCanConnectProperty();
await appConfig?.updateConnectionAllowedProperty();
}
// TODO: Make another abstraction like beforeSave instead of using

View File

@@ -12,7 +12,7 @@ class AppConfig extends Base {
properties: {
id: { type: 'string', format: 'uuid' },
key: { type: 'string' },
canConnect: { type: 'boolean', default: false },
connectionAllowed: { type: 'boolean', default: false },
allowCustomConnection: { type: 'boolean', default: false },
shared: { type: 'boolean', default: false },
disabled: { type: 'boolean', default: false },
@@ -46,7 +46,7 @@ class AppConfig extends Base {
return await App.findOneByKey(this.key);
}
async computeCanConnectProperty(oldAppConfig) {
async computeConnectionAllowedProperty(oldAppConfig) {
const appAuthClients = await oldAppConfig.$relatedQuery('appAuthClients');
const hasSomeActiveAppAuthClients = !!appAuthClients?.some(
(appAuthClient) => appAuthClient.active
@@ -57,27 +57,29 @@ class AppConfig extends Base {
const conditions = [hasSomeActiveAppAuthClients, shared, active];
const canConnect = conditions.every(Boolean);
const connectionAllowed = conditions.every(Boolean);
return canConnect;
return connectionAllowed;
}
async updateCanConnectProperty() {
const canConnect = await this.computeCanConnectProperty(this);
async updateConnectionAllowedProperty() {
const connectionAllowed = await this.computeConnectionAllowedProperty(this);
return await this.$query().patch({
canConnect,
connectionAllowed,
});
}
async computeAndAssignCanConnectProperty(oldAppConfig) {
this.canConnect = await this.computeCanConnectProperty(oldAppConfig);
async computeAndAssignConnectionAllowedProperty(oldAppConfig) {
this.connectionAllowed = await this.computeConnectionAllowedProperty(
oldAppConfig
);
}
async $beforeInsert(queryContext) {
await super.$beforeInsert(queryContext);
await this.computeAndAssignCanConnectProperty(this);
await this.computeAndAssignConnectionAllowedProperty(this);
}
async $beforeUpdate(opt, queryContext) {
@@ -85,7 +87,7 @@ class AppConfig extends Base {
const oldAppConfig = opt.old;
await this.computeAndAssignCanConnectProperty(oldAppConfig);
await this.computeAndAssignConnectionAllowedProperty(oldAppConfig);
}
}

View File

@@ -65,7 +65,7 @@ describe('AppConfig model', () => {
});
});
describe('canConnect', () => {
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({
appKey: 'deepl',
@@ -84,7 +84,7 @@ describe('AppConfig model', () => {
key: 'deepl',
});
expect(appConfig.canConnect).toBe(true);
expect(appConfig.connectionAllowed).toBe(true);
});
it('should return true when app is enabled, shared and allows custom connection with no active app auth client', async () => {
@@ -100,7 +100,7 @@ describe('AppConfig model', () => {
key: 'deepl',
});
expect(appConfig.canConnect).toBe(false);
expect(appConfig.connectionAllowed).toBe(false);
});
it('should return false when app is enabled, shared and allows custom connection without any app auth clients', async () => {
@@ -111,7 +111,7 @@ describe('AppConfig model', () => {
key: 'deepl',
});
expect(appConfig.canConnect).toBe(false);
expect(appConfig.connectionAllowed).toBe(false);
});
it('should return false when app is disabled', async () => {
@@ -120,7 +120,7 @@ describe('AppConfig model', () => {
allowCustomConnection: true,
});
expect(appConfig.canConnect).toBe(false);
expect(appConfig.connectionAllowed).toBe(false);
});
it(`should return false when app doesn't allow custom connection`, async () => {
@@ -129,7 +129,7 @@ describe('AppConfig model', () => {
allowCustomConnection: false,
});
expect(appConfig.canConnect).toBe(false);
expect(appConfig.connectionAllowed).toBe(false);
});
});