diff --git a/app/__init__.py b/app/__init__.py index e406f509..c1aa6a83 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -18,9 +18,10 @@ import datetime import os import redis -from flask import redirect, url_for, render_template, flash, request, Flask, send_from_directory, make_response +from flask import redirect, url_for, render_template, flash, request, Flask, send_from_directory, make_response, render_template_string from flask_babel import Babel, gettext from flask_flatpages import FlatPages +from flask_flatpages.utils import pygmented_markdown from flask_github import GitHub from flask_gravatar import Gravatar from flask_login import logout_user, current_user, LoginManager @@ -30,10 +31,20 @@ from flask_wtf.csrf import CSRFProtect from app.markdown import init_markdown, MARKDOWN_EXTENSIONS, MARKDOWN_EXTENSION_CONFIG app = Flask(__name__, static_folder="public/static") + + +def my_flatpage_renderer(text): + # Render with jinja first + prerendered_body = render_template_string(text) + return pygmented_markdown(prerendered_body) + + app.config["FLATPAGES_ROOT"] = "flatpages" app.config["FLATPAGES_EXTENSION"] = ".md" app.config["FLATPAGES_MARKDOWN_EXTENSIONS"] = MARKDOWN_EXTENSIONS app.config["FLATPAGES_EXTENSION_CONFIG"] = MARKDOWN_EXTENSION_CONFIG +app.config["FLATPAGES_HTML_RENDERER"] = my_flatpage_renderer + app.config["BABEL_TRANSLATION_DIRECTORIES"] = "../translations" app.config["LANGUAGES"] = { "en": "English", @@ -55,6 +66,9 @@ app.config["LANGUAGES"] = { app.config.from_pyfile(os.environ["FLASK_CONFIG"]) +if not app.config["ADMIN_CONTACT_URL"]: + raise Exception("Missing config property: ADMIN_CONTACT_URL") + redis_client = redis.Redis.from_url(app.config["REDIS_URL"]) github = GitHub(app) diff --git a/app/flatpages/about.md b/app/flatpages/about.md index 7d7d7edf..4fe013f4 100644 --- a/app/flatpages/about.md +++ b/app/flatpages/about.md @@ -12,8 +12,10 @@ ContentDB is open source software, licensed under AGPLv3.0. Source code Issue tracker -Contact admin -Stats / monitoring +Contact admin +{% if monitoring_url -%} +Stats / monitoring +{%- endif %} ## Why was ContentDB created? diff --git a/app/flatpages/help/contact_us.md b/app/flatpages/help/contact_us.md index c41970ec..cfc7d654 100644 --- a/app/flatpages/help/contact_us.md +++ b/app/flatpages/help/contact_us.md @@ -11,4 +11,4 @@ We take copyright violation and other offenses very seriously. ## Other -Contact the admin +Contact the admin diff --git a/app/flatpages/help/copyright.md b/app/flatpages/help/copyright.md index b52b108d..654813f8 100644 --- a/app/flatpages/help/copyright.md +++ b/app/flatpages/help/copyright.md @@ -135,7 +135,8 @@ ContentDB editors will check packages to make sure the package page's license ma inside the package download, but do not investigate each piece of media or line of code. If a copyright violation is reported to us, we will unlist the package and contact the author/maintainers. -Once the problem has been fixed, the package can be restored. +Once the problem has been fixed, the package can be restored. Repeated copyright infringement may lead to +permanent bans. ## Where can I get help? diff --git a/app/flatpages/help/editors.md b/app/flatpages/help/editors.md index 3f9ef3fe..b0c3f533 100644 --- a/app/flatpages/help/editors.md +++ b/app/flatpages/help/editors.md @@ -54,5 +54,4 @@ A simplified process for reviewing a package is as follows: usually incorrect. 4. check source, etc links to make sure they work and are correct. 5. verify that the package has license file that matches what is on the contentdb fields -6. verify that all assets and code are licensed correctly -7. if the above steps pass, approve the package, else request changes needed from the author +6. if the above steps pass, approve the package, else request changes needed from the author diff --git a/app/flatpages/help/faq.md b/app/flatpages/help/faq.md index 949e9af9..61b5388d 100644 --- a/app/flatpages/help/faq.md +++ b/app/flatpages/help/faq.md @@ -34,7 +34,7 @@ then you can just set a new email in [Settings > Email and Notifications](/user/settings/email/). If you have previously unsubscribed this email, then ContentDB is completely prevented from sending emails to that -address. You'll need to use a different email address, or [contact rubenwardy](https://rubenwardy.com/contact/) to +address. You'll need to use a different email address, or [contact the admin]({{ admin_contact_url }}) to remove your email from the blacklist. diff --git a/app/flatpages/help/metrics.md b/app/flatpages/help/metrics.md index c40aab98..36ab50a7 100644 --- a/app/flatpages/help/metrics.md +++ b/app/flatpages/help/metrics.md @@ -9,11 +9,13 @@ and modern alerting approach". Prometheus Metrics can be accessed at [/metrics](/metrics), or you can view them on the Grafana instance below. +{% if monitoring_url %}

- + View ContentDB on Grafana

+{% endif %} ## Metrics diff --git a/app/template_filters.py b/app/template_filters.py index e430787f..77c11a51 100644 --- a/app/template_filters.py +++ b/app/template_filters.py @@ -34,7 +34,9 @@ def inject_misc(): hide_nonfree = False if has_request_context(): hide_nonfree = request.cookies.get("hide_nonfree") == "1" - return dict(debug=app.debug, hide_nonfree=hide_nonfree, locale=get_locale()) + return dict(debug=app.debug, hide_nonfree=hide_nonfree, locale=get_locale(), + admin_contact_url=app.config["ADMIN_CONTACT_URL"], + monitoring_url=app.config.get("MONITORING_URL")) @app.context_processor diff --git a/app/templates/emails/unable_to_find_account.html b/app/templates/emails/unable_to_find_account.html index 22971e6a..aa087edf 100644 --- a/app/templates/emails/unable_to_find_account.html +++ b/app/templates/emails/unable_to_find_account.html @@ -6,8 +6,8 @@

{{ _("You can use GitHub to log in if it is associated with your account.") }} - {{ _("Otherwise, you may need to contact rubenwardy for help.") }} + {{ _("Otherwise, you may need to contact the admin for help.") }}

{{ _("If you weren't expecting to receive this email, then you can safely ignore it.") }} -

\ No newline at end of file +

diff --git a/app/templates/report/index.html b/app/templates/report/index.html index 5a8b5252..ee1d0d40 100644 --- a/app/templates/report/index.html +++ b/app/templates/report/index.html @@ -13,11 +13,11 @@

{{ _("Due to spam, we no longer accept reports from anonymous users on this form.") }} - {{ _("Please sign in or contact the admin in another way") }} + {{ _("Please sign in or contact the admin using the link below.") }}

Login - Contact the admin + Contact the admin

{% else %} diff --git a/config.example.cfg b/config.example.cfg index 2f5de9f8..d789bacc 100644 --- a/config.example.cfg +++ b/config.example.cfg @@ -35,3 +35,6 @@ TEMPLATES_AUTO_RELOAD = False LOG_SQL = False BLOCKED_DOMAINS = [] + +ADMIN_CONTACT_URL = "" +MONITORING_URL = None diff --git a/utils/ci/config.cfg b/utils/ci/config.cfg index f83ac627..74de8089 100644 --- a/utils/ci/config.cfg +++ b/utils/ci/config.cfg @@ -29,3 +29,5 @@ TEMPLATES_AUTO_RELOAD = True LANGUAGES = { 'en': 'English', } + +ADMIN_CONTACT_URL = "https://example.org"