refactor(app-config): rename canConnect as connectionAllowed
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
export async function up(knex) {
|
export async function up(knex) {
|
||||||
await knex.schema.alterTable('app_configs', (table) => {
|
await knex.schema.alterTable('app_configs', (table) => {
|
||||||
table.boolean('can_connect').defaultTo(false);
|
table.boolean('connectionAllowed').defaultTo(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
const appConfigs = await knex('app_configs').select('*');
|
const appConfigs = await knex('app_configs').select('*');
|
||||||
@@ -17,17 +17,21 @@ export async function up(knex) {
|
|||||||
const shared = appConfig.shared;
|
const shared = appConfig.shared;
|
||||||
const active = appConfig.disabled === false;
|
const active = appConfig.disabled === false;
|
||||||
|
|
||||||
const canConnectConditions = [hasSomeActiveAppAuthClients, shared, active];
|
const connectionAllowedConditions = [
|
||||||
const canConnect = canConnectConditions.every(Boolean);
|
hasSomeActiveAppAuthClients,
|
||||||
|
shared,
|
||||||
|
active,
|
||||||
|
];
|
||||||
|
const connectionAllowed = connectionAllowedConditions.every(Boolean);
|
||||||
|
|
||||||
await knex('app_configs')
|
await knex('app_configs')
|
||||||
.where('id', appConfig.id)
|
.where('id', appConfig.id)
|
||||||
.update({ can_connect: canConnect });
|
.update({ connection_allowed: connectionAllowed });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(knex) {
|
export async function down(knex) {
|
||||||
await knex.schema.alterTable('app_configs', (table) => {
|
await knex.schema.alterTable('app_configs', (table) => {
|
||||||
table.dropColumn('can_connect');
|
table.dropColumn('connectionAllowed');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ exports[`AppConfig model > jsonSchema should have correct validations 1`] = `
|
|||||||
"default": false,
|
"default": false,
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
},
|
},
|
||||||
"canConnect": {
|
"connectionAllowed": {
|
||||||
"default": false,
|
"default": false,
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
},
|
},
|
||||||
|
@@ -63,7 +63,7 @@ class AppAuthClient extends Base {
|
|||||||
async triggerAppConfigUpdate() {
|
async triggerAppConfigUpdate() {
|
||||||
const appConfig = await this.$relatedQuery('appConfig').select('*');
|
const appConfig = await this.$relatedQuery('appConfig').select('*');
|
||||||
|
|
||||||
await appConfig?.updateCanConnectProperty();
|
await appConfig?.updateConnectionAllowedProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make another abstraction like beforeSave instead of using
|
// TODO: Make another abstraction like beforeSave instead of using
|
||||||
|
@@ -12,7 +12,7 @@ class AppConfig extends Base {
|
|||||||
properties: {
|
properties: {
|
||||||
id: { type: 'string', format: 'uuid' },
|
id: { type: 'string', format: 'uuid' },
|
||||||
key: { type: 'string' },
|
key: { type: 'string' },
|
||||||
canConnect: { type: 'boolean', default: false },
|
connectionAllowed: { type: 'boolean', default: false },
|
||||||
allowCustomConnection: { type: 'boolean', default: false },
|
allowCustomConnection: { type: 'boolean', default: false },
|
||||||
shared: { type: 'boolean', default: false },
|
shared: { type: 'boolean', default: false },
|
||||||
disabled: { type: 'boolean', default: false },
|
disabled: { type: 'boolean', default: false },
|
||||||
@@ -46,7 +46,7 @@ class AppConfig extends Base {
|
|||||||
return await App.findOneByKey(this.key);
|
return await App.findOneByKey(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async computeCanConnectProperty(oldAppConfig) {
|
async computeConnectionAllowedProperty(oldAppConfig) {
|
||||||
const appAuthClients = await oldAppConfig.$relatedQuery('appAuthClients');
|
const appAuthClients = await oldAppConfig.$relatedQuery('appAuthClients');
|
||||||
const hasSomeActiveAppAuthClients = !!appAuthClients?.some(
|
const hasSomeActiveAppAuthClients = !!appAuthClients?.some(
|
||||||
(appAuthClient) => appAuthClient.active
|
(appAuthClient) => appAuthClient.active
|
||||||
@@ -57,27 +57,29 @@ class AppConfig extends Base {
|
|||||||
|
|
||||||
const conditions = [hasSomeActiveAppAuthClients, shared, active];
|
const conditions = [hasSomeActiveAppAuthClients, shared, active];
|
||||||
|
|
||||||
const canConnect = conditions.every(Boolean);
|
const connectionAllowed = conditions.every(Boolean);
|
||||||
|
|
||||||
return canConnect;
|
return connectionAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateCanConnectProperty() {
|
async updateConnectionAllowedProperty() {
|
||||||
const canConnect = await this.computeCanConnectProperty(this);
|
const connectionAllowed = await this.computeConnectionAllowedProperty(this);
|
||||||
|
|
||||||
return await this.$query().patch({
|
return await this.$query().patch({
|
||||||
canConnect,
|
connectionAllowed,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async computeAndAssignCanConnectProperty(oldAppConfig) {
|
async computeAndAssignConnectionAllowedProperty(oldAppConfig) {
|
||||||
this.canConnect = await this.computeCanConnectProperty(oldAppConfig);
|
this.connectionAllowed = await this.computeConnectionAllowedProperty(
|
||||||
|
oldAppConfig
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async $beforeInsert(queryContext) {
|
async $beforeInsert(queryContext) {
|
||||||
await super.$beforeInsert(queryContext);
|
await super.$beforeInsert(queryContext);
|
||||||
|
|
||||||
await this.computeAndAssignCanConnectProperty(this);
|
await this.computeAndAssignConnectionAllowedProperty(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async $beforeUpdate(opt, queryContext) {
|
async $beforeUpdate(opt, queryContext) {
|
||||||
@@ -85,7 +87,7 @@ class AppConfig extends Base {
|
|||||||
|
|
||||||
const oldAppConfig = opt.old;
|
const oldAppConfig = opt.old;
|
||||||
|
|
||||||
await this.computeAndAssignCanConnectProperty(oldAppConfig);
|
await this.computeAndAssignConnectionAllowedProperty(oldAppConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 () => {
|
it('should return true when app is enabled, shared and allows custom connection with an active app auth client at least', async () => {
|
||||||
await createAppAuthClient({
|
await createAppAuthClient({
|
||||||
appKey: 'deepl',
|
appKey: 'deepl',
|
||||||
@@ -84,7 +84,7 @@ describe('AppConfig model', () => {
|
|||||||
key: 'deepl',
|
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 () => {
|
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',
|
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 () => {
|
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',
|
key: 'deepl',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(appConfig.canConnect).toBe(false);
|
expect(appConfig.connectionAllowed).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when app is disabled', async () => {
|
it('should return false when app is disabled', async () => {
|
||||||
@@ -120,7 +120,7 @@ describe('AppConfig model', () => {
|
|||||||
allowCustomConnection: true,
|
allowCustomConnection: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(appConfig.canConnect).toBe(false);
|
expect(appConfig.connectionAllowed).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return false when app doesn't allow custom connection`, async () => {
|
it(`should return false when app doesn't allow custom connection`, async () => {
|
||||||
@@ -129,7 +129,7 @@ describe('AppConfig model', () => {
|
|||||||
allowCustomConnection: false,
|
allowCustomConnection: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(appConfig.canConnect).toBe(false);
|
expect(appConfig.connectionAllowed).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ const appConfigSerializer = (appConfig) => {
|
|||||||
allowCustomConnection: appConfig.allowCustomConnection,
|
allowCustomConnection: appConfig.allowCustomConnection,
|
||||||
shared: appConfig.shared,
|
shared: appConfig.shared,
|
||||||
disabled: appConfig.disabled,
|
disabled: appConfig.disabled,
|
||||||
canConnect: appConfig.canConnect,
|
connectionAllowed: appConfig.connectionAllowed,
|
||||||
canCustomConnect: appConfig.canCustomConnect,
|
canCustomConnect: appConfig.canCustomConnect,
|
||||||
createdAt: appConfig.createdAt.getTime(),
|
createdAt: appConfig.createdAt.getTime(),
|
||||||
updatedAt: appConfig.updatedAt.getTime(),
|
updatedAt: appConfig.updatedAt.getTime(),
|
||||||
|
@@ -16,7 +16,7 @@ describe('appConfig serializer', () => {
|
|||||||
allowCustomConnection: appConfig.allowCustomConnection,
|
allowCustomConnection: appConfig.allowCustomConnection,
|
||||||
shared: appConfig.shared,
|
shared: appConfig.shared,
|
||||||
disabled: appConfig.disabled,
|
disabled: appConfig.disabled,
|
||||||
canConnect: appConfig.canConnect,
|
connectionAllowed: appConfig.connectionAllowed,
|
||||||
canCustomConnect: appConfig.canCustomConnect,
|
canCustomConnect: appConfig.canCustomConnect,
|
||||||
createdAt: appConfig.createdAt.getTime(),
|
createdAt: appConfig.createdAt.getTime(),
|
||||||
updatedAt: appConfig.updatedAt.getTime(),
|
updatedAt: appConfig.updatedAt.getTime(),
|
||||||
|
@@ -6,7 +6,7 @@ const getAppConfigMock = (appConfig) => {
|
|||||||
allowCustomConnection: appConfig.allowCustomConnection,
|
allowCustomConnection: appConfig.allowCustomConnection,
|
||||||
shared: appConfig.shared,
|
shared: appConfig.shared,
|
||||||
disabled: appConfig.disabled,
|
disabled: appConfig.disabled,
|
||||||
canConnect: appConfig.canConnect,
|
connectionAllowed: appConfig.connectionAllowed,
|
||||||
canCustomConnect: appConfig.canCustomConnect,
|
canCustomConnect: appConfig.canCustomConnect,
|
||||||
createdAt: appConfig.createdAt.getTime(),
|
createdAt: appConfig.createdAt.getTime(),
|
||||||
updatedAt: appConfig.updatedAt.getTime(),
|
updatedAt: appConfig.updatedAt.getTime(),
|
||||||
|
@@ -100,7 +100,7 @@ function ChooseConnectionSubstep(props) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appConfig?.data?.canConnect) {
|
if (appConfig?.data?.connectionAllowed) {
|
||||||
options.push({
|
options.push({
|
||||||
label: formatMessage('chooseConnectionSubstep.addNewSharedConnection'),
|
label: formatMessage('chooseConnectionSubstep.addNewSharedConnection'),
|
||||||
value: ADD_SHARED_CONNECTION_VALUE,
|
value: ADD_SHARED_CONNECTION_VALUE,
|
||||||
|
@@ -77,14 +77,14 @@ export default function Application() {
|
|||||||
|
|
||||||
const connectionOptions = React.useMemo(() => {
|
const connectionOptions = React.useMemo(() => {
|
||||||
const shouldHaveCustomConnection =
|
const shouldHaveCustomConnection =
|
||||||
appConfig?.data?.canConnect && appConfig?.data?.canCustomConnect;
|
appConfig?.data?.connectionAllowed && appConfig?.data?.canCustomConnect;
|
||||||
|
|
||||||
const options = [
|
const options = [
|
||||||
{
|
{
|
||||||
label: formatMessage('app.addConnection'),
|
label: formatMessage('app.addConnection'),
|
||||||
key: 'addConnection',
|
key: 'addConnection',
|
||||||
'data-test': 'add-connection-button',
|
'data-test': 'add-connection-button',
|
||||||
to: URLS.APP_ADD_CONNECTION(appKey, appConfig?.data?.canConnect),
|
to: URLS.APP_ADD_CONNECTION(appKey, appConfig?.data?.connectionAllowed),
|
||||||
disabled: !currentUserAbility.can('create', 'Connection'),
|
disabled: !currentUserAbility.can('create', 'Connection'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -155,7 +155,7 @@ export default function Application() {
|
|||||||
disabled={
|
disabled={
|
||||||
!allowed ||
|
!allowed ||
|
||||||
(appConfig?.data &&
|
(appConfig?.data &&
|
||||||
!appConfig?.data?.canConnect &&
|
!appConfig?.data?.connectionAllowed &&
|
||||||
!appConfig?.data?.canCustomConnect) ||
|
!appConfig?.data?.canCustomConnect) ||
|
||||||
connectionOptions.every(({ disabled }) => disabled)
|
connectionOptions.every(({ disabled }) => disabled)
|
||||||
}
|
}
|
||||||
|
@@ -460,7 +460,7 @@ export const AppConfigPropType = PropTypes.shape({
|
|||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
key: PropTypes.string,
|
key: PropTypes.string,
|
||||||
allowCustomConnection: PropTypes.bool,
|
allowCustomConnection: PropTypes.bool,
|
||||||
canConnect: PropTypes.bool,
|
connectionAllowed: PropTypes.bool,
|
||||||
canCustomConnect: PropTypes.bool,
|
canCustomConnect: PropTypes.bool,
|
||||||
shared: PropTypes.bool,
|
shared: PropTypes.bool,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
Reference in New Issue
Block a user