Compare commits

..

18 Commits

Author SHA1 Message Date
Rıdvan Akca
d893a36a47 feat(changedetection): add changed watch trigger 2024-05-13 17:18:19 +02:00
Rıdvan Akca
c62aea3852 feat(changedetection): add delete watch action 2024-05-13 16:31:58 +02:00
Rıdvan Akca
58c90da385 feat(changedetection): add create watch action 2024-05-13 16:31:18 +02:00
Rıdvan Akca
c095d3138b feat(changedetection): add changedetection integration 2024-05-13 16:28:05 +02:00
Ali BARIN
9548c93b4c Merge pull request #1867 from automatisch/custom-user-seed
add POST /api/v1/installation/users to seed user
2024-05-13 16:19:37 +02:00
Ali BARIN
4144944ab2 refactor(migrations): rename installation completed migration 2024-05-13 14:12:46 +00:00
Ali BARIN
46b85519c1 refactor(User/createAdmin): mark installation completed 2024-05-13 14:10:21 +00:00
Ali BARIN
5a83fc33ec refactor(User): rename createAdminUser with createAdmin 2024-05-13 14:09:09 +00:00
Ali BARIN
c80791267f refactor(installation): improve allow installation guard 2024-05-13 14:00:12 +00:00
Ali BARIN
b30f97db3e feat: add POST /api/v1/installation/users to seed user 2024-05-13 13:31:16 +00:00
Ali BARIN
717c81fa2b test(global-hooks): truncate config table 2024-05-13 13:31:16 +00:00
Ali BARIN
ae188bc563 feat: add migration to mark userful instances installation completed 2024-05-13 13:31:16 +00:00
Ali BARIN
fc4561221d feat: add DISABLE_SEED_USER to bypass yarn db:seed:user command 2024-05-13 13:31:16 +00:00
Ali BARIN
5aeb4f8809 Merge pull request #1883 from automatisch/checkisenterprise
feat: remove checkIsEnterprise middleware from admin users
2024-05-13 15:30:55 +02:00
Ali BARIN
c6c900bc39 test(get-users.ee): remove license mock 2024-05-13 13:20:48 +00:00
Rıdvan Akca
c18ab67a25 feat: remove checkIsEnterprise middleware from admin users 2024-05-13 15:02:10 +02:00
Ali BARIN
55ae1470d0 Merge pull request #1875 from automatisch/logout-saml 2024-05-13 13:51:49 +02:00
Ömer Faruk Aydın
a1136fdfb2 Merge pull request #1882 from automatisch/no-proxy
feat: add no_proxy support in http(s) agents
2024-05-13 13:43:39 +02:00
31 changed files with 344 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ import appConfig from '../../src/config/app.js';
import logger from '../../src/helpers/logger.js';
import client from './client.js';
import User from '../../src/models/user.js';
import Config from '../../src/models/config.js';
import Role from '../../src/models/role.js';
import '../../src/config/orm.js';
import process from 'process';
@@ -45,6 +46,8 @@ export async function createUser(
if (userCount === 0) {
const user = await User.query().insertAndFetch(userParams);
logger.info(`User has been saved: ${user.email}`);
await Config.markInstallationCompleted();
} else {
logger.info('No need to seed a user.');
}

View File

@@ -0,0 +1,29 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Create a watch',
key: 'createWatch',
description: 'Creates a new change detection watch for a specific website.',
arguments: [
{
label: 'URL',
key: 'url',
type: 'string',
required: true,
variables: true,
description: 'Url you want to monitor',
},
],
async run($) {
const url = $.step.parameters.url;
const body = {
url,
};
const response = await $.http.post('/v1/watch', body);
$.setActionItem({ raw: response.data });
},
});

View File

@@ -0,0 +1,29 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Delete a watch',
key: 'deleteWatch',
description: 'Deletes a change detection watch.',
arguments: [
{
label: 'Watch ID',
key: 'watchId',
type: 'string',
required: true,
variables: true,
description: 'Watch id you want to delete',
},
],
async run($) {
const watchId = $.step.parameters.watchId;
await $.http.delete(`/v1/watch/${watchId}`);
$.setActionItem({
raw: {
result: 'successful',
},
});
},
});

View File

@@ -0,0 +1,4 @@
import createWatch from './create-watch/index.js';
import deleteWatch from './delete-watch/index.js';
export default [createWatch, deleteWatch];

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

@@ -0,0 +1,44 @@
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Screen name of your connection to be used on Automatisch UI.',
clickToCopy: false,
},
{
key: 'instanceUrl',
label: 'Instance URL',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: null,
clickToCopy: false,
},
{
key: 'apiKey',
label: 'API Key',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Changedetection API key of your account.',
clickToCopy: false,
},
],
verifyCredentials,
isStillVerified,
};

View File

@@ -0,0 +1,8 @@
import verifyCredentials from './verify-credentials.js';
const isStillVerified = async ($) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -0,0 +1,10 @@
const verifyCredentials = async ($) => {
await $.http.get('/v1/systeminfo');
await $.auth.set({
screenName: $.auth.data.screenName,
apiKey: $.auth.data.apiKey,
});
};
export default verifyCredentials;

View File

@@ -0,0 +1,9 @@
const addAuthHeader = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
requestConfig.headers['x-api-key'] = $.auth.data.apiKey;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -0,0 +1,10 @@
const setBaseUrl = ($, requestConfig) => {
const instanceUrl = $.auth.data.instanceUrl;
if (instanceUrl) {
requestConfig.baseURL = `${instanceUrl}/api`;
}
return requestConfig;
};
export default setBaseUrl;

View File

@@ -0,0 +1,3 @@
import listWatches from './list-watches/index.js';
export default [listWatches];

View File

@@ -0,0 +1,24 @@
export default {
name: 'List watches',
key: 'listWatches',
async run($) {
const watches = {
data: [],
};
const { data } = await $.http.get('/v1/watch');
const watchIds = Object.keys(data);
if (watchIds?.length) {
for (const watchId of watchIds) {
watches.data.push({
value: watchId,
name: data[watchId].url,
});
}
}
return watches;
},
};

View File

@@ -0,0 +1,23 @@
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import setBaseUrl from './common/set-base-url.js';
import actions from './actions/index.js';
import dynamicData from './dynamic-data/index.js';
import triggers from './triggers/index.js';
export default defineApp({
name: 'Changedetection',
key: 'changedetection',
iconUrl: '{BASE_URL}/apps/changedetection/assets/favicon.svg',
authDocUrl: '{DOCS_URL}/apps/changedetection/connection',
supportsConnections: true,
baseUrl: 'https://changedetection.io',
apiBaseUrl: '',
primaryColor: '3056d3',
beforeRequest: [setBaseUrl, addAuthHeader],
auth,
actions,
dynamicData,
triggers,
});

View File

@@ -0,0 +1,43 @@
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Changed watch',
key: 'changedWatch',
pollInterval: 15,
description: 'Triggers when any changes detected.',
arguments: [
{
label: 'Watch',
key: 'watchId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listWatches',
},
],
},
},
],
async run($) {
const watchId = $.step.parameters.watchId;
const { data } = await $.http.get(`v1/watch/${watchId}`);
if (Object.keys(data).length !== 0) {
$.pushTriggerItem({
raw: data,
meta: {
internalId: `${watchId}-${data.last_changed}`,
},
});
}
},
});

View File

@@ -0,0 +1,3 @@
import changedWatch from './changed-watch/index.js';
export default [changedWatch];

View File

@@ -1,11 +1,10 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import { describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../../../../app';
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id';
import { createRole } from '../../../../../../test/factories/role';
import { createUser } from '../../../../../../test/factories/user';
import getUsersMock from '../../../../../../test/mocks/rest/api/v1/admin/users/get-users.js';
import * as license from '../../../../../helpers/license.ee.js';
describe('GET /api/v1/admin/users', () => {
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
@@ -32,8 +31,6 @@ describe('GET /api/v1/admin/users', () => {
});
it('should return users data', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const response = await request(app)
.get('/api/v1/admin/users')
.set('Authorization', token)

View File

@@ -1,12 +1,9 @@
import User from '../../../../../models/user.js';
import Config from '../../../../../models/config.js';
export default async (request, response) => {
const { email, password, fullName } = request.body;
await User.createAdminUser({ email, password, fullName });
await Config.markInstallationCompleted();
await User.createAdmin({ email, password, fullName });
response.status(204).end();
};

View File

@@ -4,6 +4,7 @@ import app from '../../../../../app.js';
import Config from '../../../../../models/config.js';
import User from '../../../../../models/user.js';
import { createRole } from '../../../../../../test/factories/role';
import { createUser } from '../../../../../../test/factories/user';
import { createInstallationCompletedConfig } from '../../../../../../test/factories/config';
describe('POST /api/v1/installation/users', () => {
@@ -17,7 +18,7 @@ describe('POST /api/v1/installation/users', () => {
});
describe('for incomplete installations', () => {
it('should respond with HTTP 204 with correct payload', async () => {
it('should respond with HTTP 204 with correct payload when no user', async () => {
expect(await Config.isInstallationCompleted()).toBe(false);
await request(app)
@@ -34,6 +35,27 @@ describe('POST /api/v1/installation/users', () => {
expect(user.roleId).toBe(adminRole.id);
expect(await Config.isInstallationCompleted()).toBe(true);
});
it('should respond with HTTP 403 with correct payload when one user exists at least', async () => {
expect(await Config.isInstallationCompleted()).toBe(false);
await createUser();
const usersCountBefore = await User.query().resultSize();
await request(app)
.post('/api/v1/installation/users')
.send({
email: 'user@automatisch.io',
password: 'password',
fullName: 'Initial admin'
})
.expect(403);
const usersCountAfter = await User.query().resultSize();
expect(usersCountBefore).toEqual(usersCountAfter);
});
});
describe('for completed installations', () => {

View File

@@ -0,0 +1,16 @@
import Config from '../models/config.js';
import User from '../models/user.js';
export async function allowInstallation(request, response, next) {
if (await Config.isInstallationCompleted()) {
return response.status(403).end();
}
const hasAnyUsers = await User.query().resultSize() > 0;
if (hasAnyUsers) {
return response.status(403).end();
}
next();
};

View File

@@ -1,9 +0,0 @@
import Config from '../models/config.js';
export async function authorizeInstallation(request, response, next) {
if (await Config.isInstallationCompleted()) {
return response.status(403).end();
} else {
next();
}
};

View File

@@ -10,6 +10,7 @@ import Base from './base.js';
import App from './app.js';
import AccessToken from './access-token.js';
import Connection from './connection.js';
import Config from './config.js';
import Execution from './execution.js';
import Flow from './flow.js';
import Identity from './identity.ee.js';
@@ -373,7 +374,7 @@ class User extends Base {
return apps;
}
static async createAdminUser({ email, password, fullName }) {
static async createAdmin({ email, password, fullName }) {
const adminRole = await Role.findAdmin();
const adminUser = await this.query().insert({
@@ -383,6 +384,8 @@ class User extends Base {
roleId: adminRole.id
});
await Config.markInstallationCompleted();
return adminUser;
}

View File

@@ -2,25 +2,17 @@ import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authenticateUser } from '../../../../helpers/authentication.js';
import { authorizeAdmin } from '../../../../helpers/authorization.js';
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
import getUsersAction from '../../../../controllers/api/v1/admin/users/get-users.ee.js';
import getUserAction from '../../../../controllers/api/v1/admin/users/get-user.ee.js';
const router = Router();
router.get(
'/',
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getUsersAction)
);
router.get('/', authenticateUser, authorizeAdmin, asyncHandler(getUsersAction));
router.get(
'/:userId',
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getUserAction)
);

View File

@@ -1,13 +1,13 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import { authorizeInstallation } from '../../../../helpers/authorize-installation.js';
import { allowInstallation } from '../../../../helpers/allow-installation.js';
import createUserAction from '../../../../controllers/api/v1/installation/users/create-user.js';
const router = Router();
router.post(
'/',
authorizeInstallation,
allowInstallation,
asyncHandler(createUserAction)
);

View File

@@ -41,6 +41,16 @@ export default defineConfig({
{ text: 'Connection', link: '/apps/carbone/connection' },
],
},
{
text: 'Changedetection',
collapsible: true,
collapsed: true,
items: [
{ text: 'Triggers', link: '/apps/changedetection/triggers' },
{ text: 'Actions', link: '/apps/changedetection/actions' },
{ text: 'Connection', link: '/apps/changedetection/connection' },
],
},
{
text: 'Datastore',
collapsible: true,

View File

@@ -0,0 +1,14 @@
---
favicon: /favicons/changedetection.svg
items:
- name: Create a watch
desc: Creates a new change detection watch for a specific website.
- name: Delete a watch
desc: Deletes a change detection watch.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -0,0 +1,14 @@
# Changedetection
:::info
This page explains the steps you need to follow to set up the Changedetection
connection in Automatisch. If any of the steps are outdated, please let us know!
:::
1. Go to your Changedetection admin panel.
2. Click on the **Settings** button.
3. Click on the **API** tab.
4. Copy **API key** from the page to the `API Key` field on Automatisch.
5. Add your Instance URL in the **Instance URL** field on Automatisch.
6. Write any screen name to be displayed in Automatisch.
7. Now, you can start using the Changedetection connection with Automatisch.

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/changedetection.svg
items:
- name: Changed watch
desc: Triggers when any changes detected.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -3,6 +3,7 @@
The following integrations are currently supported by Automatisch.
- [Carbone](/apps/carbone/actions)
- [Changedetection](/apps/changedetection/actions)
- [Datastore](/apps/datastore/actions)
- [DeepL](/apps/deepl/actions)
- [Delay](/apps/delay/actions)

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.9 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.9 KiB