From 935337cbd078d1ef045a0cb54f59424c32bb42d9 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:23:26 +1200 Subject: [PATCH] tidy ups to #289 --- app/__init__.py | 6 ++---- app/dev/routes.py | 18 +++++++++++++----- app/templates/admin/_nav.html | 2 +- app/templates/base.html | 2 +- app/templates/dev/tools.html | 2 ++ app/utils.py | 6 ------ pyfedi.py | 2 +- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index a97b81e3..e5643076 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -106,10 +106,8 @@ def create_app(config_class=Config): from app.tag import bp as tag_bp app.register_blueprint(tag_bp) - # make the dev tools page available if in dev mode - if app.config['MODE'] == 'development': - from app.dev import bp as dev_bp - app.register_blueprint(dev_bp) + from app.dev import bp as dev_bp + app.register_blueprint(dev_bp) # send error reports via email if app.config['MAIL_SERVER'] and app.config['MAIL_ERRORS']: diff --git a/app/dev/routes.py b/app/dev/routes.py index 812c08a8..5043c73f 100644 --- a/app/dev/routes.py +++ b/app/dev/routes.py @@ -1,5 +1,5 @@ import random -from flask import request, flash, url_for, current_app, redirect, g +from flask import request, flash, url_for, current_app, redirect, g, abort from flask_login import login_required, current_user from flask_babel import _ @@ -8,6 +8,7 @@ from app.activitypub.signature import RsaKeys from app.admin.routes import unsubscribe_everyone_then_delete from app.dev import bp from app.dev.forms import AddTestCommunities, AddTestTopics, DeleteTestCommunities, DeleteTestTopics +from app.inoculation import inoculation from app.models import Site, User, Community, CommunityMember, Language, Topic, utcnow from app.utils import render_template, community_membership, moderating_communities, joined_communities, menu_topics, markdown_to_html @@ -16,6 +17,8 @@ from app.utils import render_template, community_membership, moderating_communit @bp.route('/dev/tools', methods=['GET', 'POST']) @login_required def tools(): + if not current_app.debug: + abort(404) communities_form = AddTestCommunities() topics_form = AddTestTopics() delete_communities_form = DeleteTestCommunities() @@ -177,7 +180,12 @@ def tools(): else: return render_template('dev/tools.html', - communities_form=communities_form, - topics_form=topics_form, - delete_communities_form=delete_communities_form, - delete_topics_form=delete_topics_form) + communities_form=communities_form, + topics_form=topics_form, + delete_communities_form=delete_communities_form, + delete_topics_form=delete_topics_form, + moderating_communities=moderating_communities(current_user.get_id()), + joined_communities=joined_communities(current_user.get_id()), + menu_topics=menu_topics(), site=g.site, + inoculation=inoculation[random.randint(0, len(inoculation) - 1)] if g.site.show_inoculation_block else None + ) diff --git a/app/templates/admin/_nav.html b/app/templates/admin/_nav.html index 8d29147f..e04d0b84 100644 --- a/app/templates/admin/_nav.html +++ b/app/templates/admin/_nav.html @@ -15,7 +15,7 @@ {{ _('Newsletter') }} | {{ _('Permissions') }} | {{ _('Activities') }} - {% if current_mode == 'development' %} + {% if debug_mode %} | {{ _('Dev Tools') }} {% endif%} diff --git a/app/templates/base.html b/app/templates/base.html index bff86699..e4150943 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -211,7 +211,7 @@
  • {{ _('Newsletter') }}
  • {{ _('Activities') }}
  • {{ _('Permissions') }}
  • - {% if current_mode == 'development' %} + {% if debug_mode %}
  • {{ _('Dev Tools') }}
  • {% endif %} diff --git a/app/templates/dev/tools.html b/app/templates/dev/tools.html index ade6791e..a49332cd 100644 --- a/app/templates/dev/tools.html +++ b/app/templates/dev/tools.html @@ -7,6 +7,8 @@ {% set active_child = 'dev_tools' %} {% block app_content %} +

    {{ _('Dev Tools') }}

    +

    {{ _('Use these buttons to quickly generate some testing topics and communities to use during development.') }}

    diff --git a/app/utils.py b/app/utils.py index 4d828951..8f9e15dd 100644 --- a/app/utils.py +++ b/app/utils.py @@ -34,7 +34,6 @@ import re from moviepy.editor import VideoFileClip from PIL import Image, ImageOps -from app.email import send_welcome_email from app.models import Settings, Domain, Instance, BannedInstances, User, Community, DomainBlock, ActivityPubLog, IpBan, \ Site, Post, PostReply, utcnow, Filter, CommunityMember, InstanceBlock, CommunityBan, Topic, UserBlock, Language, \ File, ModLog @@ -42,11 +41,6 @@ from app.models import Settings, Domain, Instance, BannedInstances, User, Commun # Flask's render_template function, with support for themes added def render_template(template_name: str, **context) -> Response: - # add current_mode to context - # if mode is 'development' this will enable the dev tools link in the admin drop down - current_mode = current_app.config['MODE'] - context['current_mode'] = current_mode - theme = current_theme() if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): content = flask.render_template(f'themes/{theme}/{template_name}', **context) diff --git a/pyfedi.py b/pyfedi.py index b446271a..9a5fefc2 100644 --- a/pyfedi.py +++ b/pyfedi.py @@ -23,7 +23,7 @@ cli.register(app) def app_context_processor(): def getmtime(filename): return os.path.getmtime('app/static/' + filename) - return dict(getmtime=getmtime, instance_domain=current_app.config['SERVER_NAME'], + return dict(getmtime=getmtime, instance_domain=current_app.config['SERVER_NAME'], debug_mode=current_app.debug, POST_TYPE_LINK=POST_TYPE_LINK, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_ARTICLE=POST_TYPE_ARTICLE, POST_TYPE_VIDEO=POST_TYPE_VIDEO, POST_TYPE_POLL=POST_TYPE_POLL, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,