Compare commits
17 Commits
AUT-996
...
static-can
Author | SHA1 | Date | |
---|---|---|---|
![]() |
40636119fb | ||
![]() |
beb3b2cf45 | ||
![]() |
c2375ed3d4 | ||
![]() |
4942cf8dae | ||
![]() |
8f444eafa7 | ||
![]() |
2484a0e631 | ||
![]() |
d3747ad050 | ||
![]() |
bb68a75636 | ||
![]() |
98131d633e | ||
![]() |
e8193e0e17 | ||
![]() |
74b7dd8f34 | ||
![]() |
4f500e2d04 | ||
![]() |
b53ddca8ce | ||
![]() |
70f30034ab | ||
![]() |
fcd83909f7 | ||
![]() |
eadb472af9 | ||
![]() |
600316577e |
@@ -1,52 +0,0 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import Crypto from 'crypto';
|
|
||||||
import app from '../../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import getAdminAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/app-auth-clients/get-app-auth-client.js';
|
|
||||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
|
||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/app-auth-clients/:appAuthClientId', () => {
|
|
||||||
let currentUser, currentUserRole, currentAppAuthClient, token;
|
|
||||||
|
|
||||||
describe('with valid license key', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
|
||||||
currentAppAuthClient = await createAppAuthClient();
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/admin/app-auth-clients/${currentAppAuthClient.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getAdminAppAuthClientMock(currentAppAuthClient);
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return not found response for not existing app auth client UUID', async () => {
|
|
||||||
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
|
||||||
|
|
||||||
await request(app)
|
|
||||||
.get(`/api/v1/admin/app-auth-clients/${notExistingAppAuthClientUUID}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(404);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
|
||||||
await request(app)
|
|
||||||
.get('/api/v1/admin/app-auth-clients/invalidAppAuthClientUUID')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(400);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -1,41 +0,0 @@
|
|||||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
|
||||||
import { createUser } from '../../../../../../test/factories/user.js';
|
|
||||||
import getAdminAppAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/app-auth-clients/get-app-auth-clients.js';
|
|
||||||
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
|
||||||
import { createRole } from '../../../../../../test/factories/role.js';
|
|
||||||
import * as license from '../../../../../helpers/license.ee.js';
|
|
||||||
|
|
||||||
describe('GET /api/v1/admin/app-auth-clients', () => {
|
|
||||||
let currentUser, currentUserRole, token;
|
|
||||||
|
|
||||||
describe('with valid license key', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
|
||||||
|
|
||||||
currentUserRole = await createRole({ key: 'admin' });
|
|
||||||
currentUser = await createUser({ roleId: currentUserRole.id });
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return app auth clients', async () => {
|
|
||||||
const appAuthClientOne = await createAppAuthClient();
|
|
||||||
const appAuthClientTwo = await createAppAuthClient();
|
|
||||||
|
|
||||||
const response = await request(app)
|
|
||||||
.get('/api/v1/admin/app-auth-clients')
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getAdminAppAuthClientsMock([
|
|
||||||
appAuthClientTwo,
|
|
||||||
appAuthClientOne,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@@ -4,6 +4,7 @@ import AppAuthClient from '../../../../../models/app-auth-client.js';
|
|||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClient = await AppAuthClient.query()
|
const appAuthClient = await AppAuthClient.query()
|
||||||
.findById(request.params.appAuthClientId)
|
.findById(request.params.appAuthClientId)
|
||||||
|
.where({ app_key: request.params.appKey })
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
renderObject(response, appAuthClient);
|
renderObject(response, appAuthClient);
|
@@ -0,0 +1,55 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import Crypto from 'crypto';
|
||||||
|
import app from '../../../../../app.js';
|
||||||
|
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
|
import { createUser } from '../../../../../../test/factories/user.js';
|
||||||
|
import { createRole } from '../../../../../../test/factories/role.js';
|
||||||
|
import getAppAuthClientMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-client.js';
|
||||||
|
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||||
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/admin/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||||
|
let currentUser, adminRole, currentAppAuthClient, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
adminRole = await createRole({ key: 'admin' });
|
||||||
|
currentUser = await createUser({ roleId: adminRole.id });
|
||||||
|
|
||||||
|
currentAppAuthClient = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified app auth client', async () => {
|
||||||
|
const response = await request(app)
|
||||||
|
.get(`/api/v1/admin/apps/deepl/auth-clients/${currentAppAuthClient.id}`)
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getAppAuthClientMock(currentAppAuthClient);
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return not found response for not existing app auth client ID', async () => {
|
||||||
|
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
||||||
|
|
||||||
|
await request(app)
|
||||||
|
.get(
|
||||||
|
`/api/v1/admin/apps/deepl/auth-clients/${notExistingAppAuthClientUUID}`
|
||||||
|
)
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return bad request response for invalid UUID', async () => {
|
||||||
|
await request(app)
|
||||||
|
.get('/api/v1/admin/apps/deepl/auth-clients/invalidAppAuthClientUUID')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
|
});
|
@@ -2,10 +2,9 @@ import { renderObject } from '../../../../../helpers/renderer.js';
|
|||||||
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
import AppAuthClient from '../../../../../models/app-auth-client.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClients = await AppAuthClient.query().orderBy(
|
const appAuthClients = await AppAuthClient.query()
|
||||||
'created_at',
|
.where({ app_key: request.params.appKey })
|
||||||
'desc'
|
.orderBy('created_at', 'desc');
|
||||||
);
|
|
||||||
|
|
||||||
renderObject(response, appAuthClients);
|
renderObject(response, appAuthClients);
|
||||||
};
|
};
|
@@ -0,0 +1,44 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import app from '../../../../../app.js';
|
||||||
|
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
|
import { createUser } from '../../../../../../test/factories/user.js';
|
||||||
|
import { createRole } from '../../../../../../test/factories/role.js';
|
||||||
|
import getAuthClientsMock from '../../../../../../test/mocks/rest/api/v1/admin/apps/get-auth-clients.js';
|
||||||
|
import { createAppAuthClient } from '../../../../../../test/factories/app-auth-client.js';
|
||||||
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/admin/apps/:appKey/auth-clients', () => {
|
||||||
|
let currentUser, adminRole, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
adminRole = await createRole({ key: 'admin' });
|
||||||
|
currentUser = await createUser({ roleId: adminRole.id });
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified app auth client info', async () => {
|
||||||
|
const appAuthClientOne = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const appAuthClientTwo = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get('/api/v1/admin/apps/deepl/auth-clients')
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getAuthClientsMock([
|
||||||
|
appAuthClientTwo,
|
||||||
|
appAuthClientOne,
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -4,7 +4,7 @@ import AppAuthClient from '../../../../models/app-auth-client.js';
|
|||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClient = await AppAuthClient.query()
|
const appAuthClient = await AppAuthClient.query()
|
||||||
.findById(request.params.appAuthClientId)
|
.findById(request.params.appAuthClientId)
|
||||||
.where({ active: true })
|
.where({ app_key: request.params.appKey, active: true })
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
renderObject(response, appAuthClient);
|
renderObject(response, appAuthClient);
|
@@ -4,25 +4,27 @@ import Crypto from 'crypto';
|
|||||||
import app from '../../../../app.js';
|
import app from '../../../../app.js';
|
||||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
|
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
import { createUser } from '../../../../../test/factories/user.js';
|
import { createUser } from '../../../../../test/factories/user.js';
|
||||||
import getAppAuthClientMock from '../../../../../test/mocks/rest/api/v1/app-auth-clients/get-app-auth-client.js';
|
import getAppAuthClientMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth-client.js';
|
||||||
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/app-auth-clients/:id', () => {
|
describe('GET /api/v1/apps/:appKey/auth-clients/:appAuthClientId', () => {
|
||||||
let currentUser, currentAppAuthClient, token;
|
let currentUser, currentAppAuthClient, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
currentUser = await createUser();
|
currentUser = await createUser();
|
||||||
currentAppAuthClient = await createAppAuthClient();
|
currentAppAuthClient = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
it('should return specified app auth client', async () => {
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get(`/api/v1/app-auth-clients/${currentAppAuthClient.id}`)
|
.get(`/api/v1/apps/deepl/auth-clients/${currentAppAuthClient.id}`)
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
@@ -34,14 +36,14 @@ describe('GET /api/v1/app-auth-clients/:id', () => {
|
|||||||
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
const notExistingAppAuthClientUUID = Crypto.randomUUID();
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.get(`/api/v1/app-auth-clients/${notExistingAppAuthClientUUID}`)
|
.get(`/api/v1/apps/deepl/auth-clients/${notExistingAppAuthClientUUID}`)
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return bad request response for invalid UUID', async () => {
|
it('should return bad request response for invalid UUID', async () => {
|
||||||
await request(app)
|
await request(app)
|
||||||
.get('/api/v1/app-auth-clients/invalidAppAuthClientUUID')
|
.get('/api/v1/apps/deepl/auth-clients/invalidAppAuthClientUUID')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(400);
|
.expect(400);
|
||||||
});
|
});
|
@@ -3,7 +3,7 @@ import AppAuthClient from '../../../../models/app-auth-client.js';
|
|||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const appAuthClients = await AppAuthClient.query()
|
const appAuthClients = await AppAuthClient.query()
|
||||||
.where({ active: true })
|
.where({ app_key: request.params.appKey, active: true })
|
||||||
.orderBy('created_at', 'desc');
|
.orderBy('created_at', 'desc');
|
||||||
|
|
||||||
renderObject(response, appAuthClients);
|
renderObject(response, appAuthClients);
|
@@ -3,11 +3,11 @@ import request from 'supertest';
|
|||||||
import app from '../../../../app.js';
|
import app from '../../../../app.js';
|
||||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
|
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id.js';
|
||||||
import { createUser } from '../../../../../test/factories/user.js';
|
import { createUser } from '../../../../../test/factories/user.js';
|
||||||
import getAppAuthClientsMock from '../../../../../test/mocks/rest/api/v1/app-auth-clients/get-app-auth-clients.js';
|
import getAuthClientsMock from '../../../../../test/mocks/rest/api/v1/apps/get-auth-clients.js';
|
||||||
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
import { createAppAuthClient } from '../../../../../test/factories/app-auth-client.js';
|
||||||
import * as license from '../../../../helpers/license.ee.js';
|
import * as license from '../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
describe('GET /api/v1/app-auth-clients', () => {
|
describe('GET /api/v1/apps/:appKey/auth-clients', () => {
|
||||||
let currentUser, token;
|
let currentUser, token;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -19,15 +19,20 @@ describe('GET /api/v1/app-auth-clients', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return specified app auth client info', async () => {
|
it('should return specified app auth client info', async () => {
|
||||||
const appAuthClientOne = await createAppAuthClient();
|
const appAuthClientOne = await createAppAuthClient({
|
||||||
const appAuthClientTwo = await createAppAuthClient();
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
|
const appAuthClientTwo = await createAppAuthClient({
|
||||||
|
appKey: 'deepl',
|
||||||
|
});
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.get('/api/v1/app-auth-clients')
|
.get('/api/v1/apps/deepl/auth-clients')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
const expectedPayload = getAppAuthClientsMock([
|
const expectedPayload = getAuthClientsMock([
|
||||||
appAuthClientTwo,
|
appAuthClientTwo,
|
||||||
appAuthClientOne,
|
appAuthClientOne,
|
||||||
]);
|
]);
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.string('app_key');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.dropColumn('app_key');
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
const appAuthClients = await knex('app_auth_clients').select('*');
|
||||||
|
|
||||||
|
for (const appAuthClient of appAuthClients) {
|
||||||
|
const appConfig = await knex('app_configs')
|
||||||
|
.where('id', appAuthClient.app_config_id)
|
||||||
|
.first();
|
||||||
|
|
||||||
|
await knex('app_auth_clients')
|
||||||
|
.where('id', appAuthClient.id)
|
||||||
|
.update({ app_key: appConfig.key });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down() {
|
||||||
|
// void
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.dropColumn('app_config_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table
|
||||||
|
.uuid('app_config_id')
|
||||||
|
.notNullable()
|
||||||
|
.references('id')
|
||||||
|
.inTable('app_configs');
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.string('app_key').notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_auth_clients', (table) => {
|
||||||
|
table.string('app_key').nullable().alter();
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
export async function up(knex) {
|
||||||
|
await knex.schema.table('app_configs', (table) => {
|
||||||
|
table.boolean('can_connect').defaultTo(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex) {
|
||||||
|
await knex.schema.table('app_configs', (table) => {
|
||||||
|
table.dropColumn('can_connect');
|
||||||
|
});
|
||||||
|
}
|
@@ -9,11 +9,11 @@ class AppAuthClient extends Base {
|
|||||||
|
|
||||||
static jsonSchema = {
|
static jsonSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['name', 'appConfigId', 'formattedAuthDefaults'],
|
required: ['name', 'appKey', 'formattedAuthDefaults'],
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
id: { type: 'string', format: 'uuid' },
|
id: { type: 'string', format: 'uuid' },
|
||||||
appConfigId: { type: 'string', format: 'uuid' },
|
appKey: { type: 'string' },
|
||||||
active: { type: 'boolean' },
|
active: { type: 'boolean' },
|
||||||
authDefaults: { type: ['string', 'null'] },
|
authDefaults: { type: ['string', 'null'] },
|
||||||
formattedAuthDefaults: { type: 'object' },
|
formattedAuthDefaults: { type: 'object' },
|
||||||
@@ -22,17 +22,6 @@ class AppAuthClient extends Base {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static relationMappings = () => ({
|
|
||||||
appConfig: {
|
|
||||||
relation: Base.BelongsToOneRelation,
|
|
||||||
modelClass: AppConfig,
|
|
||||||
join: {
|
|
||||||
from: 'app_auth_clients.app_config_id',
|
|
||||||
to: 'app_configs.id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
encryptData() {
|
encryptData() {
|
||||||
if (!this.eligibleForEncryption()) return;
|
if (!this.eligibleForEncryption()) return;
|
||||||
|
|
||||||
@@ -71,6 +60,21 @@ class AppAuthClient extends Base {
|
|||||||
this.encryptData();
|
this.encryptData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async assignCanConnectForAppConfig() {
|
||||||
|
const appConfig = await AppConfig.query().findOne({ key: this.appKey });
|
||||||
|
await appConfig?.assignCanConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
async $afterInsert(queryContext) {
|
||||||
|
await super.$afterInsert(queryContext);
|
||||||
|
await this.assignCanConnectForAppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
async $afterUpdate(opt, queryContext) {
|
||||||
|
await super.$afterUpdate(opt, queryContext);
|
||||||
|
await this.assignCanConnectForAppConfig();
|
||||||
|
}
|
||||||
|
|
||||||
async $afterFind() {
|
async $afterFind() {
|
||||||
this.decryptData();
|
this.decryptData();
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import App from './app.js';
|
import App from './app.js';
|
||||||
import Base from './base.js';
|
|
||||||
import AppAuthClient from './app-auth-client.js';
|
import AppAuthClient from './app-auth-client.js';
|
||||||
|
import Base from './base.js';
|
||||||
|
|
||||||
class AppConfig extends Base {
|
class AppConfig extends Base {
|
||||||
static tableName = 'app_configs';
|
static tableName = 'app_configs';
|
||||||
@@ -15,45 +15,48 @@ class AppConfig extends Base {
|
|||||||
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 },
|
||||||
|
canConnect: { type: 'boolean', default: false },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static get virtualAttributes() {
|
|
||||||
return ['canConnect', 'canCustomConnect'];
|
|
||||||
}
|
|
||||||
|
|
||||||
static relationMappings = () => ({
|
|
||||||
appAuthClients: {
|
|
||||||
relation: Base.HasManyRelation,
|
|
||||||
modelClass: AppAuthClient,
|
|
||||||
join: {
|
|
||||||
from: 'app_configs.id',
|
|
||||||
to: 'app_auth_clients.app_config_id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
get canCustomConnect() {
|
|
||||||
return !this.disabled && this.allowCustomConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
get canConnect() {
|
|
||||||
const hasSomeActiveAppAuthClients = !!this.appAuthClients?.some(
|
|
||||||
(appAuthClient) => appAuthClient.active
|
|
||||||
);
|
|
||||||
const shared = this.shared;
|
|
||||||
const active = this.disabled === false;
|
|
||||||
|
|
||||||
const conditions = [hasSomeActiveAppAuthClients, shared, active];
|
|
||||||
|
|
||||||
return conditions.every(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getApp() {
|
async getApp() {
|
||||||
if (!this.key) return null;
|
if (!this.key) return null;
|
||||||
|
|
||||||
return await App.findOneByKey(this.key);
|
return await App.findOneByKey(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async hasActiveAppAuthClients() {
|
||||||
|
const appAuthClients = await AppAuthClient.query().where({
|
||||||
|
appKey: this.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasSomeActiveAppAuthClients = !!appAuthClients?.some(
|
||||||
|
(appAuthClient) => appAuthClient.active
|
||||||
|
);
|
||||||
|
|
||||||
|
return hasSomeActiveAppAuthClients;
|
||||||
|
}
|
||||||
|
|
||||||
|
async assignCanConnect() {
|
||||||
|
const shared = this.shared;
|
||||||
|
const active = this.disabled === false;
|
||||||
|
const hasSomeActiveAppAuthClients = await this.hasActiveAppAuthClients();
|
||||||
|
|
||||||
|
const conditions = [hasSomeActiveAppAuthClients, shared, active];
|
||||||
|
const canConnect = conditions.every(Boolean);
|
||||||
|
|
||||||
|
this.canConnect = canConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
async $beforeInsert(queryContext) {
|
||||||
|
await super.$beforeInsert(queryContext);
|
||||||
|
await this.assignCanConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
async $beforeUpdate(opt, queryContext) {
|
||||||
|
await super.$beforeUpdate(opt, queryContext);
|
||||||
|
await this.assignCanConnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AppConfig;
|
export default AppConfig;
|
||||||
|
@@ -3,25 +3,25 @@ import asyncHandler from 'express-async-handler';
|
|||||||
import { authenticateUser } from '../../../../helpers/authentication.js';
|
import { authenticateUser } from '../../../../helpers/authentication.js';
|
||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
||||||
import getAdminAppAuthClientsAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-clients.ee.js';
|
import getAuthClientsAction from '../../../../controllers/api/v1/admin/apps/get-auth-clients.ee.js';
|
||||||
import getAdminAppAuthClientAction from '../../../../controllers/api/v1/admin/app-auth-clients/get-app-auth-client.ee.js';
|
import getAuthClientAction from '../../../../controllers/api/v1/admin/apps/get-auth-client.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/:appKey/auth-clients',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
authorizeAdmin,
|
authorizeAdmin,
|
||||||
checkIsEnterprise,
|
checkIsEnterprise,
|
||||||
asyncHandler(getAdminAppAuthClientsAction)
|
asyncHandler(getAuthClientsAction)
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:appAuthClientId',
|
'/:appKey/auth-clients/:appAuthClientId',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
authorizeAdmin,
|
authorizeAdmin,
|
||||||
checkIsEnterprise,
|
checkIsEnterprise,
|
||||||
asyncHandler(getAdminAppAuthClientAction)
|
asyncHandler(getAuthClientAction)
|
||||||
);
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
@@ -1,24 +0,0 @@
|
|||||||
import { Router } from 'express';
|
|
||||||
import asyncHandler from 'express-async-handler';
|
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
|
||||||
import { checkIsEnterprise } from '../../../helpers/check-is-enterprise.js';
|
|
||||||
import getAppAuthClientAction from '../../../controllers/api/v1/app-auth-clients/get-app-auth-client.js';
|
|
||||||
import getAppAuthClientsAction from '../../../controllers/api/v1/app-auth-clients/get-app-auth-clients.js';
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAppAuthClientsAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
'/:appAuthClientId',
|
|
||||||
authenticateUser,
|
|
||||||
checkIsEnterprise,
|
|
||||||
asyncHandler(getAppAuthClientAction)
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
@@ -7,6 +7,8 @@ import getAppAction from '../../../controllers/api/v1/apps/get-app.js';
|
|||||||
import getAppsAction from '../../../controllers/api/v1/apps/get-apps.js';
|
import getAppsAction from '../../../controllers/api/v1/apps/get-apps.js';
|
||||||
import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js';
|
import getAuthAction from '../../../controllers/api/v1/apps/get-auth.js';
|
||||||
import getConfigAction from '../../../controllers/api/v1/apps/get-config.ee.js';
|
import getConfigAction from '../../../controllers/api/v1/apps/get-config.ee.js';
|
||||||
|
import getAuthClientsAction from '../../../controllers/api/v1/apps/get-auth-clients.ee.js';
|
||||||
|
import getAuthClientAction from '../../../controllers/api/v1/apps/get-auth-client.ee.js';
|
||||||
import getTriggersAction from '../../../controllers/api/v1/apps/get-triggers.js';
|
import getTriggersAction from '../../../controllers/api/v1/apps/get-triggers.js';
|
||||||
import getTriggerSubstepsAction from '../../../controllers/api/v1/apps/get-trigger-substeps.js';
|
import getTriggerSubstepsAction from '../../../controllers/api/v1/apps/get-trigger-substeps.js';
|
||||||
import getActionsAction from '../../../controllers/api/v1/apps/get-actions.js';
|
import getActionsAction from '../../../controllers/api/v1/apps/get-actions.js';
|
||||||
@@ -26,6 +28,20 @@ router.get(
|
|||||||
asyncHandler(getConfigAction)
|
asyncHandler(getConfigAction)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/auth-clients',
|
||||||
|
authenticateUser,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getAuthClientsAction)
|
||||||
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:appKey/auth-clients/:appAuthClientId',
|
||||||
|
authenticateUser,
|
||||||
|
checkIsEnterprise,
|
||||||
|
asyncHandler(getAuthClientAction)
|
||||||
|
);
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:appKey/triggers',
|
'/:appKey/triggers',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
|
@@ -7,18 +7,17 @@ import automatischRouter from './api/v1/automatisch.js';
|
|||||||
import accessTokensRouter from './api/v1/access-tokens.js';
|
import accessTokensRouter from './api/v1/access-tokens.js';
|
||||||
import usersRouter from './api/v1/users.js';
|
import usersRouter from './api/v1/users.js';
|
||||||
import paymentRouter from './api/v1/payment.ee.js';
|
import paymentRouter from './api/v1/payment.ee.js';
|
||||||
import appAuthClientsRouter from './api/v1/app-auth-clients.js';
|
|
||||||
import flowsRouter from './api/v1/flows.js';
|
import flowsRouter from './api/v1/flows.js';
|
||||||
import stepsRouter from './api/v1/steps.js';
|
import stepsRouter from './api/v1/steps.js';
|
||||||
import appsRouter from './api/v1/apps.js';
|
import appsRouter from './api/v1/apps.js';
|
||||||
import connectionsRouter from './api/v1/connections.js';
|
import connectionsRouter from './api/v1/connections.js';
|
||||||
import executionsRouter from './api/v1/executions.js';
|
import executionsRouter from './api/v1/executions.js';
|
||||||
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
import samlAuthProvidersRouter from './api/v1/saml-auth-providers.ee.js';
|
||||||
|
import adminAppsRouter from './api/v1/admin/apps.ee.js';
|
||||||
import adminSamlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
import adminSamlAuthProvidersRouter from './api/v1/admin/saml-auth-providers.ee.js';
|
||||||
import rolesRouter from './api/v1/admin/roles.ee.js';
|
import rolesRouter from './api/v1/admin/roles.ee.js';
|
||||||
import permissionsRouter from './api/v1/admin/permissions.ee.js';
|
import permissionsRouter from './api/v1/admin/permissions.ee.js';
|
||||||
import adminUsersRouter from './api/v1/admin/users.ee.js';
|
import adminUsersRouter from './api/v1/admin/users.ee.js';
|
||||||
import adminAppAuthClientsRouter from './api/v1/admin/app-auth-clients.ee.js';
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -30,17 +29,16 @@ router.use('/api/v1/automatisch', automatischRouter);
|
|||||||
router.use('/api/v1/access-tokens', accessTokensRouter);
|
router.use('/api/v1/access-tokens', accessTokensRouter);
|
||||||
router.use('/api/v1/users', usersRouter);
|
router.use('/api/v1/users', usersRouter);
|
||||||
router.use('/api/v1/payment', paymentRouter);
|
router.use('/api/v1/payment', paymentRouter);
|
||||||
router.use('/api/v1/app-auth-clients', appAuthClientsRouter);
|
|
||||||
router.use('/api/v1/flows', flowsRouter);
|
|
||||||
router.use('/api/v1/steps', stepsRouter);
|
|
||||||
router.use('/api/v1/apps', appsRouter);
|
router.use('/api/v1/apps', appsRouter);
|
||||||
router.use('/api/v1/connections', connectionsRouter);
|
router.use('/api/v1/connections', connectionsRouter);
|
||||||
|
router.use('/api/v1/flows', flowsRouter);
|
||||||
|
router.use('/api/v1/steps', stepsRouter);
|
||||||
router.use('/api/v1/executions', executionsRouter);
|
router.use('/api/v1/executions', executionsRouter);
|
||||||
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
router.use('/api/v1/saml-auth-providers', samlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
|
router.use('/api/v1/admin/apps', adminAppsRouter);
|
||||||
|
router.use('/api/v1/admin/users', adminUsersRouter);
|
||||||
router.use('/api/v1/admin/roles', rolesRouter);
|
router.use('/api/v1/admin/roles', rolesRouter);
|
||||||
router.use('/api/v1/admin/permissions', permissionsRouter);
|
router.use('/api/v1/admin/permissions', permissionsRouter);
|
||||||
router.use('/api/v1/admin/users', adminUsersRouter);
|
router.use('/api/v1/admin/saml-auth-providers', adminSamlAuthProvidersRouter);
|
||||||
router.use('/api/v1/admin/app-auth-clients', adminAppAuthClientsRouter);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import { createAppConfig } from './app-config.js';
|
|
||||||
import AppAuthClient from '../../src/models/app-auth-client';
|
import AppAuthClient from '../../src/models/app-auth-client';
|
||||||
|
|
||||||
const formattedAuthDefaults = {
|
const formattedAuthDefaults = {
|
||||||
@@ -12,7 +11,7 @@ const formattedAuthDefaults = {
|
|||||||
export const createAppAuthClient = async (params = {}) => {
|
export const createAppAuthClient = async (params = {}) => {
|
||||||
params.name = params?.name || faker.person.fullName();
|
params.name = params?.name || faker.person.fullName();
|
||||||
params.id = params?.id || faker.string.uuid();
|
params.id = params?.id || faker.string.uuid();
|
||||||
params.appConfigId = params?.appConfigId || (await createAppConfig()).id;
|
params.appKey = params?.appKey || 'deepl';
|
||||||
params.active = params?.active ?? true;
|
params.active = params?.active ?? true;
|
||||||
params.formattedAuthDefaults =
|
params.formattedAuthDefaults =
|
||||||
params?.formattedAuthDefaults || formattedAuthDefaults;
|
params?.formattedAuthDefaults || formattedAuthDefaults;
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
const getAdminAppAuthClientsMock = (appAuthClients) => {
|
const getAdminAppAuthClientsMock = (appAuthClients) => {
|
||||||
return {
|
return {
|
||||||
data: appAuthClients.map((appAuthClient) => ({
|
data: appAuthClients.map((appAuthClient) => ({
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
@@ -1,9 +1,9 @@
|
|||||||
const getAdminAppAuthClientMock = (appAuthClient) => {
|
const getAppAuthClientMock = (appAuthClient) => {
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
|
appConfigId: appAuthClient.appConfigId,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
@@ -16,4 +16,4 @@ const getAdminAppAuthClientMock = (appAuthClient) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getAdminAppAuthClientMock;
|
export default getAppAuthClientMock;
|
@@ -1,7 +1,6 @@
|
|||||||
const getAppAuthClientsMock = (appAuthClients) => {
|
const getAppAuthClientsMock = (appAuthClients) => {
|
||||||
return {
|
return {
|
||||||
data: appAuthClients.map((appAuthClient) => ({
|
data: appAuthClients.map((appAuthClient) => ({
|
||||||
appConfigId: appAuthClient.appConfigId,
|
|
||||||
name: appAuthClient.name,
|
name: appAuthClient.name,
|
||||||
id: appAuthClient.id,
|
id: appAuthClient.id,
|
||||||
active: appAuthClient.active,
|
active: appAuthClient.active,
|
Reference in New Issue
Block a user