feat: Convert all mutation files to js
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import AppConfig from '../../models/app-config';
|
||||||
|
|
||||||
|
const createAppAuthClient = async (_parent, params, context) => {
|
||||||
|
context.currentUser.can('update', 'App');
|
||||||
|
|
||||||
|
const appConfig = await AppConfig.query()
|
||||||
|
.findById(params.input.appConfigId)
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
const appAuthClient = await appConfig
|
||||||
|
.$relatedQuery('appAuthClients')
|
||||||
|
.insert(params.input);
|
||||||
|
|
||||||
|
return appAuthClient;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default createAppAuthClient;
|
@@ -1,35 +0,0 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
import AppConfig from '../../models/app-config';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
appConfigId: string;
|
|
||||||
name: string;
|
|
||||||
formattedAuthDefaults?: IJSONObject;
|
|
||||||
active?: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createAppAuthClient = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'App');
|
|
||||||
|
|
||||||
const appConfig = await AppConfig
|
|
||||||
.query()
|
|
||||||
.findById(params.input.appConfigId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
const appAuthClient = await appConfig
|
|
||||||
.$relatedQuery('appAuthClients')
|
|
||||||
.insert(
|
|
||||||
params.input
|
|
||||||
);
|
|
||||||
|
|
||||||
return appAuthClient;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createAppAuthClient;
|
|
@@ -0,0 +1,18 @@
|
|||||||
|
import App from '../../models/app';
|
||||||
|
import AppConfig from '../../models/app-config';
|
||||||
|
|
||||||
|
const createAppConfig = async (_parent, params, context) => {
|
||||||
|
context.currentUser.can('update', 'App');
|
||||||
|
|
||||||
|
const key = params.input.key;
|
||||||
|
|
||||||
|
const app = await App.findOneByKey(key);
|
||||||
|
|
||||||
|
if (!app) throw new Error('The app cannot be found!');
|
||||||
|
|
||||||
|
const appConfig = await AppConfig.query().insert(params.input);
|
||||||
|
|
||||||
|
return appConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default createAppConfig;
|
@@ -1,36 +0,0 @@
|
|||||||
import App from '../../models/app';
|
|
||||||
import AppConfig from '../../models/app-config';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
key: string;
|
|
||||||
allowCustomConnection?: boolean;
|
|
||||||
shared?: boolean;
|
|
||||||
disabled?: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createAppConfig = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'App');
|
|
||||||
|
|
||||||
const key = params.input.key;
|
|
||||||
|
|
||||||
const app = await App.findOneByKey(key);
|
|
||||||
|
|
||||||
if (!app) throw new Error('The app cannot be found!');
|
|
||||||
|
|
||||||
const appConfig = await AppConfig
|
|
||||||
.query()
|
|
||||||
.insert(
|
|
||||||
params.input
|
|
||||||
);
|
|
||||||
|
|
||||||
return appConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createAppConfig;
|
|
@@ -1,21 +1,7 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
import AppConfig from '../../models/app-config';
|
import AppConfig from '../../models/app-config';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const createConnection = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
key: string;
|
|
||||||
appAuthClientId: string;
|
|
||||||
formattedData: IJSONObject;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createConnection = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Connection');
|
context.currentUser.can('create', 'Connection');
|
||||||
|
|
||||||
const { key, appAuthClientId } = params.input;
|
const { key, appAuthClientId } = params.input;
|
||||||
@@ -26,16 +12,20 @@ const createConnection = async (
|
|||||||
|
|
||||||
let formattedData = params.input.formattedData;
|
let formattedData = params.input.formattedData;
|
||||||
if (appConfig) {
|
if (appConfig) {
|
||||||
if (appConfig.disabled) throw new Error('This application has been disabled for new connections!');
|
if (appConfig.disabled)
|
||||||
|
throw new Error(
|
||||||
|
'This application has been disabled for new connections!'
|
||||||
|
);
|
||||||
|
|
||||||
if (!appConfig.allowCustomConnection && formattedData) throw new Error(`Custom connections cannot be created for ${app.name}!`);
|
if (!appConfig.allowCustomConnection && formattedData)
|
||||||
|
throw new Error(`Custom connections cannot be created for ${app.name}!`);
|
||||||
|
|
||||||
if (appConfig.shared && !formattedData) {
|
if (appConfig.shared && !formattedData) {
|
||||||
const authClient = await appConfig
|
const authClient = await appConfig
|
||||||
.$relatedQuery('appAuthClients')
|
.$relatedQuery('appAuthClients')
|
||||||
.findById(appAuthClientId)
|
.findById(appAuthClientId)
|
||||||
.where({
|
.where({
|
||||||
active: true
|
active: true,
|
||||||
})
|
})
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
@@ -43,8 +33,7 @@ const createConnection = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdConnection = await context
|
const createdConnection = await context.currentUser
|
||||||
.currentUser
|
|
||||||
.$relatedQuery('connections')
|
.$relatedQuery('connections')
|
||||||
.insert({
|
.insert({
|
||||||
key,
|
key,
|
@@ -1,19 +1,7 @@
|
|||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
import Step from '../../models/step';
|
import Step from '../../models/step';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const createFlow = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
triggerAppKey: string;
|
|
||||||
connectionId: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createFlow = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Flow');
|
context.currentUser.can('create', 'Flow');
|
||||||
|
|
||||||
const connectionId = params?.input?.connectionId;
|
const connectionId = params?.input?.connectionId;
|
29
packages/backend/src/graphql/mutations/create-role.ee.js
Normal file
29
packages/backend/src/graphql/mutations/create-role.ee.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import kebabCase from 'lodash/kebabCase';
|
||||||
|
import Role from '../../models/role';
|
||||||
|
|
||||||
|
const createRole = async (_parent, params, context) => {
|
||||||
|
context.currentUser.can('create', 'Role');
|
||||||
|
|
||||||
|
const { name, description, permissions } = params.input;
|
||||||
|
const key = kebabCase(name);
|
||||||
|
|
||||||
|
const existingRole = await Role.query().findOne({ key });
|
||||||
|
|
||||||
|
if (existingRole) {
|
||||||
|
throw new Error('Role already exists!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return await Role.query()
|
||||||
|
.insertGraph(
|
||||||
|
{
|
||||||
|
key,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
permissions,
|
||||||
|
},
|
||||||
|
{ relate: ['permissions'] }
|
||||||
|
)
|
||||||
|
.returning('*');
|
||||||
|
};
|
||||||
|
|
||||||
|
export default createRole;
|
@@ -1,34 +0,0 @@
|
|||||||
import kebabCase from 'lodash/kebabCase';
|
|
||||||
import Permission from '../../models/permission';
|
|
||||||
import Role from '../../models/role';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
permissions: Permission[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createRole = async (_parent: unknown, params: Params, context: Context) => {
|
|
||||||
context.currentUser.can('create', 'Role');
|
|
||||||
|
|
||||||
const { name, description, permissions } = params.input;
|
|
||||||
const key = kebabCase(name);
|
|
||||||
|
|
||||||
const existingRole = await Role.query().findOne({ key });
|
|
||||||
|
|
||||||
if (existingRole) {
|
|
||||||
throw new Error('Role already exists!');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await Role.query().insertGraph({
|
|
||||||
key,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
permissions,
|
|
||||||
}, { relate: ['permissions'] }).returning('*');
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createRole;
|
|
@@ -1,28 +1,7 @@
|
|||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
import Flow from '../../models/flow';
|
import Flow from '../../models/flow';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const createStep = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
key: string;
|
|
||||||
appKey: string;
|
|
||||||
flow: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
connection: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
previousStep: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createStep = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const conditions = context.currentUser.can('update', 'Flow');
|
const conditions = context.currentUser.can('update', 'Flow');
|
||||||
const userFlows = context.currentUser.$relatedQuery('flows');
|
const userFlows = context.currentUser.$relatedQuery('flows');
|
||||||
const allFlows = Flow.query();
|
const allFlows = Flow.query();
|
@@ -1,23 +1,7 @@
|
|||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
import Role from '../../models/role';
|
import Role from '../../models/role';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const createUser = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
fullName: string;
|
|
||||||
email: string;
|
|
||||||
password: string;
|
|
||||||
role: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const createUser = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'User');
|
context.currentUser.can('create', 'User');
|
||||||
|
|
||||||
const { fullName, email, password } = params.input;
|
const { fullName, email, password } = params.input;
|
||||||
@@ -30,7 +14,7 @@ const createUser = async (
|
|||||||
throw new Error('User already exists!');
|
throw new Error('User already exists!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const userPayload: Partial<User> = {
|
const userPayload = {
|
||||||
fullName,
|
fullName,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
@@ -1,21 +1,9 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import AppAuthClient from '../../models/app-auth-client';
|
import AppAuthClient from '../../models/app-auth-client';
|
||||||
|
|
||||||
type Params = {
|
const deleteAppAuthClient = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteAppAuthClient = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('delete', 'App');
|
context.currentUser.can('delete', 'App');
|
||||||
|
|
||||||
await AppAuthClient
|
await AppAuthClient.query()
|
||||||
.query()
|
|
||||||
.delete()
|
.delete()
|
||||||
.findOne({
|
.findOne({
|
||||||
id: params.input.id,
|
id: params.input.id,
|
@@ -1,16 +1,4 @@
|
|||||||
import Context from '../../types/express/context';
|
const deleteConnection = async (_parent, params, context) => {
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteConnection = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('delete', 'Connection');
|
context.currentUser.can('delete', 'Connection');
|
||||||
|
|
||||||
await context.currentUser
|
await context.currentUser
|
@@ -1,17 +1,11 @@
|
|||||||
import { Duration } from 'luxon';
|
import { Duration } from 'luxon';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
import deleteUserQueue from '../../queues/delete-user.ee';
|
import deleteUserQueue from '../../queues/delete-user.ee';
|
||||||
import flowQueue from '../../queues/flow';
|
import flowQueue from '../../queues/flow';
|
||||||
import Flow from '../../models/flow';
|
import Flow from '../../models/flow';
|
||||||
import Execution from '../../models/execution';
|
|
||||||
import ExecutionStep from '../../models/execution-step';
|
import ExecutionStep from '../../models/execution-step';
|
||||||
import appConfig from '../../config/app';
|
import appConfig from '../../config/app';
|
||||||
|
|
||||||
const deleteCurrentUser = async (
|
const deleteCurrentUser = async (_parent, params, context) => {
|
||||||
_parent: unknown,
|
|
||||||
params: never,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const id = context.currentUser.id;
|
const id = context.currentUser.id;
|
||||||
|
|
||||||
const flows = await context.currentUser.$relatedQuery('flows').where({
|
const flows = await context.currentUser.$relatedQuery('flows').where({
|
||||||
@@ -32,7 +26,7 @@ const deleteCurrentUser = async (
|
|||||||
await context.currentUser
|
await context.currentUser
|
||||||
.$relatedQuery('executions')
|
.$relatedQuery('executions')
|
||||||
.select('executions.id')
|
.select('executions.id')
|
||||||
).map((execution: Execution) => execution.id);
|
).map((execution) => execution.id);
|
||||||
const flowIds = flows.map((flow) => flow.id);
|
const flowIds = flows.map((flow) => flow.id);
|
||||||
|
|
||||||
await ExecutionStep.query().delete().whereIn('execution_id', executionIds);
|
await ExecutionStep.query().delete().whereIn('execution_id', executionIds);
|
@@ -1,21 +1,9 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import Flow from '../../models/flow';
|
import Flow from '../../models/flow';
|
||||||
import Execution from '../../models/execution';
|
|
||||||
import ExecutionStep from '../../models/execution-step';
|
import ExecutionStep from '../../models/execution-step';
|
||||||
import globalVariable from '../../helpers/global-variable';
|
import globalVariable from '../../helpers/global-variable';
|
||||||
import logger from '../../helpers/logger';
|
import logger from '../../helpers/logger';
|
||||||
|
|
||||||
type Params = {
|
const deleteFlow = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteFlow = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const conditions = context.currentUser.can('delete', 'Flow');
|
const conditions = context.currentUser.can('delete', 'Flow');
|
||||||
const isCreator = conditions.isCreator;
|
const isCreator = conditions.isCreator;
|
||||||
const allFlows = Flow.query();
|
const allFlows = Flow.query();
|
||||||
@@ -43,13 +31,15 @@ const deleteFlow = async (
|
|||||||
await trigger.unregisterHook($);
|
await trigger.unregisterHook($);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// suppress error as the remote resource might have been already deleted
|
// suppress error as the remote resource might have been already deleted
|
||||||
logger.debug(`Failed to unregister webhook for flow ${flow.id}: ${error.message}`);
|
logger.debug(
|
||||||
|
`Failed to unregister webhook for flow ${flow.id}: ${error.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const executionIds = (
|
const executionIds = (
|
||||||
await flow.$relatedQuery('executions').select('executions.id')
|
await flow.$relatedQuery('executions').select('executions.id')
|
||||||
).map((execution: Execution) => execution.id);
|
).map((execution) => execution.id);
|
||||||
|
|
||||||
await ExecutionStep.query().delete().whereIn('execution_id', executionIds);
|
await ExecutionStep.query().delete().whereIn('execution_id', executionIds);
|
||||||
|
|
@@ -1,18 +1,7 @@
|
|||||||
import Role from '../../models/role';
|
import Role from '../../models/role';
|
||||||
import SamlAuthProvider from '../../models/saml-auth-provider.ee';
|
import SamlAuthProvider from '../../models/saml-auth-provider.ee';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const deleteRole = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteRole = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('delete', 'Role');
|
context.currentUser.can('delete', 'Role');
|
||||||
|
|
||||||
const role = await Role.query().findById(params.input.id).throwIfNotFound();
|
const role = await Role.query().findById(params.input.id).throwIfNotFound();
|
@@ -1,16 +1,4 @@
|
|||||||
import Context from '../../types/express/context';
|
const deleteStep = async (_parent, params, context) => {
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteStep = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'Flow');
|
context.currentUser.can('update', 'Flow');
|
||||||
|
|
||||||
const step = await context.currentUser
|
const step = await context.currentUser
|
@@ -1,19 +1,8 @@
|
|||||||
import { Duration } from 'luxon';
|
import { Duration } from 'luxon';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
import deleteUserQueue from '../../queues/delete-user.ee';
|
import deleteUserQueue from '../../queues/delete-user.ee';
|
||||||
|
|
||||||
type Params = {
|
const deleteUser = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteUser = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('delete', 'User');
|
context.currentUser.can('delete', 'User');
|
||||||
|
|
||||||
const id = params.input.id;
|
const id = params.input.id;
|
||||||
@@ -24,7 +13,7 @@ const deleteUser = async (
|
|||||||
const jobPayload = { id };
|
const jobPayload = { id };
|
||||||
const millisecondsFor30Days = Duration.fromObject({ days: 30 }).toMillis();
|
const millisecondsFor30Days = Duration.fromObject({ days: 30 }).toMillis();
|
||||||
const jobOptions = {
|
const jobOptions = {
|
||||||
delay: millisecondsFor30Days
|
delay: millisecondsFor30Days,
|
||||||
};
|
};
|
||||||
|
|
||||||
await deleteUserQueue.add(jobName, jobPayload, jobOptions);
|
await deleteUserQueue.add(jobName, jobPayload, jobOptions);
|
@@ -1,15 +1,4 @@
|
|||||||
import Context from '../../types/express/context';
|
function updateStepId(value, newStepIds) {
|
||||||
import Step from '../../models/step';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
type NewStepIds = Record<string, string>;
|
|
||||||
|
|
||||||
function updateStepId(value: string, newStepIds: NewStepIds) {
|
|
||||||
let newValue = value;
|
let newValue = value;
|
||||||
|
|
||||||
const stepIdEntries = Object.entries(newStepIds);
|
const stepIdEntries = Object.entries(newStepIds);
|
||||||
@@ -24,9 +13,9 @@ function updateStepId(value: string, newStepIds: NewStepIds) {
|
|||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStepVariables(parameters: Step['parameters'], newStepIds: NewStepIds): Step['parameters'] {
|
function updateStepVariables(parameters, newStepIds) {
|
||||||
const entries = Object.entries(parameters);
|
const entries = Object.entries(parameters);
|
||||||
return entries.reduce((result, [key, value]: [string, unknown]) => {
|
return entries.reduce((result, [key, value]) => {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
@@ -37,7 +26,7 @@ function updateStepVariables(parameters: Step['parameters'], newStepIds: NewStep
|
|||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
[key]: value.map(item => updateStepVariables(item, newStepIds)),
|
[key]: value.map((item) => updateStepVariables(item, newStepIds)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +37,7 @@ function updateStepVariables(parameters: Step['parameters'], newStepIds: NewStep
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const duplicateFlow = async (
|
const duplicateFlow = async (_parent, params, context) => {
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Flow');
|
context.currentUser.can('create', 'Flow');
|
||||||
|
|
||||||
const flow = await context.currentUser
|
const flow = await context.currentUser
|
||||||
@@ -69,17 +54,16 @@ const duplicateFlow = async (
|
|||||||
active: false,
|
active: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const newStepIds: NewStepIds = {};
|
const newStepIds = {};
|
||||||
for (const step of flow.steps) {
|
for (const step of flow.steps) {
|
||||||
const duplicatedStep = await duplicatedFlow.$relatedQuery('steps')
|
const duplicatedStep = await duplicatedFlow.$relatedQuery('steps').insert({
|
||||||
.insert({
|
key: step.key,
|
||||||
key: step.key,
|
appKey: step.appKey,
|
||||||
appKey: step.appKey,
|
type: step.type,
|
||||||
type: step.type,
|
connectionId: step.connectionId,
|
||||||
connectionId: step.connectionId,
|
position: step.position,
|
||||||
position: step.position,
|
parameters: updateStepVariables(step.parameters, newStepIds),
|
||||||
parameters: updateStepVariables(step.parameters, newStepIds),
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (duplicatedStep.isTrigger) {
|
if (duplicatedStep.isTrigger) {
|
||||||
await duplicatedStep.updateWebhookUrl();
|
await duplicatedStep.updateWebhookUrl();
|
@@ -1,18 +1,7 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import testRun from '../../services/test-run';
|
import testRun from '../../services/test-run';
|
||||||
import Step from '../../models/step';
|
import Step from '../../models/step';
|
||||||
|
|
||||||
type Params = {
|
const executeFlow = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
stepId: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const executeFlow = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const conditions = context.currentUser.can('update', 'Flow');
|
const conditions = context.currentUser.can('update', 'Flow');
|
||||||
const isCreator = conditions.isCreator;
|
const isCreator = conditions.isCreator;
|
||||||
const allSteps = Step.query();
|
const allSteps = Step.query();
|
||||||
@@ -21,10 +10,7 @@ const executeFlow = async (
|
|||||||
|
|
||||||
const { stepId } = params.input;
|
const { stepId } = params.input;
|
||||||
|
|
||||||
const untilStep = await baseQuery
|
const untilStep = await baseQuery.clone().findById(stepId).throwIfNotFound();
|
||||||
.clone()
|
|
||||||
.findById(stepId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
const { executionStep } = await testRun({ stepId });
|
const { executionStep } = await testRun({ stepId });
|
||||||
|
|
@@ -6,13 +6,7 @@ import {
|
|||||||
REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
||||||
} from '../../helpers/remove-job-configuration';
|
} from '../../helpers/remove-job-configuration';
|
||||||
|
|
||||||
type Params = {
|
const forgotPassword = async (_parent, params) => {
|
||||||
input: {
|
|
||||||
email: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const forgotPassword = async (_parent: unknown, params: Params) => {
|
|
||||||
const { email } = params.input;
|
const { email } = params.input;
|
||||||
|
|
||||||
const user = await User.query().findOne({ email: email.toLowerCase() });
|
const user = await User.query().findOne({ email: email.toLowerCase() });
|
@@ -1,18 +1,7 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import globalVariable from '../../helpers/global-variable';
|
import globalVariable from '../../helpers/global-variable';
|
||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
|
|
||||||
type Params = {
|
const generateAuthUrl = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateAuthUrl = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Connection');
|
context.currentUser.can('create', 'Connection');
|
||||||
|
|
||||||
const connection = await context.currentUser
|
const connection = await context.currentUser
|
@@ -1,14 +1,7 @@
|
|||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
|
import createAuthTokenByUserId from '../../helpers/create-auth-token-by-user-id';
|
||||||
|
|
||||||
type Params = {
|
const login = async (_parent, params) => {
|
||||||
input: {
|
|
||||||
email: string;
|
|
||||||
password: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const login = async (_parent: unknown, params: Params) => {
|
|
||||||
const user = await User.query().findOne({
|
const user = await User.query().findOne({
|
||||||
email: params.input.email.toLowerCase(),
|
email: params.input.email.toLowerCase(),
|
||||||
});
|
});
|
@@ -1,15 +1,7 @@
|
|||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
import Role from '../../models/role';
|
import Role from '../../models/role';
|
||||||
|
|
||||||
type Params = {
|
const registerUser = async (_parent, params) => {
|
||||||
input: {
|
|
||||||
fullName: string;
|
|
||||||
email: string;
|
|
||||||
password: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const registerUser = async (_parent: unknown, params: Params) => {
|
|
||||||
const { fullName, email, password } = params.input;
|
const { fullName, email, password } = params.input;
|
||||||
|
|
||||||
const existingUser = await User.query().findOne({
|
const existingUser = await User.query().findOne({
|
@@ -1,16 +1,4 @@
|
|||||||
import Context from '../../types/express/context';
|
const resetConnection = async (_parent, params, context) => {
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const resetConnection = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Connection');
|
context.currentUser.can('create', 'Connection');
|
||||||
|
|
||||||
let connection = await context.currentUser
|
let connection = await context.currentUser
|
@@ -1,13 +1,6 @@
|
|||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
|
|
||||||
type Params = {
|
const resetPassword = async (_parent, params) => {
|
||||||
input: {
|
|
||||||
token: string;
|
|
||||||
password: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const resetPassword = async (_parent: unknown, params: Params) => {
|
|
||||||
const { token, password } = params.input;
|
const { token, password } = params.input;
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
@@ -0,0 +1,17 @@
|
|||||||
|
import AppAuthClient from '../../models/app-auth-client';
|
||||||
|
|
||||||
|
const updateAppAuthClient = async (_parent, params, context) => {
|
||||||
|
context.currentUser.can('update', 'App');
|
||||||
|
|
||||||
|
const { id, ...appAuthClientData } = params.input;
|
||||||
|
|
||||||
|
const appAuthClient = await AppAuthClient.query()
|
||||||
|
.findById(id)
|
||||||
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
await appAuthClient.$query().patch(appAuthClientData);
|
||||||
|
|
||||||
|
return appAuthClient;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default updateAppAuthClient;
|
@@ -1,38 +0,0 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
import AppAuthClient from '../../models/app-auth-client';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
formattedAuthDefaults?: IJSONObject;
|
|
||||||
active?: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateAppAuthClient = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'App');
|
|
||||||
|
|
||||||
const {
|
|
||||||
id,
|
|
||||||
...appAuthClientData
|
|
||||||
} = params.input;
|
|
||||||
|
|
||||||
const appAuthClient = await AppAuthClient
|
|
||||||
.query()
|
|
||||||
.findById(id)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
await appAuthClient
|
|
||||||
.$query()
|
|
||||||
.patch(appAuthClientData);
|
|
||||||
|
|
||||||
return appAuthClient;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default updateAppAuthClient;
|
|
@@ -0,0 +1,15 @@
|
|||||||
|
import AppConfig from '../../models/app-config';
|
||||||
|
|
||||||
|
const updateAppConfig = async (_parent, params, context) => {
|
||||||
|
context.currentUser.can('update', 'App');
|
||||||
|
|
||||||
|
const { id, ...appConfigToUpdate } = params.input;
|
||||||
|
|
||||||
|
const appConfig = await AppConfig.query().findById(id).throwIfNotFound();
|
||||||
|
|
||||||
|
await appConfig.$query().patch(appConfigToUpdate);
|
||||||
|
|
||||||
|
return appConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default updateAppConfig;
|
@@ -1,39 +0,0 @@
|
|||||||
import AppConfig from '../../models/app-config';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
allowCustomConnection?: boolean;
|
|
||||||
shared?: boolean;
|
|
||||||
disabled?: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateAppConfig = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'App');
|
|
||||||
|
|
||||||
const {
|
|
||||||
id,
|
|
||||||
...appConfigToUpdate
|
|
||||||
} = params.input;
|
|
||||||
|
|
||||||
const appConfig = await AppConfig
|
|
||||||
.query()
|
|
||||||
.findById(id)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
await appConfig
|
|
||||||
.$query()
|
|
||||||
.patch(
|
|
||||||
appConfigToUpdate
|
|
||||||
);
|
|
||||||
|
|
||||||
return appConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default updateAppConfig;
|
|
@@ -1,18 +1,6 @@
|
|||||||
import type { IJSONValue } from '@automatisch/types';
|
|
||||||
import Config from '../../models/config';
|
import Config from '../../models/config';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const updateConfig = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
[index: string]: IJSONValue;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateConfig = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'Config');
|
context.currentUser.can('update', 'Config');
|
||||||
|
|
||||||
const config = params.input;
|
const config = params.input;
|
@@ -1,20 +1,6 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
import AppAuthClient from '../../models/app-auth-client';
|
import AppAuthClient from '../../models/app-auth-client';
|
||||||
|
|
||||||
type Params = {
|
const updateConnection = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
formattedData?: IJSONObject;
|
|
||||||
appAuthClientId?: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateConnection = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Connection');
|
context.currentUser.can('create', 'Connection');
|
||||||
|
|
||||||
let connection = await context.currentUser
|
let connection = await context.currentUser
|
||||||
@@ -27,8 +13,7 @@ const updateConnection = async (
|
|||||||
let formattedData = params.input.formattedData;
|
let formattedData = params.input.formattedData;
|
||||||
|
|
||||||
if (params.input.appAuthClientId) {
|
if (params.input.appAuthClientId) {
|
||||||
const appAuthClient = await AppAuthClient
|
const appAuthClient = await AppAuthClient.query()
|
||||||
.query()
|
|
||||||
.findById(params.input.appAuthClientId)
|
.findById(params.input.appAuthClientId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
const updateCurrentUser = async (_parent, params, context) => {
|
||||||
|
const user = await context.currentUser.$query().patchAndFetch({
|
||||||
|
email: params.input.email,
|
||||||
|
password: params.input.password,
|
||||||
|
fullName: params.input.fullName,
|
||||||
|
});
|
||||||
|
|
||||||
|
return user;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default updateCurrentUser;
|
@@ -1,25 +0,0 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
email: string;
|
|
||||||
password: string;
|
|
||||||
fullName: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateCurrentUser = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const user = await context.currentUser.$query().patchAndFetch({
|
|
||||||
email: params.input.email,
|
|
||||||
password: params.input.password,
|
|
||||||
fullName: params.input.fullName,
|
|
||||||
});
|
|
||||||
|
|
||||||
return user;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default updateCurrentUser;
|
|
@@ -1,24 +1,15 @@
|
|||||||
import Flow from '../../models/flow';
|
import Flow from '../../models/flow';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
import flowQueue from '../../queues/flow';
|
import flowQueue from '../../queues/flow';
|
||||||
import { REMOVE_AFTER_30_DAYS_OR_150_JOBS, REMOVE_AFTER_7_DAYS_OR_50_JOBS } from '../../helpers/remove-job-configuration';
|
import {
|
||||||
|
REMOVE_AFTER_30_DAYS_OR_150_JOBS,
|
||||||
|
REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
||||||
|
} from '../../helpers/remove-job-configuration';
|
||||||
import globalVariable from '../../helpers/global-variable';
|
import globalVariable from '../../helpers/global-variable';
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
active: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const JOB_NAME = 'flow';
|
const JOB_NAME = 'flow';
|
||||||
const EVERY_15_MINUTES_CRON = '*/15 * * * *';
|
const EVERY_15_MINUTES_CRON = '*/15 * * * *';
|
||||||
|
|
||||||
const updateFlowStatus = async (
|
const updateFlowStatus = async (_parent, params, context) => {
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const conditions = context.currentUser.can('publish', 'Flow');
|
const conditions = context.currentUser.can('publish', 'Flow');
|
||||||
const isCreator = conditions.isCreator;
|
const isCreator = conditions.isCreator;
|
||||||
const allFlows = Flow.query();
|
const allFlows = Flow.query();
|
||||||
@@ -74,7 +65,7 @@ const updateFlowStatus = async (
|
|||||||
repeat: repeatOptions,
|
repeat: repeatOptions,
|
||||||
jobId: flow.id,
|
jobId: flow.id,
|
||||||
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
removeOnComplete: REMOVE_AFTER_7_DAYS_OR_50_JOBS,
|
||||||
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS
|
removeOnFail: REMOVE_AFTER_30_DAYS_OR_150_JOBS,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -85,12 +76,9 @@ const updateFlowStatus = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flow = await flow
|
flow = await flow.$query().withGraphFetched('steps').patchAndFetch({
|
||||||
.$query()
|
active: newActiveValue,
|
||||||
.withGraphFetched('steps')
|
});
|
||||||
.patchAndFetch({
|
|
||||||
active: newActiveValue,
|
|
||||||
});
|
|
||||||
|
|
||||||
return flow;
|
return flow;
|
||||||
};
|
};
|
@@ -1,17 +1,4 @@
|
|||||||
import Context from '../../types/express/context';
|
const updateFlow = async (_parent, params, context) => {
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateFlow = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'Flow');
|
context.currentUser.can('update', 'Flow');
|
||||||
|
|
||||||
let flow = await context.currentUser
|
let flow = await context.currentUser
|
@@ -1,35 +1,13 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import Role from '../../models/role';
|
import Role from '../../models/role';
|
||||||
import Permission from '../../models/permission';
|
import Permission from '../../models/permission';
|
||||||
import permissionCatalog from '../../helpers/permission-catalog.ee';
|
import permissionCatalog from '../../helpers/permission-catalog.ee';
|
||||||
|
|
||||||
type Params = {
|
const updateRole = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
permissions: Permission[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateRole = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'Role');
|
context.currentUser.can('update', 'Role');
|
||||||
|
|
||||||
const {
|
const { id, name, description, permissions } = params.input;
|
||||||
id,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
permissions,
|
|
||||||
} = params.input;
|
|
||||||
|
|
||||||
const role = await Role
|
const role = await Role.query().findById(id).throwIfNotFound();
|
||||||
.query()
|
|
||||||
.findById(id)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedRole = await Role.transaction(async (trx) => {
|
const updatedRole = await Role.transaction(async (trx) => {
|
||||||
@@ -38,19 +16,17 @@ const updateRole = async (
|
|||||||
if (permissions?.length) {
|
if (permissions?.length) {
|
||||||
const sanitizedPermissions = permissions
|
const sanitizedPermissions = permissions
|
||||||
.filter((permission) => {
|
.filter((permission) => {
|
||||||
const {
|
const { action, subject, conditions } = permission;
|
||||||
action,
|
|
||||||
subject,
|
|
||||||
conditions,
|
|
||||||
} = permission;
|
|
||||||
|
|
||||||
const relevantAction = permissionCatalog.actions.find(actionCatalogItem => actionCatalogItem.key === action);
|
const relevantAction = permissionCatalog.actions.find(
|
||||||
|
(actionCatalogItem) => actionCatalogItem.key === action
|
||||||
|
);
|
||||||
const validSubject = relevantAction.subjects.includes(subject);
|
const validSubject = relevantAction.subjects.includes(subject);
|
||||||
const validConditions = conditions.every(condition => {
|
const validConditions = conditions.every((condition) => {
|
||||||
return !!permissionCatalog
|
return !!permissionCatalog.conditions.find(
|
||||||
.conditions
|
(conditionCatalogItem) => conditionCatalogItem.key === condition
|
||||||
.find((conditionCatalogItem) => conditionCatalogItem.key === condition);
|
);
|
||||||
})
|
});
|
||||||
|
|
||||||
return validSubject && validConditions;
|
return validSubject && validConditions;
|
||||||
})
|
})
|
||||||
@@ -62,22 +38,17 @@ const updateRole = async (
|
|||||||
await Permission.query().insert(sanitizedPermissions);
|
await Permission.query().insert(sanitizedPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
await role
|
await role.$query(trx).patch({
|
||||||
.$query(trx)
|
name,
|
||||||
.patch(
|
description,
|
||||||
{
|
});
|
||||||
name,
|
|
||||||
description,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return await Role
|
return await Role.query(trx)
|
||||||
.query(trx)
|
|
||||||
.leftJoinRelated({
|
.leftJoinRelated({
|
||||||
permissions: true
|
permissions: true,
|
||||||
})
|
})
|
||||||
.withGraphFetched({
|
.withGraphFetched({
|
||||||
permissions: true
|
permissions: true,
|
||||||
})
|
})
|
||||||
.findById(id);
|
.findById(id);
|
||||||
});
|
});
|
@@ -1,29 +1,8 @@
|
|||||||
import { IJSONObject } from '@automatisch/types';
|
|
||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
import Step from '../../models/step';
|
import Step from '../../models/step';
|
||||||
import Connection from '../../models/connection';
|
import Connection from '../../models/connection';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
const updateStep = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
key: string;
|
|
||||||
appKey: string;
|
|
||||||
parameters: IJSONObject;
|
|
||||||
flow: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
connection: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateStep = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
const { isCreator } = context.currentUser.can('update', 'Flow');
|
const { isCreator } = context.currentUser.can('update', 'Flow');
|
||||||
const userSteps = context.currentUser.$relatedQuery('steps');
|
const userSteps = context.currentUser.$relatedQuery('steps');
|
||||||
const allSteps = Step.query();
|
const allSteps = Step.query();
|
||||||
@@ -50,11 +29,13 @@ const updateStep = async (
|
|||||||
|
|
||||||
const userConnections = context.currentUser.$relatedQuery('connections');
|
const userConnections = context.currentUser.$relatedQuery('connections');
|
||||||
const allConnections = Connection.query();
|
const allConnections = Connection.query();
|
||||||
const baseConnectionsQuery = canSeeAllConnections ? allConnections : userConnections;
|
const baseConnectionsQuery = canSeeAllConnections
|
||||||
|
? allConnections
|
||||||
|
: userConnections;
|
||||||
|
|
||||||
const connection = await baseConnectionsQuery
|
const connection = await baseConnectionsQuery
|
||||||
.clone()
|
.clone()
|
||||||
.findById(input.connection?.id)
|
.findById(input.connection?.id);
|
||||||
|
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('The connection does not exist!');
|
throw new Error('The connection does not exist!');
|
@@ -1,25 +1,9 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
|
|
||||||
type Params = {
|
const updateUser = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
email: string;
|
|
||||||
fullName: string;
|
|
||||||
role: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateUser = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('update', 'User');
|
context.currentUser.can('update', 'User');
|
||||||
|
|
||||||
const userPayload: Partial<User> = {
|
const userPayload = {
|
||||||
email: params.input.email,
|
email: params.input.email,
|
||||||
fullName: params.input.fullName,
|
fullName: params.input.fullName,
|
||||||
};
|
};
|
@@ -0,0 +1,30 @@
|
|||||||
|
import SamlAuthProvider from '../../models/saml-auth-provider.ee';
|
||||||
|
|
||||||
|
const upsertSamlAuthProvider = async (_parent, params, context) => {
|
||||||
|
context.currentUser.can('create', 'SamlAuthProvider');
|
||||||
|
|
||||||
|
const samlAuthProviderPayload = {
|
||||||
|
...params.input,
|
||||||
|
};
|
||||||
|
|
||||||
|
const existingSamlAuthProvider = await SamlAuthProvider.query()
|
||||||
|
.limit(1)
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (!existingSamlAuthProvider) {
|
||||||
|
const samlAuthProvider = await SamlAuthProvider.query().insert(
|
||||||
|
samlAuthProviderPayload
|
||||||
|
);
|
||||||
|
|
||||||
|
return samlAuthProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
const samlAuthProvider = await SamlAuthProvider.query().patchAndFetchById(
|
||||||
|
existingSamlAuthProvider.id,
|
||||||
|
samlAuthProviderPayload
|
||||||
|
);
|
||||||
|
|
||||||
|
return samlAuthProvider;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default upsertSamlAuthProvider;
|
@@ -1,52 +0,0 @@
|
|||||||
import type { SamlConfig } from '@node-saml/passport-saml';
|
|
||||||
import SamlAuthProvider from '../../models/saml-auth-provider.ee';
|
|
||||||
import Context from '../../types/express/context';
|
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
name: string;
|
|
||||||
certificate: string;
|
|
||||||
signatureAlgorithm: SamlConfig['signatureAlgorithm'];
|
|
||||||
issuer: string;
|
|
||||||
entryPoint: string;
|
|
||||||
firstnameAttributeName: string;
|
|
||||||
surnameAttributeName: string;
|
|
||||||
emailAttributeName: string;
|
|
||||||
roleAttributeName: string;
|
|
||||||
defaultRoleId: string;
|
|
||||||
active: boolean;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const upsertSamlAuthProvider = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'SamlAuthProvider');
|
|
||||||
|
|
||||||
const samlAuthProviderPayload: Partial<SamlAuthProvider> = {
|
|
||||||
...params.input,
|
|
||||||
};
|
|
||||||
|
|
||||||
const existingSamlAuthProvider = await SamlAuthProvider.query()
|
|
||||||
.limit(1)
|
|
||||||
.first();
|
|
||||||
|
|
||||||
if (!existingSamlAuthProvider) {
|
|
||||||
const samlAuthProvider = await SamlAuthProvider.query().insert(
|
|
||||||
samlAuthProviderPayload
|
|
||||||
);
|
|
||||||
|
|
||||||
return samlAuthProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
const samlAuthProvider = await SamlAuthProvider.query().patchAndFetchById(
|
|
||||||
existingSamlAuthProvider.id,
|
|
||||||
samlAuthProviderPayload
|
|
||||||
);
|
|
||||||
|
|
||||||
return samlAuthProvider;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default upsertSamlAuthProvider;
|
|
@@ -1,24 +1,11 @@
|
|||||||
import SamlAuthProvider from '../../models/saml-auth-provider.ee';
|
import SamlAuthProvider from '../../models/saml-auth-provider.ee';
|
||||||
import SamlAuthProvidersRoleMapping from '../../models/saml-auth-providers-role-mapping.ee';
|
import SamlAuthProvidersRoleMapping from '../../models/saml-auth-providers-role-mapping.ee';
|
||||||
import Context from '../../types/express/context';
|
|
||||||
import isEmpty from 'lodash/isEmpty';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
|
||||||
type Params = {
|
|
||||||
input: {
|
|
||||||
samlAuthProviderId: string;
|
|
||||||
samlAuthProvidersRoleMappings: [
|
|
||||||
{
|
|
||||||
roleId: string;
|
|
||||||
remoteRoleName: string;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const upsertSamlAuthProvidersRoleMappings = async (
|
const upsertSamlAuthProvidersRoleMappings = async (
|
||||||
_parent: unknown,
|
_parent,
|
||||||
params: Params,
|
params,
|
||||||
context: Context
|
context
|
||||||
) => {
|
) => {
|
||||||
context.currentUser.can('update', 'SamlAuthProvider');
|
context.currentUser.can('update', 'SamlAuthProvider');
|
||||||
|
|
@@ -1,18 +1,7 @@
|
|||||||
import Context from '../../types/express/context';
|
|
||||||
import App from '../../models/app';
|
import App from '../../models/app';
|
||||||
import globalVariable from '../../helpers/global-variable';
|
import globalVariable from '../../helpers/global-variable';
|
||||||
|
|
||||||
type Params = {
|
const verifyConnection = async (_parent, params, context) => {
|
||||||
input: {
|
|
||||||
id: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const verifyConnection = async (
|
|
||||||
_parent: unknown,
|
|
||||||
params: Params,
|
|
||||||
context: Context
|
|
||||||
) => {
|
|
||||||
context.currentUser.can('create', 'Connection');
|
context.currentUser.can('create', 'Connection');
|
||||||
|
|
||||||
let connection = await context.currentUser
|
let connection = await context.currentUser
|
Reference in New Issue
Block a user