Use relative URLs in report, to ensure correct links

This commit is contained in:
rubenwardy 2022-01-21 14:17:50 +00:00
parent e0421c1e57
commit a32b63f932
5 changed files with 10 additions and 14 deletions

@ -26,13 +26,12 @@ from wtforms.validators import InputRequired, Optional, Length
from app.models import User, UserRank
from app.tasks.emails import send_user_email
from app.tasks.webhooktasks import post_discord_webhook
from app.utils import isYes, isNo
from app.utils import isYes, isNo, abs_url
bp = Blueprint("report", __name__)
class ReportForm(FlaskForm):
url = URLField(lazy_gettext("URL"), [Optional()])
message = TextAreaField(lazy_gettext("Message"), [InputRequired(), Length(10, 10000)])
submit = SubmitField(lazy_gettext("Report"))
@ -41,26 +40,25 @@ class ReportForm(FlaskForm):
def report():
is_anon = not current_user.is_authenticated or not isNo(request.args.get("anon"))
form = ReportForm(formdata=request.form)
if request.method == "GET":
if "url" in request.args:
form.url.data = request.args["url"]
url = request.args.get("url")
if url:
url = abs_url(url)
form = ReportForm(formdata=request.form)
if form.validate_on_submit():
if current_user.is_authenticated:
user_info = f"{current_user.username}"
else:
user_info = request.headers.get("X-Forwarded-For") or request.remote_addr
url = request.args.get("url") or form.url.data or "?"
text = f"{url}\n\n{form.message.data}"
task = None
for admin in User.query.filter_by(rank=UserRank.ADMIN).all():
task = send_user_email.delay(admin.email, f"User report from {user_info}", text)
post_discord_webhook.delay(None if is_anon else current_user.username, f"**New Report**\n`{url}`\n\n{form.message.data}", True)
post_discord_webhook.delay(None if is_anon else current_user.username, f"**New Report**\n{url}\n\n{form.message.data}", True)
return redirect(url_for("tasks.check", id=task.id, r=url_for("homepage.home")))
return render_template("report/index.html", form=form, url=request.args.get("url"), is_anon=is_anon)
return render_template("report/index.html", form=form, url=url, is_anon=is_anon)

@ -235,7 +235,7 @@
<li class="list-inline-item"><a href="{{ url_for('flatpage', path='help/api') }}">{{ _("API") }}</a></li>
<li class="list-inline-item"><a href="{{ url_for('flatpage', path='privacy_policy') }}">{{ _("Privacy Policy") }}</a></li>
{% if request.endpoint != "flatpage" %}
<li class="list-inline-item"><a href="{{ url_for('report.report', url=url_current(True)) }}">{{ _("Report") }}</a></li>
<li class="list-inline-item"><a href="{{ url_for('report.report', url=url_current()) }}">{{ _("Report") }}</a></li>
{% endif %}
<li class="list-inline-item"><a href="https://monitor.rubenwardy.com/d/3ELzFy3Wz/contentdb">{{ _("Stats / Monitoring") }}</a></li>
<li class="list-inline-item"><a href="{{ url_for('users.list_all') }}">{{ _("User List") }}</a></li>

@ -473,7 +473,7 @@
<p class="mt-3">
{% if package.approved and current_user != package.author %}
<a href="{{ url_for('report.report', url=url_current(True)) }}">
<a href="{{ url_for('report.report', url=url_current()) }}">
<i class="fas fa-flag mr-1"></i>
{{ _("Report") }}
</a>

@ -15,8 +15,6 @@
<p>
URL: <code>{{ url }}</code>
</p>
{% else %}
{{ render_field(form.url, hint=_("URL to the thing you're reporting")) }}
{% endif %}
{{ render_field(form.message, hint=_("What are you reporting? Why are you reporting it?")) }}
{{ render_submit_field(form.submit) }}

@ -23,7 +23,7 @@
</a>
{% endif %}
<a class="btn btn-secondary float-right mr-3" href="{{ url_for('report.report', url=url_current(True)) }}">
<a class="btn btn-secondary float-right mr-3" href="{{ url_for('report.report', url=url_current()) }}">
<i class="fas fa-flag mr-1"></i>
{{ _("Report") }}
</a>