Compare commits

..

15 Commits

Author SHA1 Message Date
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
20 changed files with 173 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 logger from '../../src/helpers/logger.js';
import client from './client.js'; import client from './client.js';
import User from '../../src/models/user.js'; import User from '../../src/models/user.js';
import Config from '../../src/models/config.js';
import Role from '../../src/models/role.js'; import Role from '../../src/models/role.js';
import '../../src/config/orm.js'; import '../../src/config/orm.js';
import process from 'process'; import process from 'process';
@@ -45,6 +46,8 @@ export async function createUser(
if (userCount === 0) { if (userCount === 0) {
const user = await User.query().insertAndFetch(userParams); const user = await User.query().insertAndFetch(userParams);
logger.info(`User has been saved: ${user.email}`); logger.info(`User has been saved: ${user.email}`);
await Config.markInstallationCompleted();
} else { } else {
logger.info('No need to seed a user.'); logger.info('No need to seed a user.');
} }

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,17 @@
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';
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,
});

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

View File

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

View File

@@ -4,6 +4,7 @@ import app from '../../../../../app.js';
import Config from '../../../../../models/config.js'; import Config from '../../../../../models/config.js';
import User from '../../../../../models/user.js'; import User from '../../../../../models/user.js';
import { createRole } from '../../../../../../test/factories/role'; import { createRole } from '../../../../../../test/factories/role';
import { createUser } from '../../../../../../test/factories/user';
import { createInstallationCompletedConfig } from '../../../../../../test/factories/config'; import { createInstallationCompletedConfig } from '../../../../../../test/factories/config';
describe('POST /api/v1/installation/users', () => { describe('POST /api/v1/installation/users', () => {
@@ -17,7 +18,7 @@ describe('POST /api/v1/installation/users', () => {
}); });
describe('for incomplete installations', () => { 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); expect(await Config.isInstallationCompleted()).toBe(false);
await request(app) await request(app)
@@ -34,6 +35,27 @@ describe('POST /api/v1/installation/users', () => {
expect(user.roleId).toBe(adminRole.id); expect(user.roleId).toBe(adminRole.id);
expect(await Config.isInstallationCompleted()).toBe(true); 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', () => { 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 App from './app.js';
import AccessToken from './access-token.js'; import AccessToken from './access-token.js';
import Connection from './connection.js'; import Connection from './connection.js';
import Config from './config.js';
import Execution from './execution.js'; import Execution from './execution.js';
import Flow from './flow.js'; import Flow from './flow.js';
import Identity from './identity.ee.js'; import Identity from './identity.ee.js';
@@ -373,7 +374,7 @@ class User extends Base {
return apps; return apps;
} }
static async createAdminUser({ email, password, fullName }) { static async createAdmin({ email, password, fullName }) {
const adminRole = await Role.findAdmin(); const adminRole = await Role.findAdmin();
const adminUser = await this.query().insert({ const adminUser = await this.query().insert({
@@ -383,6 +384,8 @@ class User extends Base {
roleId: adminRole.id roleId: adminRole.id
}); });
await Config.markInstallationCompleted();
return adminUser; return adminUser;
} }

View File

@@ -2,25 +2,17 @@ import { Router } from 'express';
import asyncHandler from 'express-async-handler'; 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 getUsersAction from '../../../../controllers/api/v1/admin/users/get-users.ee.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'; import getUserAction from '../../../../controllers/api/v1/admin/users/get-user.ee.js';
const router = Router(); const router = Router();
router.get( router.get('/', authenticateUser, authorizeAdmin, asyncHandler(getUsersAction));
'/',
authenticateUser,
authorizeAdmin,
checkIsEnterprise,
asyncHandler(getUsersAction)
);
router.get( router.get(
'/:userId', '/:userId',
authenticateUser, authenticateUser,
authorizeAdmin, authorizeAdmin,
checkIsEnterprise,
asyncHandler(getUserAction) asyncHandler(getUserAction)
); );

View File

@@ -1,13 +1,13 @@
import { Router } from 'express'; import { Router } from 'express';
import asyncHandler from 'express-async-handler'; 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'; import createUserAction from '../../../../controllers/api/v1/installation/users/create-user.js';
const router = Router(); const router = Router();
router.post( router.post(
'/', '/',
authorizeInstallation, allowInstallation,
asyncHandler(createUserAction) asyncHandler(createUserAction)
); );

View File

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

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.

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.9 KiB