add: template editor
This commit is contained in:
77
api/setting/path/webhook.py
Normal file
77
api/setting/path/webhook.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from flask import jsonify, request
|
||||
from api import require_auth
|
||||
from api.setting import setting_bp
|
||||
from db import get_db
|
||||
from db.models.WebhookSetting import WebhookSetting
|
||||
|
||||
|
||||
@setting_bp.route('/path/webhook/', methods=['GET'])
|
||||
@require_auth(roles=['admin'])
|
||||
def list_webhook_settings():
|
||||
with get_db() as session:
|
||||
settings = session.query(WebhookSetting).all()
|
||||
return jsonify([s.to_dict() for s in settings]), 200
|
||||
|
||||
|
||||
@setting_bp.route('/path/webhook/<int:setting_id>', methods=['GET'])
|
||||
@require_auth(roles=['admin'])
|
||||
def webhook_setting(setting_id):
|
||||
with get_db() as session:
|
||||
setting = session.query(WebhookSetting).filter(WebhookSetting.id == setting_id).first()
|
||||
if not setting:
|
||||
return jsonify({}), 204
|
||||
return jsonify(setting.to_dict()), 200
|
||||
|
||||
|
||||
@setting_bp.route('/path/webhook/', methods=['POST'])
|
||||
@require_auth(roles=['admin'])
|
||||
def create_webhook_setting():
|
||||
data = request.json
|
||||
with get_db() as session:
|
||||
setting = WebhookSetting(
|
||||
webhook_id=data.get('webhook_id'),
|
||||
recursive=data.get('recursive', False),
|
||||
additional_header=data.get('additional_header', ''),
|
||||
enabled=data.get('enabled', True),
|
||||
on_events=data.get('on_events', 1),
|
||||
)
|
||||
session.add(setting)
|
||||
session.commit()
|
||||
return jsonify(setting.to_dict()), 201
|
||||
|
||||
|
||||
@setting_bp.route('/path/webhook/<int:setting_id>', methods=['PUT', 'PATCH'])
|
||||
@require_auth(roles=['admin'])
|
||||
def update_webhook_setting(setting_id):
|
||||
data = request.json
|
||||
with get_db() as session:
|
||||
setting = session.query(WebhookSetting).get(setting_id)
|
||||
if not setting:
|
||||
return jsonify({'error': 'Webhook setting not found'}), 404
|
||||
if 'webhook_id' in data:
|
||||
setting.webhook_id = data['webhook_id']
|
||||
if 'recursive' in data:
|
||||
setting.recursive = data['recursive']
|
||||
if 'additional_header' in data:
|
||||
setting.additional_header = data['additional_header']
|
||||
if 'enabled' in data:
|
||||
setting.enabled = data['enabled']
|
||||
if 'on_events' in data:
|
||||
setting.on_events = data['on_events']
|
||||
|
||||
session.commit()
|
||||
return jsonify(setting.to_dict()), 200
|
||||
|
||||
|
||||
@setting_bp.route('/path/webhook/<int:setting_id>', methods=['DELETE'])
|
||||
@require_auth(roles=['admin'])
|
||||
def delete_webhook_setting(setting_id):
|
||||
with get_db() as session:
|
||||
setting = session.query(WebhookSetting).get(setting_id)
|
||||
if not setting:
|
||||
return jsonify({'error': 'Webhook setting not found'}), 404
|
||||
|
||||
session.delete(setting)
|
||||
session.commit()
|
||||
return jsonify({'message': 'Webhook setting deleted'}), 200
|
||||
|
||||
Reference in New Issue
Block a user