From f2f389ae7da1ec359798323d2a5b13bc809284d0 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 5 Apr 2017 04:00:44 +0000 Subject: [PATCH] Show admin panel link with correct permissions --- titanembeds/blueprints/api/api.py | 4 +++- titanembeds/blueprints/embed/embed.py | 2 +- titanembeds/static/js/embed.js | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/titanembeds/blueprints/api/api.py b/titanembeds/blueprints/api/api.py index de3c3b1..b0f7e90 100644 --- a/titanembeds/blueprints/api/api.py +++ b/titanembeds/blueprints/api/api.py @@ -1,7 +1,7 @@ from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers 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.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 sqlalchemy import and_ import random @@ -55,6 +55,7 @@ def update_user_status(guild_id, username, user_key=None): status = { 'authenticated': False, 'avatar': None, + 'manage_embed': False, 'ip_address': ip_address, 'username': username, 'user_key': user_key, @@ -75,6 +76,7 @@ def update_user_status(guild_id, username, user_key=None): status = { 'authenticated': True, 'avatar': session["avatar"], + 'manage_embed': check_user_can_administrate_guild(guild_id), 'username': username, 'guild_id': guild_id, 'user_id': session['user_id'], diff --git a/titanembeds/blueprints/embed/embed.py b/titanembeds/blueprints/embed/embed.py index 8f1a589..f81fac8 100644 --- a/titanembeds/blueprints/embed/embed.py +++ b/titanembeds/blueprints/embed/embed.py @@ -1,6 +1,6 @@ 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.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 embed = Blueprint("embed", __name__) diff --git a/titanembeds/static/js/embed.js b/titanembeds/static/js/embed.js index 753a923..371821d 100644 --- a/titanembeds/static/js/embed.js +++ b/titanembeds/static/js/embed.js @@ -117,12 +117,10 @@ function initialize_embed(guildobj) { } function prepare_guild(guildobj) { - console.log(guildobj); fill_channels(guildobj.channels); fill_discord_members(guildobj.discordmembers); fill_authenticated_users(guildobj.embedmembers.authenticated); fill_unauthenticated_users(guildobj.embedmembers.unauthenticated); - console.log("running fetch routine"); run_fetch_routine(); } @@ -221,10 +219,14 @@ function run_fetch_routine() { jumpscroll = element_in_view($('#discordmessage_'+last_message_id), true); } fet.done(function(data) { - console.log(data); var status = data.status; update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id); last_message_id = fill_discord_messages(data.messages, jumpscroll); + if (status.manage_embed) { + $("#administrate_link").show(); + } else { + $("#administrate_link").hide(); + } var guild = query_guild(); guild.done(function(guildobj) { fill_channels(guildobj.channels);