improve: change db schema for settings
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from api import require_auth, limiter
|
||||
from api import require_auth
|
||||
from db import get_db
|
||||
from db.models.Webhook import Webhook
|
||||
from db.models.WebhookSetting import WebhookSetting
|
||||
@@ -70,7 +70,6 @@ def delete_webhook(webhook_id):
|
||||
return jsonify({'message': 'Webhook deleted'}), 200
|
||||
|
||||
|
||||
|
||||
@webhook_bp.route('/setting/', methods=['GET'])
|
||||
@require_auth(roles=['admin'])
|
||||
def list_webhook_settings():
|
||||
@@ -78,6 +77,7 @@ def list_webhook_settings():
|
||||
settings = session.query(WebhookSetting).all()
|
||||
return jsonify([s.to_dict() for s in settings]), 200
|
||||
|
||||
|
||||
@webhook_bp.route('/setting/<int:setting_id>', methods=['GET'])
|
||||
@require_auth(roles=['admin'])
|
||||
def webhook_setting(setting_id):
|
||||
@@ -88,27 +88,12 @@ def webhook_setting(setting_id):
|
||||
return jsonify(setting.to_dict()), 200
|
||||
|
||||
|
||||
@webhook_bp.route('/setting/path/<int:path_id>', methods=['GET'])
|
||||
@require_auth(roles=['admin'])
|
||||
def webhook_setting_by_path(path_id):
|
||||
with get_db() as session:
|
||||
setting = session.query(WebhookSetting).filter(WebhookSetting.path_id == path_id).first()
|
||||
if not setting:
|
||||
return jsonify({'info': 'Webhook setting not found'}), 204
|
||||
return jsonify(setting.to_dict()), 200
|
||||
|
||||
@webhook_bp.route('/setting/', methods=['POST'])
|
||||
@require_auth(roles=['admin'])
|
||||
def create_webhook_setting():
|
||||
data = request.json
|
||||
print(data)
|
||||
required = ['path_id', 'webhook_id']
|
||||
for key in required:
|
||||
if key not in data:
|
||||
return jsonify({'error': 'Required field missing'}), 400
|
||||
with get_db() as session:
|
||||
setting = WebhookSetting(
|
||||
path_id=data.get('path_id'),
|
||||
webhook_id=data.get('webhook_id'),
|
||||
recursive=data.get('recursive', False),
|
||||
additional_header=data.get('additional_header', ''),
|
||||
@@ -118,6 +103,8 @@ def create_webhook_setting():
|
||||
session.add(setting)
|
||||
session.commit()
|
||||
return jsonify(setting.to_dict()), 201
|
||||
|
||||
|
||||
@webhook_bp.route('/setting/<int:setting_id>', methods=['PUT', 'PATCH'])
|
||||
@require_auth(roles=['admin'])
|
||||
def update_webhook_setting(setting_id):
|
||||
@@ -126,7 +113,8 @@ def update_webhook_setting(setting_id):
|
||||
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:
|
||||
@@ -139,6 +127,7 @@ def update_webhook_setting(setting_id):
|
||||
session.commit()
|
||||
return jsonify(setting.to_dict()), 200
|
||||
|
||||
|
||||
@webhook_bp.route('/setting/<int:setting_id>', methods=['DELETE'])
|
||||
@require_auth(roles=['admin'])
|
||||
def delete_webhook_setting(setting_id):
|
||||
|
||||
Reference in New Issue
Block a user