Added ChannelPlugin menu for debugging
This commit is contained in:
		
							parent
							
								
									be4cac6b24
								
							
						
					
					
						commit
						1e4ac60365
					
				
					 4 changed files with 87 additions and 33 deletions
				
			
		| 
						 | 
				
			
			@ -1,24 +1,21 @@
 | 
			
		|||
import json
 | 
			
		||||
import os.path
 | 
			
		||||
from functools import wraps
 | 
			
		||||
 | 
			
		||||
import structlog
 | 
			
		||||
from flask import (
 | 
			
		||||
    Blueprint,
 | 
			
		||||
    render_template,
 | 
			
		||||
    g,
 | 
			
		||||
    flash,
 | 
			
		||||
    request,
 | 
			
		||||
    session,
 | 
			
		||||
    redirect,
 | 
			
		||||
    url_for,
 | 
			
		||||
    flash,
 | 
			
		||||
    g,
 | 
			
		||||
    redirect,
 | 
			
		||||
    render_template,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
from butterrobot.config import HOSTNAME
 | 
			
		||||
from butterrobot.db import UserQuery, ChannelQuery, ChannelPluginQuery
 | 
			
		||||
from butterrobot.plugins import get_available_plugins
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
admin = Blueprint("admin", __name__, url_prefix="/admin")
 | 
			
		||||
admin.template_folder = os.path.join(os.path.dirname(__name__), "templates")
 | 
			
		||||
logger = structlog.get_logger(__name__)
 | 
			
		||||
| 
						 | 
				
			
			@ -99,7 +96,8 @@ def channel_list_view():
 | 
			
		|||
def channel_detail_view(channel_id):
 | 
			
		||||
    if request.method == "POST":
 | 
			
		||||
        ChannelQuery.update(
 | 
			
		||||
            channel_id, enabled=request.form["enabled"] == "true",
 | 
			
		||||
            channel_id,
 | 
			
		||||
            enabled=request.form["enabled"] == "true",
 | 
			
		||||
        )
 | 
			
		||||
        flash("Channel updated", "success")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -117,9 +115,10 @@ def channel_delete_view(channel_id):
 | 
			
		|||
    return redirect(url_for("admin.channel_list_view"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.route("/channelplugins", methods=["POST"])
 | 
			
		||||
@admin.route("/channelplugins", methods=["GET", "POST"])
 | 
			
		||||
@login_required
 | 
			
		||||
def channel_plugin_list_view():
 | 
			
		||||
    if request.method == "POST":
 | 
			
		||||
        data = request.form
 | 
			
		||||
        try:
 | 
			
		||||
            ChannelPluginQuery.create(
 | 
			
		||||
| 
						 | 
				
			
			@ -127,16 +126,22 @@ def channel_plugin_list_view():
 | 
			
		|||
            )
 | 
			
		||||
            flash(f"Plugin {data['plugin_id']} added to the channel", "success")
 | 
			
		||||
        except ChannelPluginQuery.Duplicated:
 | 
			
		||||
        flash(f"Plugin {data['plugin_id']} is already present on the channel", "error")
 | 
			
		||||
            flash(
 | 
			
		||||
                f"Plugin {data['plugin_id']} is already present on the channel", "error"
 | 
			
		||||
            )
 | 
			
		||||
        return redirect(request.headers.get("Referer"))
 | 
			
		||||
 | 
			
		||||
    channel_plugins = ChannelPluginQuery.all()
 | 
			
		||||
    return render_template("channel_plugins_list.j2", channel_plugins=channel_plugins)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@admin.route("/channelplugins/<channel_plugin_id>", methods=["GET", "POST"])
 | 
			
		||||
@login_required
 | 
			
		||||
def channel_plugin_detail_view(channel_plugin_id):
 | 
			
		||||
    if request.method == "POST":
 | 
			
		||||
        ChannelPluginQuery.update(
 | 
			
		||||
            channel_plugin_id, enabled=request.form["enabled"] == "true",
 | 
			
		||||
            channel_plugin_id,
 | 
			
		||||
            enabled=request.form["enabled"] == "true",
 | 
			
		||||
        )
 | 
			
		||||
        flash("Plugin updated", category="success")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,7 +43,7 @@
 | 
			
		|||
                    <div class="navbar navbar-light">
 | 
			
		||||
                        <div class="container-xl">
 | 
			
		||||
                            <ul class="navbar-nav">
 | 
			
		||||
                                <li class="nav-item {% if 'channels' in request.url %}active{% endif %}">
 | 
			
		||||
                                <li class="nav-item {% if '/channels' in request.url %}active{% endif %}">
 | 
			
		||||
                                    <a class="nav-link" href="{{ url_for('admin.channel_list_view') }}">
 | 
			
		||||
                                        <span class="nav-link-icon d-md-none d-lg-inline-block">
 | 
			
		||||
                                            <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24"
 | 
			
		||||
| 
						 | 
				
			
			@ -60,7 +60,7 @@
 | 
			
		|||
                                        </span>
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                </li>
 | 
			
		||||
                                <li class="nav-item {% if 'plugins' in request.url %}active{% endif %}">
 | 
			
		||||
                                <li class="nav-item {% if '/plugins' in request.url %}active{% endif %}">
 | 
			
		||||
                                    <a class="nav-link" href="{{ url_for('admin.plugin_list_view') }}">
 | 
			
		||||
                                        <span class="nav-link-icon d-md-none d-lg-inline-block">
 | 
			
		||||
                                            <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24"
 | 
			
		||||
| 
						 | 
				
			
			@ -76,6 +76,22 @@
 | 
			
		|||
                                        </span>
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                </li>
 | 
			
		||||
                                <li class="nav-item {% if '/channelplugins' in request.url %}active{% endif %}">
 | 
			
		||||
                                   <a class="nav-link" href="{{ url_for('admin.channel_plugin_list_view') }}">
 | 
			
		||||
                                        <span class="nav-link-icon d-md-none d-lg-inline-block">
 | 
			
		||||
                                            <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24"
 | 
			
		||||
                                                viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
 | 
			
		||||
                                                stroke-linecap="round" stroke-linejoin="round">
 | 
			
		||||
                                                <path stroke="none" d="M0 0h24v24H0z" fill="none" />
 | 
			
		||||
                                                <path
 | 
			
		||||
                                                    d="M4 7h3a1 1 0 0 0 1 -1v-1a2 2 0 0 1 4 0v1a1 1 0 0 0 1 1h3a1 1 0 0 1 1 1v3a1 1 0 0 0 1 1h1a2 2 0 0 1 0 4h-1a1 1 0 0 0 -1 1v3a1 1 0 0 1 -1 1h-3a1 1 0 0 1 -1 -1v-1a2 2 0 0 0 -4 0v1a1 1 0 0 1 -1 1h-3a1 1 0 0 1 -1 -1v-3a1 1 0 0 1 1 -1h1a2 2 0 0 0 0 -4h-1a1 1 0 0 1 -1 -1v-3a1 1 0 0 1 1 -1" />
 | 
			
		||||
                                            </svg>
 | 
			
		||||
                                        </span>
 | 
			
		||||
                                        <span class="nav-link-title">
 | 
			
		||||
                                            Channel Plugins
 | 
			
		||||
                                        </span>
 | 
			
		||||
                                    </a>
 | 
			
		||||
                                </li>
 | 
			
		||||
                            </ul>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										41
									
								
								butterrobot/admin/templates/channel_plugins_list.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								butterrobot/admin/templates/channel_plugins_list.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
{% extends "_base.j2" %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
<div class="page-header d-print-none">
 | 
			
		||||
    <div class="row align-items-center">
 | 
			
		||||
        <div class="col">
 | 
			
		||||
            <h2 class="page-title">
 | 
			
		||||
                Channel list
 | 
			
		||||
            </h2>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="row">
 | 
			
		||||
    <div class="table-responsive">
 | 
			
		||||
        <table class="table table-vcenter card-table">
 | 
			
		||||
            <thead>
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <th>ID</th>
 | 
			
		||||
                    <th>Channel ID</th>
 | 
			
		||||
                    <th>Plugin ID</th>
 | 
			
		||||
                    <th>Enabled</th>
 | 
			
		||||
                </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
 | 
			
		||||
            <tbody>
 | 
			
		||||
                {% for channel_plugin in channel_plugins %}
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <td>{{ channel_plugin.id }}</td>
 | 
			
		||||
                    <td>{{ channel_plugin.channel_id }}</td>
 | 
			
		||||
                    <td class="text-muted">
 | 
			
		||||
                        {{ channel_plugin.plugin_id }}
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td class="text-muted">{{ channel_plugin.enabled }}</td>
 | 
			
		||||
                </tr>
 | 
			
		||||
                {% endfor %}
 | 
			
		||||
            </tbody>
 | 
			
		||||
        </table>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,23 +1,15 @@
 | 
			
		|||
import asyncio
 | 
			
		||||
import traceback
 | 
			
		||||
from dataclasses import asdict
 | 
			
		||||
from functools import lru_cache
 | 
			
		||||
 | 
			
		||||
from flask import Flask, request, jsonify
 | 
			
		||||
import structlog
 | 
			
		||||
from flask import Flask, request
 | 
			
		||||
 | 
			
		||||
import butterrobot.logging  # noqa
 | 
			
		||||
from butterrobot.queue import q
 | 
			
		||||
from butterrobot.db import ChannelQuery
 | 
			
		||||
from butterrobot.config import SECRET_KEY, HOSTNAME
 | 
			
		||||
from butterrobot.objects import Message, Channel
 | 
			
		||||
from butterrobot.http import ExternalProxyFix
 | 
			
		||||
from butterrobot.plugins import get_available_plugins
 | 
			
		||||
from butterrobot.platforms import PLATFORMS, get_available_platforms
 | 
			
		||||
from butterrobot.platforms.base import Platform
 | 
			
		||||
from butterrobot.queue import q
 | 
			
		||||
from butterrobot.config import SECRET_KEY
 | 
			
		||||
from butterrobot.platforms import get_available_platforms
 | 
			
		||||
from butterrobot.admin.blueprint import admin as admin_bp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
loop = asyncio.get_event_loop()
 | 
			
		||||
logger = structlog.get_logger(__name__)
 | 
			
		||||
app = Flask(__name__)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue