I've found some bugs in the admin guilds thing system, this push fixed it, these bugs are tested, investigated, solved and tested again

This commit is contained in:
JustMaffie 2017-07-27 23:15:24 +02:00
parent 4a9c38aa47
commit 33f881bff3
2 changed files with 47 additions and 5 deletions

View File

@ -1,7 +1,8 @@
from flask import Blueprint, url_for, redirect, session, render_template, abort, request from flask import Blueprint, url_for, redirect, session, render_template, abort, request
from functools import wraps from functools import wraps
from titanembeds.database import db, get_administrators_list, Cosmetics, Guilds from titanembeds.database import db, get_administrators_list, Cosmetics, Guilds, UnauthenticatedUsers, UnauthenticatedBans
from titanembeds.oauth import generate_guild_icon_url from titanembeds.oauth import generate_guild_icon_url
import datetime
admin = Blueprint("admin", __name__) admin = Blueprint("admin", __name__)
@ -74,11 +75,53 @@ def cosmetics_patch():
entry.css = css entry.css = css
db.session.commit() db.session.commit()
return ('', 204) return ('', 204)
def prepare_guild_members_list(members, bans):
all_users = []
ip_pool = []
members = sorted(members, key=lambda k: datetime.datetime.strptime(str(k.last_timestamp), "%Y-%m-%d %H:%M:%S"), reverse=True)
for member in members:
user = {
"id": member.id,
"username": member.username,
"discrim": member.discriminator,
"ip": member.ip_address,
"last_visit": member.last_timestamp,
"kicked": member.revoked,
"banned": False,
"banned_timestamp": None,
"banned_by": None,
"banned_reason": None,
"ban_lifted_by": None,
"aliases": [],
}
for banned in bans:
if banned.ip_address == member.ip_address:
if banned.lifter_id is None:
user['banned'] = True
user["banned_timestamp"] = banned.timestamp
user['banned_by'] = banned.placer_id
user['banned_reason'] = banned.reason
user['ban_lifted_by'] = banned.lifter_id
continue
if user["ip"] not in ip_pool:
all_users.append(user)
ip_pool.append(user["ip"])
else:
for usr in all_users:
if user["ip"] == usr["ip"]:
alias = user["username"]+"#"+str(user["discrim"])
if len(usr["aliases"]) < 5 and alias not in usr["aliases"]:
usr["aliases"].append(alias)
continue
return all_users
@admin.route("/administrate_guild/<guild_id>", methods=["GET"]) @admin.route("/administrate_guild/<guild_id>", methods=["GET"])
@is_admin @is_admin
def administrate_guild(guild_id): def administrate_guild(guild_id):
db_guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first() db_guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
if not db_guild:
abort(500)
return
session["redirect"] = None session["redirect"] = None
permissions=[] permissions=[]
permissions.append("Manage Embed Settings") permissions.append("Manage Embed Settings")
@ -109,7 +152,6 @@ def update_administrate_guild(guild_id):
db_guild.chat_links = request.form.get("chat_links", db_guild.chat_links) 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.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) db_guild.mentions_limit = request.form.get("mentions_limit", db_guild.mentions_limit)
discordio = request.form.get("discordio", db_guild.discordio) discordio = request.form.get("discordio", db_guild.discordio)
if discordio and discordio.strip() == "": if discordio and discordio.strip() == "":
discordio = None discordio = None
@ -125,7 +167,7 @@ def update_administrate_guild(guild_id):
discordio=db_guild.discordio, discordio=db_guild.discordio,
) )
@user.route("/guilds") @admin.route("/guilds")
@is_admin @is_admin
def guilds(): def guilds():
guilds = db.session.query(Guilds).all() guilds = db.session.query(Guilds).all()

View File

@ -11,7 +11,7 @@
<div class="row valign-wrapper"> <div class="row valign-wrapper">
<div class="col s3"> <div class="col s3">
{% if server.icon %} {% if server.icon %}
<img src="{{ icon_generate(server.id, server.icon) }}" alt="" class="circle responsive-img"> <img src="{{ icon_generate(server.guild_id, server.icon) }}" alt="" class="circle responsive-img">
{% else %} {% else %}
<span class="black-text">No icon :(</span> <span class="black-text">No icon :(</span>
{% endif %} {% endif %}
@ -20,7 +20,7 @@
<span class="black-text"> <span class="black-text">
<p class="flow-text truncate">{{ server.name }}</p> <p class="flow-text truncate">{{ server.name }}</p>
<br> <br>
<a class="waves-effect waves-light btn" href="{{url_for('admin.administrate_guild', guild_id=server['id'])}}">Modify</a> <a class="waves-effect waves-light btn" href="{{url_for('admin.administrate_guild', guild_id=server['guild_id'])}}">Modify</a>
</span> </span>
</div> </div>
</div> </div>