Move devs to the administrators table

This commit is contained in:
Jeremy Zhang 2017-07-22 02:06:45 +00:00
parent a34f43a9d0
commit f4608794a0
8 changed files with 177 additions and 11 deletions

View File

@ -0,0 +1,148 @@
"""Create administrators table
Revision ID: 6fe130518448
Revises: 40cbd3e0f22d
Create Date: 2017-07-22 02:00:35.317471
"""
# revision identifiers, used by Alembic.
revision = '6fe130518448'
down_revision = '40cbd3e0f22d'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('administrators',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.alter_column(u'cosmetics', 'css',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False)
op.alter_column(u'guild_members', 'active',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guild_members', 'banned',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False,
existing_server_default=sa.text(u"'0'"))
op.alter_column(u'guilds', 'bracket_links',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guilds', 'channels',
existing_type=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
type_=sa.Text(length=4294967295),
existing_nullable=False)
op.alter_column(u'guilds', 'chat_links',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guilds', 'emojis',
existing_type=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
type_=sa.Text(length=4294967295),
existing_nullable=False)
op.alter_column(u'guilds', 'roles',
existing_type=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
type_=sa.Text(length=4294967295),
existing_nullable=False)
op.alter_column(u'guilds', 'unauth_users',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guilds', 'visitor_view',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False)
op.alter_column(u'guilds', 'webhooks',
existing_type=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
type_=sa.Text(length=4294967295),
existing_nullable=False)
op.alter_column(u'unauthenticated_users', 'revoked',
existing_type=mysql.TINYINT(display_width=1),
type_=sa.Boolean(),
existing_nullable=False,
existing_server_default=sa.text(u"'0'"))
op.alter_column(u'user_css', 'css',
existing_type=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
type_=sa.Text(length=4294967295),
existing_nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column(u'user_css', 'css',
existing_type=sa.Text(length=4294967295),
type_=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
existing_nullable=True)
op.alter_column(u'unauthenticated_users', 'revoked',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False,
existing_server_default=sa.text(u"'0'"))
op.alter_column(u'guilds', 'webhooks',
existing_type=sa.Text(length=4294967295),
type_=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
existing_nullable=False)
op.alter_column(u'guilds', 'visitor_view',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False)
op.alter_column(u'guilds', 'unauth_users',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guilds', 'roles',
existing_type=sa.Text(length=4294967295),
type_=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
existing_nullable=False)
op.alter_column(u'guilds', 'emojis',
existing_type=sa.Text(length=4294967295),
type_=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
existing_nullable=False)
op.alter_column(u'guilds', 'chat_links',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guilds', 'channels',
existing_type=sa.Text(length=4294967295),
type_=mysql.LONGTEXT(collation=u'utf8mb4_unicode_ci'),
existing_nullable=False)
op.alter_column(u'guilds', 'bracket_links',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'guild_members', 'banned',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False,
existing_server_default=sa.text(u"'0'"))
op.alter_column(u'guild_members', 'active',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False,
existing_server_default=sa.text(u"'1'"))
op.alter_column(u'cosmetics', 'css',
existing_type=sa.Boolean(),
type_=mysql.TINYINT(display_width=1),
existing_nullable=False)
op.drop_table('administrators')
# ### end Alembic commands ###

View File

@ -1,2 +0,0 @@
global devs
devs = [ "138881969185357825" , "197322731115642880", "193908323911860224" ]

View File

@ -8,7 +8,7 @@ import blueprints.user
import blueprints.admin import blueprints.admin
import blueprints.embed import blueprints.embed
import os import os
from titanembeds import devs from titanembeds.database import get_administrators_list
os.chdir(config['app-location']) os.chdir(config['app-location'])
@ -39,10 +39,9 @@ def about():
@app.before_request @app.before_request
def before_request(): def before_request():
db.create_all()
discord_api.init_discordrest() discord_api.init_discordrest()
@app.context_processor @app.context_processor
def context_processor(): def context_processor():
bot_status = bot_alive() bot_status = bot_alive()
return {"bot_status": bot_status, "devs": devs} return {"bot_status": bot_status, "devs": get_administrators_list()}

View File

@ -1,6 +1,6 @@
from flask import Blueprint, url_for, redirect, session, render_template from flask import Blueprint, url_for, redirect, session, render_template
from functools import wraps from functools import wraps
from titanembeds import devs from titanembeds.database import get_administrators_list
admin = Blueprint("admin", __name__) admin = Blueprint("admin", __name__)
@ -10,7 +10,7 @@ def is_admin(f):
def decorated_function(*args, **kwargs): def decorated_function(*args, **kwargs):
if 'user_id' not in session: if 'user_id' not in session:
return redirect(url_for("index")) return redirect(url_for("index"))
if session['user_id'] not in devs: if session['user_id'] not in get_administrators_list():
return redirect(url_for("index")) return redirect(url_for("index"))
return f(*args, **kwargs) return f(*args, **kwargs)
return decorated_function return decorated_function

View File

@ -2,7 +2,7 @@ from titanembeds.database import db, Guilds, UnauthenticatedUsers, Unauthenticat
from titanembeds.decorators import valid_session_required, discord_users_only from titanembeds.decorators import valid_session_required, discord_users_only
from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key
from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
from titanembeds import devs from titanembeds.database import get_administrators_list
from flask import Blueprint, abort, jsonify, session, request, url_for from flask import Blueprint, abort, jsonify, session, request, url_for
from sqlalchemy import and_ from sqlalchemy import and_
import random import random
@ -381,7 +381,7 @@ def post():
userid = session["user_id"] userid = session["user_id"]
content = format_everyone_mention(chan, content) content = format_everyone_mention(chan, content)
webhook = get_channel_webhook_url(guild_id, channel_id) webhook = get_channel_webhook_url(guild_id, channel_id)
if userid in devs: if userid in get_administrators_list():
oldcontent = content oldcontent = content
content = "(Titan Dev) " + oldcontent content = "(Titan Dev) " + oldcontent
if webhook: if webhook:

View File

@ -11,3 +11,4 @@ from keyvalue_properties import KeyValueProperties, set_keyvalproperty, get_keyv
from messages import Messages, get_channel_messages from messages import Messages, get_channel_messages
from cosmetics import Cosmetics from cosmetics import Cosmetics
from user_css import UserCSS from user_css import UserCSS
from administrators import Administrators, get_administrators_list

View File

@ -0,0 +1,13 @@
from titanembeds.database import db
class Administrators(db.Model):
__tablename__ = "administrators"
id = db.Column(db.Integer, primary_key=True) # Auto increment id
user_id = db.Column(db.String(255), nullable=False) # Discord user id of user of an administrator
def get_administrators_list():
q = db.session.query(Administrators).all()
their_ids = []
for admin in q:
their_ids.append(admin.user_id)
return their_ids

View File

@ -5,3 +5,10 @@ class Cosmetics(db.Model):
id = db.Column(db.Integer, primary_key=True) # Auto increment id id = db.Column(db.Integer, primary_key=True) # Auto increment id
user_id = db.Column(db.String(255), nullable=False) # Discord user id of user of cosmetics user_id = db.Column(db.String(255), nullable=False) # Discord user id of user of cosmetics
css = db.Column(db.Boolean(), nullable=False) # If they can create/edit custom CSS css = db.Column(db.Boolean(), nullable=False) # If they can create/edit custom CSS
def __init__(self, user_id, **kwargs):
self.name = name
self.user_id = user_id
if "css" in kwargs:
self.css = kwargs["css"]