feat: Move webhooks configuration from environment variable to UI
This commit is contained in:
@@ -10,6 +10,7 @@ import request from '../request';
|
||||
import api from '../../../api';
|
||||
import mergeRecords from '../../../utils/merge-records';
|
||||
import { isUserAdminOrProjectOwner } from '../../../utils/record-helpers';
|
||||
import { UserRoles } from '../../../constants/Enums';
|
||||
|
||||
export function* fetchCore() {
|
||||
const {
|
||||
@@ -17,6 +18,11 @@ export function* fetchCore() {
|
||||
included: { notificationServices: notificationServices1 },
|
||||
} = yield call(request, api.getCurrentUser, true);
|
||||
|
||||
let webhooks;
|
||||
if (user.role === UserRoles.ADMIN) {
|
||||
({ items: webhooks } = yield call(request, api.getWebhooks));
|
||||
}
|
||||
|
||||
let users1;
|
||||
if (isUserAdminOrProjectOwner(user)) {
|
||||
({ items: users1 } = yield call(request, api.getUsers));
|
||||
@@ -101,6 +107,7 @@ export function* fetchCore() {
|
||||
return {
|
||||
user,
|
||||
board,
|
||||
webhooks,
|
||||
projectManagers,
|
||||
backgroundImages,
|
||||
baseCustomFieldGroups,
|
||||
|
||||
@@ -21,6 +21,7 @@ export function* initializeCore() {
|
||||
const {
|
||||
user,
|
||||
board,
|
||||
webhooks,
|
||||
users,
|
||||
projects,
|
||||
projectManagers,
|
||||
@@ -50,6 +51,7 @@ export function* initializeCore() {
|
||||
actions.initializeCore(
|
||||
user,
|
||||
board,
|
||||
webhooks,
|
||||
users,
|
||||
projects,
|
||||
projectManagers,
|
||||
|
||||
@@ -7,6 +7,7 @@ import router from './router';
|
||||
import socket from './socket';
|
||||
import core from './core';
|
||||
import modals from './modals';
|
||||
import webhooks from './webhooks';
|
||||
import users from './users';
|
||||
import projects from './projects';
|
||||
import projectManagers from './project-managers';
|
||||
@@ -33,6 +34,7 @@ export default {
|
||||
...socket,
|
||||
...core,
|
||||
...modals,
|
||||
...webhooks,
|
||||
...users,
|
||||
...projects,
|
||||
...projectManagers,
|
||||
|
||||
@@ -24,6 +24,7 @@ export function* handleSocketReconnect() {
|
||||
let config;
|
||||
let user;
|
||||
let board;
|
||||
let webhooks;
|
||||
let users;
|
||||
let projects;
|
||||
let projectManagers;
|
||||
@@ -51,6 +52,7 @@ export function* handleSocketReconnect() {
|
||||
({
|
||||
user,
|
||||
board,
|
||||
webhooks,
|
||||
users,
|
||||
projects,
|
||||
projectManagers,
|
||||
@@ -81,6 +83,7 @@ export function* handleSocketReconnect() {
|
||||
config,
|
||||
user,
|
||||
board,
|
||||
webhooks,
|
||||
users,
|
||||
projects,
|
||||
projectManagers,
|
||||
|
||||
@@ -70,6 +70,7 @@ export function* handleUserUpdate(user) {
|
||||
|
||||
let config;
|
||||
let board;
|
||||
let webhooks;
|
||||
let users1;
|
||||
let users2;
|
||||
let users3;
|
||||
@@ -102,6 +103,7 @@ export function* handleUserUpdate(user) {
|
||||
|
||||
if (user.role === UserRoles.ADMIN) {
|
||||
({ item: config } = yield call(request, api.getConfig));
|
||||
({ items: webhooks } = yield call(request, api.getWebhooks));
|
||||
|
||||
({
|
||||
items: projects,
|
||||
@@ -164,6 +166,7 @@ export function* handleUserUpdate(user) {
|
||||
boardIds,
|
||||
config,
|
||||
board,
|
||||
webhooks,
|
||||
mergeRecords(users1, users2, users3),
|
||||
projects,
|
||||
projectManagers,
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
import { call, put } from 'redux-saga/effects';
|
||||
|
||||
import request from '../request';
|
||||
import actions from '../../../actions';
|
||||
import api from '../../../api';
|
||||
import { createLocalId } from '../../../utils/local-id';
|
||||
|
||||
export function* createWebhook(data) {
|
||||
const localId = yield call(createLocalId);
|
||||
|
||||
yield put(
|
||||
actions.createWebhook({
|
||||
...data,
|
||||
id: localId,
|
||||
}),
|
||||
);
|
||||
|
||||
let webhook;
|
||||
try {
|
||||
({ item: webhook } = yield call(request, api.createWebhook, {
|
||||
...data,
|
||||
events: data.events && data.events.join(','),
|
||||
excludedEvents: data.excludedEvents && data.excludedEvents.join(','),
|
||||
}));
|
||||
} catch (error) {
|
||||
yield put(actions.createWebhook.failure(localId, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(actions.createWebhook.success(localId, webhook));
|
||||
}
|
||||
|
||||
export function* handleWebhookCreate(webhook) {
|
||||
yield put(actions.handleWebhookCreate(webhook));
|
||||
}
|
||||
|
||||
export function* updateWebhook(id, data) {
|
||||
yield put(actions.updateWebhook(id, data));
|
||||
|
||||
let webhook;
|
||||
try {
|
||||
({ item: webhook } = yield call(request, api.updateWebhook, id, {
|
||||
...data,
|
||||
events: data.events && data.events.join(','),
|
||||
excludedEvents: data.excludedEvents && data.excludedEvents.join(','),
|
||||
}));
|
||||
} catch (error) {
|
||||
yield put(actions.updateWebhook.failure(id, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(actions.updateWebhook.success(webhook));
|
||||
}
|
||||
|
||||
export function* handleWebhookUpdate(webhook) {
|
||||
yield put(actions.handleWebhookUpdate(webhook));
|
||||
}
|
||||
|
||||
export function* deleteWebhook(id) {
|
||||
yield put(actions.deleteWebhook(id));
|
||||
|
||||
let webhook;
|
||||
try {
|
||||
({ item: webhook } = yield call(request, api.deleteWebhook, id));
|
||||
} catch (error) {
|
||||
yield put(actions.deleteWebhook.failure(id, error));
|
||||
return;
|
||||
}
|
||||
|
||||
yield put(actions.deleteWebhook.success(webhook));
|
||||
}
|
||||
|
||||
export function* handleWebhookDelete(webhook) {
|
||||
yield put(actions.handleWebhookDelete(webhook));
|
||||
}
|
||||
|
||||
export default {
|
||||
createWebhook,
|
||||
handleWebhookCreate,
|
||||
updateWebhook,
|
||||
handleWebhookUpdate,
|
||||
deleteWebhook,
|
||||
handleWebhookDelete,
|
||||
};
|
||||
@@ -7,6 +7,7 @@ import router from './router';
|
||||
import socket from './socket';
|
||||
import core from './core';
|
||||
import modals from './modals';
|
||||
import webhooks from './webhooks';
|
||||
import users from './users';
|
||||
import projects from './projects';
|
||||
import projectManagers from './project-managers';
|
||||
@@ -33,6 +34,7 @@ export default [
|
||||
socket,
|
||||
core,
|
||||
modals,
|
||||
webhooks,
|
||||
users,
|
||||
projects,
|
||||
projectManagers,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
import { all, takeEvery } from 'redux-saga/effects';
|
||||
|
||||
import services from '../services';
|
||||
import EntryActionTypes from '../../../constants/EntryActionTypes';
|
||||
|
||||
export default function* webhooksWatchers() {
|
||||
yield all([
|
||||
takeEvery(EntryActionTypes.WEBHOOK_CREATE, ({ payload: { data } }) =>
|
||||
services.createWebhook(data),
|
||||
),
|
||||
takeEvery(EntryActionTypes.WEBHOOK_CREATE_HANDLE, ({ payload: { webhook } }) =>
|
||||
services.handleWebhookCreate(webhook),
|
||||
),
|
||||
takeEvery(EntryActionTypes.WEBHOOK_UPDATE, ({ payload: { id, data } }) =>
|
||||
services.updateWebhook(id, data),
|
||||
),
|
||||
takeEvery(EntryActionTypes.WEBHOOK_UPDATE_HANDLE, ({ payload: { webhook } }) =>
|
||||
services.handleWebhookUpdate(webhook),
|
||||
),
|
||||
takeEvery(EntryActionTypes.WEBHOOK_DELETE, ({ payload: { id } }) => services.deleteWebhook(id)),
|
||||
takeEvery(EntryActionTypes.WEBHOOK_DELETE_HANDLE, ({ payload: { webhook } }) =>
|
||||
services.handleWebhookDelete(webhook),
|
||||
),
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user