mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-23 21:47:04 +01:00
Admin guilds manage thing
This commit is contained in:
parent
4d3140b531
commit
4a9c38aa47
@ -1,6 +1,7 @@
|
||||
from flask import Blueprint, url_for, redirect, session, render_template, abort, request
|
||||
from functools import wraps
|
||||
from titanembeds.database import db, get_administrators_list, Cosmetics
|
||||
from titanembeds.database import db, get_administrators_list, Cosmetics, Guilds
|
||||
from titanembeds.oauth import generate_guild_icon_url
|
||||
|
||||
admin = Blueprint("admin", __name__)
|
||||
|
||||
@ -73,4 +74,59 @@ def cosmetics_patch():
|
||||
entry.css = css
|
||||
db.session.commit()
|
||||
return ('', 204)
|
||||
|
||||
|
||||
@admin.route("/administrate_guild/<guild_id>", methods=["GET"])
|
||||
@is_admin
|
||||
def administrate_guild(guild_id):
|
||||
db_guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
||||
session["redirect"] = None
|
||||
permissions=[]
|
||||
permissions.append("Manage Embed Settings")
|
||||
permissions.append("Ban Members")
|
||||
permissions.append("Kick Members")
|
||||
all_members = db.session.query(UnauthenticatedUsers).filter(UnauthenticatedUsers.guild_id == guild_id).order_by(UnauthenticatedUsers.last_timestamp).all()
|
||||
all_bans = db.session.query(UnauthenticatedBans).filter(UnauthenticatedBans.guild_id == guild_id).all()
|
||||
users = prepare_guild_members_list(all_members, all_bans)
|
||||
dbguild_dict = {
|
||||
"id": db_guild.guild_id,
|
||||
"name": db_guild.name,
|
||||
"unauth_users": db_guild.unauth_users,
|
||||
"visitor_view": db_guild.visitor_view,
|
||||
"chat_links": db_guild.chat_links,
|
||||
"bracket_links": db_guild.bracket_links,
|
||||
"mentions_limit": db_guild.mentions_limit,
|
||||
"icon": db_guild.icon,
|
||||
"discordio": db_guild.discordio if db_guild.discordio != None else ""
|
||||
}
|
||||
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions)
|
||||
|
||||
@admin.route("/administrate_guild/<guild_id>", methods=["POST"])
|
||||
@is_admin
|
||||
def update_administrate_guild(guild_id):
|
||||
db_guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
||||
db_guild.unauth_users = request.form.get("unauth_users", db_guild.unauth_users) in ["true", True]
|
||||
db_guild.visitor_view = request.form.get("visitor_view", db_guild.visitor_view) in ["true", True]
|
||||
db_guild.chat_links = request.form.get("chat_links", db_guild.chat_links) in ["true", True]
|
||||
db_guild.bracket_links = request.form.get("bracket_links", db_guild.bracket_links) in ["true", True]
|
||||
db_guild.mentions_limit = request.form.get("mentions_limit", db_guild.mentions_limit)
|
||||
|
||||
discordio = request.form.get("discordio", db_guild.discordio)
|
||||
if discordio and discordio.strip() == "":
|
||||
discordio = None
|
||||
db_guild.discordio = discordio
|
||||
db.session.commit()
|
||||
return jsonify(
|
||||
id=db_guild.id,
|
||||
guild_id=db_guild.guild_id,
|
||||
unauth_users=db_guild.unauth_users,
|
||||
chat_links=db_guild.chat_links,
|
||||
bracket_links=db_guild.bracket_links,
|
||||
mentions_limit=db_guild.mentions_limit,
|
||||
discordio=db_guild.discordio,
|
||||
)
|
||||
|
||||
@user.route("/guilds")
|
||||
@is_admin
|
||||
def guilds():
|
||||
guilds = db.session.query(Guilds).all()
|
||||
return render_template("admin_guilds.html.j2", servers=guilds, icon_generate=generate_guild_icon_url)
|
||||
|
32
webapp/titanembeds/templates/admin_guilds.html.j2
Normal file
32
webapp/titanembeds/templates/admin_guilds.html.j2
Normal file
@ -0,0 +1,32 @@
|
||||
{% extends 'site_layout.html.j2' %}
|
||||
{% set title="Admin" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Manage Guilds (Admin)</h1>
|
||||
<p class="flow-text">Select a server to configure Titan Embeds.</p>
|
||||
<div class="row">
|
||||
{% for server in servers %}
|
||||
<div class="col l4 m6 s12">
|
||||
<div class="card-panel indigo lighten-5 z-depth-3 hoverable">
|
||||
<div class="row valign-wrapper">
|
||||
<div class="col s3">
|
||||
{% if server.icon %}
|
||||
<img src="{{ icon_generate(server.id, server.icon) }}" alt="" class="circle responsive-img">
|
||||
{% else %}
|
||||
<span class="black-text">No icon :(</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col s7">
|
||||
<span class="black-text">
|
||||
<p class="flow-text truncate">{{ server.name }}</p>
|
||||
<br>
|
||||
<a class="waves-effect waves-light btn" href="{{url_for('admin.administrate_guild', guild_id=server['id'])}}">Modify</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -13,5 +13,12 @@
|
||||
<a class="waves-effect waves-light btn" href="{{ url_for('admin.cosmetics') }}">Manage</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col s12">
|
||||
<div class="card-panel indigo lighten-5 z-depth-3 hoverable black-text">
|
||||
<h4>Guilds</h4>
|
||||
<p class="flow-text">Manage any guild in Titan, this will give you the normal dashboard.</p>
|
||||
<a class="waves-effect waves-light btn" href="{{ url_for('admin.guilds') }}">Manage</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user