Add registry curation system with role-based moderation
Implement comprehensive moderation system for the CmdForge registry: - Role-based access control (user, moderator, admin) - Tool moderation workflow: pending → approved/rejected/removed - Tool visibility: public, private, unlisted - Publisher management: ban/unban with token revocation - Report resolution with configurable actions - Audit logging for all moderation actions Database changes: - Add role, banned columns to publishers table - Add visibility, moderation_status columns to tools table - Create audit_log table for accountability API additions: - Admin endpoints for tool moderation (approve/reject/remove) - Publisher management endpoints (ban/unban/role) - Report resolution endpoint - Audit log query endpoint Web UI: - Admin dashboard with stats overview - Pending tools queue with approve/reject - Publisher management with ban/role controls - Report queue with resolve actions - Role badge in dashboard sidebar Existing tools grandfathered as approved, all publishers default to user role. Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
+127
-2
@@ -159,13 +159,17 @@ def _load_current_publisher() -> Optional[Dict[str, Any]]:
|
||||
row = query_one(
|
||||
conn,
|
||||
"""
|
||||
SELECT id, slug, display_name, email, verified, bio, website, created_at
|
||||
SELECT id, slug, display_name, email, verified, bio, website, role, created_at
|
||||
FROM publishers
|
||||
WHERE slug = ?
|
||||
""",
|
||||
[slug],
|
||||
)
|
||||
return dict(row) if row else None
|
||||
if row:
|
||||
data = dict(row)
|
||||
data["role"] = data.get("role") or "user"
|
||||
return data
|
||||
return None
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@@ -822,3 +826,124 @@ def collection_detail(name: str):
|
||||
"pages/collection_detail.html",
|
||||
collection=collection,
|
||||
)
|
||||
|
||||
|
||||
# ============================================
|
||||
# Admin Dashboard Routes
|
||||
# ============================================
|
||||
|
||||
def _require_moderator_role():
|
||||
"""Check if current user has moderator or admin role."""
|
||||
redirect_response = _require_login()
|
||||
if redirect_response:
|
||||
return redirect_response
|
||||
user = _load_current_publisher()
|
||||
if not user or user.get("role") not in ("moderator", "admin"):
|
||||
return render_template("errors/403.html"), 403
|
||||
return None
|
||||
|
||||
|
||||
@web_bp.route("/dashboard/admin", endpoint="admin_dashboard")
|
||||
def admin_dashboard():
|
||||
"""Admin dashboard overview."""
|
||||
forbidden = _require_moderator_role()
|
||||
if forbidden:
|
||||
return forbidden
|
||||
|
||||
user = _load_current_publisher()
|
||||
token = session.get("auth_token")
|
||||
|
||||
# Get pending tools count
|
||||
status, payload = _api_get("/api/v1/admin/tools/pending?per_page=1", token=token)
|
||||
pending_count = payload.get("meta", {}).get("total", 0) if status == 200 else 0
|
||||
|
||||
# Get pending reports count
|
||||
status, payload = _api_get("/api/v1/admin/reports?status=pending&per_page=1", token=token)
|
||||
reports_count = payload.get("meta", {}).get("total", 0) if status == 200 else 0
|
||||
|
||||
# Get publisher count
|
||||
status, payload = _api_get("/api/v1/admin/publishers?per_page=1", token=token)
|
||||
publishers_count = payload.get("meta", {}).get("total", 0) if status == 200 else 0
|
||||
|
||||
return render_template(
|
||||
"admin/index.html",
|
||||
user=user,
|
||||
active_page="admin_overview",
|
||||
pending_count=pending_count,
|
||||
reports_count=reports_count,
|
||||
publishers_count=publishers_count,
|
||||
)
|
||||
|
||||
|
||||
@web_bp.route("/dashboard/admin/pending", endpoint="admin_pending")
|
||||
def admin_pending():
|
||||
"""List pending tools for moderation."""
|
||||
forbidden = _require_moderator_role()
|
||||
if forbidden:
|
||||
return forbidden
|
||||
|
||||
user = _load_current_publisher()
|
||||
token = session.get("auth_token")
|
||||
page = request.args.get("page", 1, type=int)
|
||||
|
||||
status, payload = _api_get(f"/api/v1/admin/tools/pending?page={page}", token=token)
|
||||
tools = payload.get("data", []) if status == 200 else []
|
||||
meta = payload.get("meta", {})
|
||||
|
||||
return render_template(
|
||||
"admin/pending.html",
|
||||
user=user,
|
||||
active_page="admin_pending",
|
||||
tools=tools,
|
||||
meta=meta,
|
||||
)
|
||||
|
||||
|
||||
@web_bp.route("/dashboard/admin/publishers", endpoint="admin_publishers")
|
||||
def admin_publishers():
|
||||
"""List all publishers."""
|
||||
forbidden = _require_moderator_role()
|
||||
if forbidden:
|
||||
return forbidden
|
||||
|
||||
user = _load_current_publisher()
|
||||
token = session.get("auth_token")
|
||||
page = request.args.get("page", 1, type=int)
|
||||
|
||||
status, payload = _api_get(f"/api/v1/admin/publishers?page={page}", token=token)
|
||||
publishers = payload.get("data", []) if status == 200 else []
|
||||
meta = payload.get("meta", {})
|
||||
|
||||
return render_template(
|
||||
"admin/publishers.html",
|
||||
user=user,
|
||||
active_page="admin_publishers",
|
||||
publishers=publishers,
|
||||
meta=meta,
|
||||
)
|
||||
|
||||
|
||||
@web_bp.route("/dashboard/admin/reports", endpoint="admin_reports")
|
||||
def admin_reports():
|
||||
"""List pending reports."""
|
||||
forbidden = _require_moderator_role()
|
||||
if forbidden:
|
||||
return forbidden
|
||||
|
||||
user = _load_current_publisher()
|
||||
token = session.get("auth_token")
|
||||
page = request.args.get("page", 1, type=int)
|
||||
status_filter = request.args.get("status", "pending")
|
||||
|
||||
status, payload = _api_get(f"/api/v1/admin/reports?page={page}&status={status_filter}", token=token)
|
||||
reports = payload.get("data", []) if status == 200 else []
|
||||
meta = payload.get("meta", {})
|
||||
|
||||
return render_template(
|
||||
"admin/reports.html",
|
||||
user=user,
|
||||
active_page="admin_reports",
|
||||
reports=reports,
|
||||
meta=meta,
|
||||
status_filter=status_filter,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
{% extends "dashboard/base.html" %}
|
||||
|
||||
{% block dashboard_header %}
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-900">Admin Panel</h1>
|
||||
<p class="mt-1 text-gray-600">
|
||||
Registry moderation and management
|
||||
<span class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium {% if user.role == 'admin' %}bg-red-100 text-red-800{% else %}bg-purple-100 text-purple-800{% endif %}">
|
||||
{{ user.role|capitalize }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block dashboard_content %}
|
||||
<div class="space-y-6">
|
||||
<!-- Quick Stats -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<a href="{{ url_for('web.admin_pending') }}" class="bg-white rounded-lg border border-gray-200 p-6 hover:border-indigo-500 transition-colors">
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0 bg-yellow-100 rounded-lg p-3">
|
||||
<svg class="h-6 w-6 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4">
|
||||
<p class="text-sm font-medium text-gray-500">Pending Tools</p>
|
||||
<p class="text-2xl font-semibold text-gray-900">{{ pending_count }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<a href="{{ url_for('web.admin_reports') }}" class="bg-white rounded-lg border border-gray-200 p-6 hover:border-indigo-500 transition-colors">
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0 bg-red-100 rounded-lg p-3">
|
||||
<svg class="h-6 w-6 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4">
|
||||
<p class="text-sm font-medium text-gray-500">Open Reports</p>
|
||||
<p class="text-2xl font-semibold text-gray-900">{{ reports_count }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<a href="{{ url_for('web.admin_publishers') }}" class="bg-white rounded-lg border border-gray-200 p-6 hover:border-indigo-500 transition-colors">
|
||||
<div class="flex items-center">
|
||||
<div class="flex-shrink-0 bg-blue-100 rounded-lg p-3">
|
||||
<svg class="h-6 w-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m9 5.197v1"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-4">
|
||||
<p class="text-sm font-medium text-gray-500">Publishers</p>
|
||||
<p class="text-2xl font-semibold text-gray-900">{{ publishers_count }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Quick Actions -->
|
||||
<div class="bg-white rounded-lg border border-gray-200 p-6">
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-4">Quick Actions</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<a href="{{ url_for('web.admin_pending') }}" class="flex items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
|
||||
<svg class="h-5 w-5 text-gray-400 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-700">Review pending tools</span>
|
||||
</a>
|
||||
<a href="{{ url_for('web.admin_reports') }}" class="flex items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
|
||||
<svg class="h-5 w-5 text-gray-400 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"/>
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-700">Handle reports</span>
|
||||
</a>
|
||||
<a href="{{ url_for('web.admin_publishers') }}" class="flex items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
|
||||
<svg class="h-5 w-5 text-gray-400 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/>
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-700">Manage publishers</span>
|
||||
</a>
|
||||
<a href="{{ url_for('web.dashboard') }}" class="flex items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors">
|
||||
<svg class="h-5 w-5 text-gray-400 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 15l-3-3m0 0l3-3m-3 3h8M3 12a9 9 0 1118 0 9 9 0 01-18 0z"/>
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-700">Back to dashboard</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,164 @@
|
||||
{% extends "dashboard/base.html" %}
|
||||
|
||||
{% block dashboard_header %}
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-900">Pending Tools</h1>
|
||||
<p class="mt-1 text-gray-600">Review and approve submitted tools</p>
|
||||
</div>
|
||||
<a href="{{ url_for('web.admin_dashboard') }}" class="text-sm text-indigo-600 hover:text-indigo-700">← Back to Admin</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block dashboard_content %}
|
||||
<div class="bg-white rounded-lg border border-gray-200">
|
||||
{% if tools %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tool</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Publisher</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Category</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Submitted</th>
|
||||
<th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
{% for tool in tools %}
|
||||
<tr id="tool-row-{{ tool.id }}" class="hover:bg-gray-50">
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="flex items-center">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-900">{{ tool.owner }}/{{ tool.name }}</div>
|
||||
<div class="text-sm text-gray-500">v{{ tool.version }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="text-sm text-gray-900">{{ tool.publisher_name }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
|
||||
{{ tool.category or 'Uncategorized' }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{{ tool.published_at[:10] if tool.published_at else 'Unknown' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<button onclick="approveTool({{ tool.id }})" class="text-green-600 hover:text-green-900 mr-3">Approve</button>
|
||||
<button onclick="rejectTool({{ tool.id }})" class="text-red-600 hover:text-red-900">Reject</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
{% if meta.total_pages > 1 %}
|
||||
<div class="bg-gray-50 px-6 py-3 flex items-center justify-between border-t border-gray-200">
|
||||
<div class="text-sm text-gray-700">
|
||||
Page {{ meta.page }} of {{ meta.total_pages }} ({{ meta.total }} total)
|
||||
</div>
|
||||
<div class="flex space-x-2">
|
||||
{% if meta.page > 1 %}
|
||||
<a href="?page={{ meta.page - 1 }}" class="px-3 py-1 border rounded text-sm hover:bg-gray-100">Previous</a>
|
||||
{% endif %}
|
||||
{% if meta.page < meta.total_pages %}
|
||||
<a href="?page={{ meta.page + 1 }}" class="px-3 py-1 border rounded text-sm hover:bg-gray-100">Next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="text-center py-12">
|
||||
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
<h3 class="mt-2 text-sm font-medium text-gray-900">No pending tools</h3>
|
||||
<p class="mt-1 text-sm text-gray-500">All submitted tools have been reviewed.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Reject Modal -->
|
||||
<div id="reject-modal" class="fixed inset-0 bg-gray-600 bg-opacity-50 hidden overflow-y-auto h-full w-full z-50">
|
||||
<div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
|
||||
<div class="mt-3">
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-4">Reject Tool</h3>
|
||||
<textarea id="reject-reason" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500" placeholder="Reason for rejection (required)"></textarea>
|
||||
<div class="mt-4 flex justify-end space-x-3">
|
||||
<button onclick="closeRejectModal()" class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-500">Cancel</button>
|
||||
<button onclick="confirmReject()" class="px-4 py-2 bg-red-600 text-white text-sm font-medium rounded-md hover:bg-red-700">Reject</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentToolId = null;
|
||||
|
||||
async function approveTool(toolId) {
|
||||
if (!confirm('Approve this tool?')) return;
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/tools/${toolId}/approve`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer {{ session.get("auth_token") }}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
if (response.ok) {
|
||||
document.getElementById(`tool-row-${toolId}`).remove();
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
alert(data.error?.message || 'Failed to approve tool');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Network error');
|
||||
}
|
||||
}
|
||||
|
||||
function rejectTool(toolId) {
|
||||
currentToolId = toolId;
|
||||
document.getElementById('reject-modal').classList.remove('hidden');
|
||||
document.getElementById('reject-reason').value = '';
|
||||
}
|
||||
|
||||
function closeRejectModal() {
|
||||
document.getElementById('reject-modal').classList.add('hidden');
|
||||
currentToolId = null;
|
||||
}
|
||||
|
||||
async function confirmReject() {
|
||||
const reason = document.getElementById('reject-reason').value.trim();
|
||||
if (!reason) {
|
||||
alert('Rejection reason is required');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/tools/${currentToolId}/reject`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer {{ session.get("auth_token") }}',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ reason })
|
||||
});
|
||||
if (response.ok) {
|
||||
closeRejectModal();
|
||||
document.getElementById(`tool-row-${currentToolId}`).remove();
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
alert(data.error?.message || 'Failed to reject tool');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Network error');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,237 @@
|
||||
{% extends "dashboard/base.html" %}
|
||||
|
||||
{% block dashboard_header %}
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-900">Publishers</h1>
|
||||
<p class="mt-1 text-gray-600">Manage registry publishers</p>
|
||||
</div>
|
||||
<a href="{{ url_for('web.admin_dashboard') }}" class="text-sm text-indigo-600 hover:text-indigo-700">← Back to Admin</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block dashboard_content %}
|
||||
<div class="bg-white rounded-lg border border-gray-200">
|
||||
{% if publishers %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Publisher</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tools</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Downloads</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
||||
<th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
{% for pub in publishers %}
|
||||
<tr id="pub-row-{{ pub.id }}" class="hover:bg-gray-50">
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="flex items-center">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-900">{{ pub.display_name }}</div>
|
||||
<div class="text-sm text-gray-500">@{{ pub.slug }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full
|
||||
{% if pub.role == 'admin' %}bg-red-100 text-red-800
|
||||
{% elif pub.role == 'moderator' %}bg-purple-100 text-purple-800
|
||||
{% else %}bg-gray-100 text-gray-800{% endif %}">
|
||||
{{ pub.role }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
{{ pub.tool_count }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{{ pub.total_downloads|default(0)|int }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
{% if pub.banned %}
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
|
||||
Banned
|
||||
</span>
|
||||
{% elif pub.verified %}
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
||||
Verified
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-gray-100 text-gray-800">
|
||||
Active
|
||||
</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
{% if user.role == 'admin' and pub.role != 'admin' %}
|
||||
{% if pub.banned %}
|
||||
<button onclick="unbanPublisher({{ pub.id }})" class="text-green-600 hover:text-green-900 mr-2">Unban</button>
|
||||
{% else %}
|
||||
<button onclick="banPublisher({{ pub.id }}, '{{ pub.slug }}')" class="text-red-600 hover:text-red-900 mr-2">Ban</button>
|
||||
{% endif %}
|
||||
<button onclick="changeRole({{ pub.id }}, '{{ pub.slug }}', '{{ pub.role }}')" class="text-indigo-600 hover:text-indigo-900">Role</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
{% if meta.total_pages > 1 %}
|
||||
<div class="bg-gray-50 px-6 py-3 flex items-center justify-between border-t border-gray-200">
|
||||
<div class="text-sm text-gray-700">
|
||||
Page {{ meta.page }} of {{ meta.total_pages }} ({{ meta.total }} total)
|
||||
</div>
|
||||
<div class="flex space-x-2">
|
||||
{% if meta.page > 1 %}
|
||||
<a href="?page={{ meta.page - 1 }}" class="px-3 py-1 border rounded text-sm hover:bg-gray-100">Previous</a>
|
||||
{% endif %}
|
||||
{% if meta.page < meta.total_pages %}
|
||||
<a href="?page={{ meta.page + 1 }}" class="px-3 py-1 border rounded text-sm hover:bg-gray-100">Next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="text-center py-12">
|
||||
<h3 class="text-sm font-medium text-gray-900">No publishers found</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Ban Modal -->
|
||||
<div id="ban-modal" class="fixed inset-0 bg-gray-600 bg-opacity-50 hidden overflow-y-auto h-full w-full z-50">
|
||||
<div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
|
||||
<div class="mt-3">
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-2">Ban Publisher</h3>
|
||||
<p class="text-sm text-gray-500 mb-4" id="ban-publisher-name"></p>
|
||||
<textarea id="ban-reason" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500" placeholder="Reason for ban (required)"></textarea>
|
||||
<div class="mt-4 flex justify-end space-x-3">
|
||||
<button onclick="closeBanModal()" class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-500">Cancel</button>
|
||||
<button onclick="confirmBan()" class="px-4 py-2 bg-red-600 text-white text-sm font-medium rounded-md hover:bg-red-700">Ban</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Role Modal -->
|
||||
<div id="role-modal" class="fixed inset-0 bg-gray-600 bg-opacity-50 hidden overflow-y-auto h-full w-full z-50">
|
||||
<div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
|
||||
<div class="mt-3">
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-2">Change Role</h3>
|
||||
<p class="text-sm text-gray-500 mb-4" id="role-publisher-name"></p>
|
||||
<select id="new-role" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
||||
<option value="user">User</option>
|
||||
<option value="moderator">Moderator</option>
|
||||
<option value="admin">Admin</option>
|
||||
</select>
|
||||
<div class="mt-4 flex justify-end space-x-3">
|
||||
<button onclick="closeRoleModal()" class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-500">Cancel</button>
|
||||
<button onclick="confirmRole()" class="px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">Update</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentPublisherId = null;
|
||||
|
||||
function banPublisher(pubId, slug) {
|
||||
currentPublisherId = pubId;
|
||||
document.getElementById('ban-publisher-name').textContent = `Banning @${slug}`;
|
||||
document.getElementById('ban-modal').classList.remove('hidden');
|
||||
document.getElementById('ban-reason').value = '';
|
||||
}
|
||||
|
||||
function closeBanModal() {
|
||||
document.getElementById('ban-modal').classList.add('hidden');
|
||||
currentPublisherId = null;
|
||||
}
|
||||
|
||||
async function confirmBan() {
|
||||
const reason = document.getElementById('ban-reason').value.trim();
|
||||
if (!reason) {
|
||||
alert('Ban reason is required');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/publishers/${currentPublisherId}/ban`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer {{ session.get("auth_token") }}',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ reason })
|
||||
});
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
alert(data.error?.message || 'Failed to ban publisher');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Network error');
|
||||
}
|
||||
}
|
||||
|
||||
async function unbanPublisher(pubId) {
|
||||
if (!confirm('Unban this publisher?')) return;
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/publishers/${pubId}/unban`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer {{ session.get("auth_token") }}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
alert(data.error?.message || 'Failed to unban publisher');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Network error');
|
||||
}
|
||||
}
|
||||
|
||||
function changeRole(pubId, slug, currentRole) {
|
||||
currentPublisherId = pubId;
|
||||
document.getElementById('role-publisher-name').textContent = `Changing role for @${slug}`;
|
||||
document.getElementById('new-role').value = currentRole;
|
||||
document.getElementById('role-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeRoleModal() {
|
||||
document.getElementById('role-modal').classList.add('hidden');
|
||||
currentPublisherId = null;
|
||||
}
|
||||
|
||||
async function confirmRole() {
|
||||
const role = document.getElementById('new-role').value;
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/publishers/${currentPublisherId}/role`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer {{ session.get("auth_token") }}',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ role })
|
||||
});
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
alert(data.error?.message || 'Failed to change role');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Network error');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,177 @@
|
||||
{% extends "dashboard/base.html" %}
|
||||
|
||||
{% block dashboard_header %}
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-900">Reports</h1>
|
||||
<p class="mt-1 text-gray-600">Review and resolve tool reports</p>
|
||||
</div>
|
||||
<a href="{{ url_for('web.admin_dashboard') }}" class="text-sm text-indigo-600 hover:text-indigo-700">← Back to Admin</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block dashboard_content %}
|
||||
<div class="space-y-6">
|
||||
<!-- Status Filter -->
|
||||
<div class="flex space-x-2">
|
||||
<a href="?status=pending" class="px-4 py-2 rounded-md text-sm font-medium {% if status_filter == 'pending' %}bg-indigo-600 text-white{% else %}bg-gray-100 text-gray-700 hover:bg-gray-200{% endif %}">
|
||||
Pending
|
||||
</a>
|
||||
<a href="?status=resolved" class="px-4 py-2 rounded-md text-sm font-medium {% if status_filter == 'resolved' %}bg-indigo-600 text-white{% else %}bg-gray-100 text-gray-700 hover:bg-gray-200{% endif %}">
|
||||
Resolved
|
||||
</a>
|
||||
<a href="?status=" class="px-4 py-2 rounded-md text-sm font-medium {% if not status_filter %}bg-indigo-600 text-white{% else %}bg-gray-100 text-gray-700 hover:bg-gray-200{% endif %}">
|
||||
All
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="bg-white rounded-lg border border-gray-200">
|
||||
{% if reports %}
|
||||
<div class="overflow-x-auto">
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tool</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Reason</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Reporter</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
||||
<th scope="col" class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
{% for report in reports %}
|
||||
<tr id="report-row-{{ report.id }}" class="hover:bg-gray-50">
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="text-sm font-medium text-gray-900">{{ report.tool }}</div>
|
||||
<div class="text-sm text-gray-500">v{{ report.version }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="text-sm text-gray-900">{{ report.reason }}</div>
|
||||
{% if report.details %}
|
||||
<div class="text-xs text-gray-500 mt-1 max-w-xs truncate">{{ report.details }}</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{{ report.reporter_name or 'Anonymous' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{{ report.created_at[:10] if report.created_at else 'Unknown' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full
|
||||
{% if report.status == 'pending' %}bg-yellow-100 text-yellow-800
|
||||
{% else %}bg-green-100 text-green-800{% endif %}">
|
||||
{{ report.status }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
{% if report.status == 'pending' %}
|
||||
<button onclick="resolveReport({{ report.id }}, {{ report.tool_id }})" class="text-indigo-600 hover:text-indigo-900">Resolve</button>
|
||||
{% else %}
|
||||
<span class="text-gray-400">{{ report.resolution_note or 'Resolved' }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
{% if meta.total_pages > 1 %}
|
||||
<div class="bg-gray-50 px-6 py-3 flex items-center justify-between border-t border-gray-200">
|
||||
<div class="text-sm text-gray-700">
|
||||
Page {{ meta.page }} of {{ meta.total_pages }} ({{ meta.total }} total)
|
||||
</div>
|
||||
<div class="flex space-x-2">
|
||||
{% if meta.page > 1 %}
|
||||
<a href="?page={{ meta.page - 1 }}&status={{ status_filter }}" class="px-3 py-1 border rounded text-sm hover:bg-gray-100">Previous</a>
|
||||
{% endif %}
|
||||
{% if meta.page < meta.total_pages %}
|
||||
<a href="?page={{ meta.page + 1 }}&status={{ status_filter }}" class="px-3 py-1 border rounded text-sm hover:bg-gray-100">Next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="text-center py-12">
|
||||
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
<h3 class="mt-2 text-sm font-medium text-gray-900">No reports</h3>
|
||||
<p class="mt-1 text-sm text-gray-500">No reports matching this filter.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Resolve Modal -->
|
||||
<div id="resolve-modal" class="fixed inset-0 bg-gray-600 bg-opacity-50 hidden overflow-y-auto h-full w-full z-50">
|
||||
<div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white">
|
||||
<div class="mt-3">
|
||||
<h3 class="text-lg font-medium text-gray-900 mb-4">Resolve Report</h3>
|
||||
<div class="mb-4">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">Action</label>
|
||||
<select id="resolve-action" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
|
||||
<option value="dismiss">Dismiss (no action)</option>
|
||||
<option value="warn">Warn publisher</option>
|
||||
<option value="remove_tool">Remove tool</option>
|
||||
<option value="ban_publisher">Ban publisher</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">Note (optional)</label>
|
||||
<textarea id="resolve-note" rows="2" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500" placeholder="Resolution notes"></textarea>
|
||||
</div>
|
||||
<div class="mt-4 flex justify-end space-x-3">
|
||||
<button onclick="closeResolveModal()" class="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-500">Cancel</button>
|
||||
<button onclick="confirmResolve()" class="px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">Resolve</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentReportId = null;
|
||||
let currentToolId = null;
|
||||
|
||||
function resolveReport(reportId, toolId) {
|
||||
currentReportId = reportId;
|
||||
currentToolId = toolId;
|
||||
document.getElementById('resolve-modal').classList.remove('hidden');
|
||||
document.getElementById('resolve-action').value = 'dismiss';
|
||||
document.getElementById('resolve-note').value = '';
|
||||
}
|
||||
|
||||
function closeResolveModal() {
|
||||
document.getElementById('resolve-modal').classList.add('hidden');
|
||||
currentReportId = null;
|
||||
currentToolId = null;
|
||||
}
|
||||
|
||||
async function confirmResolve() {
|
||||
const action = document.getElementById('resolve-action').value;
|
||||
const note = document.getElementById('resolve-note').value.trim();
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/reports/${currentReportId}/resolve`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer {{ session.get("auth_token") }}',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ action, note })
|
||||
});
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
const data = await response.json();
|
||||
alert(data.error?.message || 'Failed to resolve report');
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Network error');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -6,8 +6,19 @@
|
||||
<div class="bg-white border-b border-gray-200">
|
||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
{% block dashboard_header %}
|
||||
<h1 class="text-2xl font-bold text-gray-900">Dashboard</h1>
|
||||
<p class="mt-1 text-gray-600">Welcome back, {{ user.display_name }}</p>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-900">Dashboard</h1>
|
||||
<p class="mt-1 text-gray-600">
|
||||
Welcome back, {{ user.display_name }}
|
||||
{% if user.role in ('moderator', 'admin') %}
|
||||
<span class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium {% if user.role == 'admin' %}bg-red-100 text-red-800{% else %}bg-purple-100 text-purple-800{% endif %}">
|
||||
{{ user.role|capitalize }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -46,6 +57,17 @@
|
||||
</svg>
|
||||
Settings
|
||||
</a>
|
||||
{% if user.role in ('moderator', 'admin') %}
|
||||
<div class="border-t border-gray-200 mt-2 pt-2">
|
||||
<a href="{{ url_for('web.admin_dashboard') }}"
|
||||
class="flex items-center px-4 py-3 text-sm font-medium {{ 'bg-red-50 text-red-700 border-l-4 border-red-600' if active_page and active_page.startswith('admin') else 'text-red-600 hover:bg-red-50' }}">
|
||||
<svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
|
||||
</svg>
|
||||
Admin Panel
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</nav>
|
||||
|
||||
<!-- Quick Stats (mobile hidden) -->
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Access Denied - CmdForge{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="min-h-[60vh] flex items-center justify-center px-4">
|
||||
<div class="text-center max-w-md">
|
||||
<p class="text-6xl font-bold text-red-600">403</p>
|
||||
<h1 class="mt-4 text-3xl font-bold text-gray-900">Access Denied</h1>
|
||||
<p class="mt-4 text-gray-600">
|
||||
Sorry, you don't have permission to access this page. This area is restricted to administrators and moderators.
|
||||
</p>
|
||||
<div class="mt-8 flex flex-col sm:flex-row items-center justify-center gap-4">
|
||||
<a href="{{ url_for('web.dashboard') }}"
|
||||
class="w-full sm:w-auto inline-flex justify-center items-center px-6 py-3 text-base font-medium text-white bg-indigo-600 rounded-md hover:bg-indigo-700">
|
||||
Go to Dashboard
|
||||
</a>
|
||||
<a href="{{ url_for('web.home') }}"
|
||||
class="w-full sm:w-auto inline-flex justify-center items-center px-6 py-3 text-base font-medium text-gray-700 border border-gray-300 rounded-md hover:bg-gray-50">
|
||||
Go Home
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user