Show admin panel link with correct permissions

This commit is contained in:
Jeremy Zhang 2017-04-05 04:00:44 +00:00
parent 6791f2b29b
commit f2f389ae7d
3 changed files with 9 additions and 5 deletions

View File

@ -1,7 +1,7 @@
from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers
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_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key, cache, make_guildchannels_cache_key from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key, cache, make_guildchannels_cache_key
from titanembeds.oauth import user_has_permission, generate_avatar_url from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
from flask import Blueprint, abort, jsonify, session, request from flask import Blueprint, abort, jsonify, session, request
from sqlalchemy import and_ from sqlalchemy import and_
import random import random
@ -55,6 +55,7 @@ def update_user_status(guild_id, username, user_key=None):
status = { status = {
'authenticated': False, 'authenticated': False,
'avatar': None, 'avatar': None,
'manage_embed': False,
'ip_address': ip_address, 'ip_address': ip_address,
'username': username, 'username': username,
'user_key': user_key, 'user_key': user_key,
@ -75,6 +76,7 @@ def update_user_status(guild_id, username, user_key=None):
status = { status = {
'authenticated': True, 'authenticated': True,
'avatar': session["avatar"], 'avatar': session["avatar"],
'manage_embed': check_user_can_administrate_guild(guild_id),
'username': username, 'username': username,
'guild_id': guild_id, 'guild_id': guild_id,
'user_id': session['user_id'], 'user_id': session['user_id'],

View File

@ -1,6 +1,6 @@
from flask import Blueprint, render_template, abort, redirect, url_for, session from flask import Blueprint, render_template, abort, redirect, url_for, session
from titanembeds.utils import check_guild_existance, discord_api, guild_query_unauth_users_bool from titanembeds.utils import check_guild_existance, discord_api, guild_query_unauth_users_bool
from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url, check_user_can_administrate_guild from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url
import random import random
embed = Blueprint("embed", __name__) embed = Blueprint("embed", __name__)

View File

@ -117,12 +117,10 @@ function initialize_embed(guildobj) {
} }
function prepare_guild(guildobj) { function prepare_guild(guildobj) {
console.log(guildobj);
fill_channels(guildobj.channels); fill_channels(guildobj.channels);
fill_discord_members(guildobj.discordmembers); fill_discord_members(guildobj.discordmembers);
fill_authenticated_users(guildobj.embedmembers.authenticated); fill_authenticated_users(guildobj.embedmembers.authenticated);
fill_unauthenticated_users(guildobj.embedmembers.unauthenticated); fill_unauthenticated_users(guildobj.embedmembers.unauthenticated);
console.log("running fetch routine");
run_fetch_routine(); run_fetch_routine();
} }
@ -221,10 +219,14 @@ function run_fetch_routine() {
jumpscroll = element_in_view($('#discordmessage_'+last_message_id), true); jumpscroll = element_in_view($('#discordmessage_'+last_message_id), true);
} }
fet.done(function(data) { fet.done(function(data) {
console.log(data);
var status = data.status; var status = data.status;
update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id); update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id);
last_message_id = fill_discord_messages(data.messages, jumpscroll); last_message_id = fill_discord_messages(data.messages, jumpscroll);
if (status.manage_embed) {
$("#administrate_link").show();
} else {
$("#administrate_link").hide();
}
var guild = query_guild(); var guild = query_guild();
guild.done(function(guildobj) { guild.done(function(guildobj) {
fill_channels(guildobj.channels); fill_channels(guildobj.channels);