mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +01:00
parent
3279e00aa4
commit
d4b1344f6a
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from flask import render_template, request, redirect, flash, url_for, abort
|
import typing
|
||||||
|
from flask import render_template, request, redirect, flash, url_for, abort, jsonify
|
||||||
from flask_babel import gettext, lazy_gettext
|
from flask_babel import gettext, lazy_gettext
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
@ -27,7 +28,7 @@ from app.models import db, PackageReview, Thread, ThreadReply, NotificationType,
|
|||||||
Permission, AuditSeverity, PackageState
|
Permission, AuditSeverity, PackageState
|
||||||
from app.tasks.webhooktasks import post_discord_webhook
|
from app.tasks.webhooktasks import post_discord_webhook
|
||||||
from app.utils import is_package_page, add_notification, get_int_or_abort, is_yes, is_safe_url, rank_required, \
|
from app.utils import is_package_page, add_notification, get_int_or_abort, is_yes, is_safe_url, rank_required, \
|
||||||
add_audit_log, has_blocked_domains
|
add_audit_log, has_blocked_domains, should_return_json
|
||||||
from . import bp
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
@ -178,18 +179,16 @@ def delete_review(package, reviewer):
|
|||||||
return redirect(thread.get_view_url())
|
return redirect(thread.get_view_url())
|
||||||
|
|
||||||
|
|
||||||
def handle_review_vote(package: Package, review_id: int):
|
def handle_review_vote(package: Package, review_id: int) -> typing.Optional[str]:
|
||||||
if current_user in package.maintainers:
|
if current_user in package.maintainers:
|
||||||
flash(gettext("You can't vote on the reviews on your own package!"), "danger")
|
return gettext("You can't vote on the reviews on your own package!")
|
||||||
return
|
|
||||||
|
|
||||||
review: PackageReview = PackageReview.query.get(review_id)
|
review: PackageReview = PackageReview.query.get(review_id)
|
||||||
if review is None or review.package != package:
|
if review is None or review.package != package:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
if review.author == current_user:
|
if review.author == current_user:
|
||||||
flash(gettext("You can't vote on your own reviews!"), "danger")
|
return gettext("You can't vote on your own reviews!")
|
||||||
return
|
|
||||||
|
|
||||||
is_positive = is_yes(request.form["is_positive"])
|
is_positive = is_yes(request.form["is_positive"])
|
||||||
|
|
||||||
@ -213,7 +212,15 @@ def handle_review_vote(package: Package, review_id: int):
|
|||||||
@login_required
|
@login_required
|
||||||
@is_package_page
|
@is_package_page
|
||||||
def review_vote(package, review_id):
|
def review_vote(package, review_id):
|
||||||
handle_review_vote(package, review_id)
|
msg = handle_review_vote(package, review_id)
|
||||||
|
if should_return_json():
|
||||||
|
if msg:
|
||||||
|
return jsonify({"success": False, "error": msg}), 403
|
||||||
|
else:
|
||||||
|
return jsonify({"success": True})
|
||||||
|
|
||||||
|
if msg:
|
||||||
|
flash(msg, "danger")
|
||||||
|
|
||||||
next_url = request.args.get("r")
|
next_url = request.args.get("r")
|
||||||
if next_url and is_safe_url(next_url):
|
if next_url and is_safe_url(next_url):
|
||||||
|
@ -41,11 +41,24 @@ async function submitForm(form, is_helpful) {
|
|||||||
body: data,
|
body: data,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Accept": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error(await res.text());
|
const json = await res.json();
|
||||||
|
alert(json.error ?? "Unknown server error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setButtonSelected(ele, isSelected) {
|
||||||
|
if (isSelected) {
|
||||||
|
ele.classList.add("btn-primary");
|
||||||
|
ele.classList.remove("btn-secondary");
|
||||||
|
} else {
|
||||||
|
ele.classList.add("btn-secondary");
|
||||||
|
ele.classList.remove("btn-primary");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,15 +74,16 @@ window.addEventListener("load", () => {
|
|||||||
|
|
||||||
if (not_selected.classList.contains("btn-primary")) {
|
if (not_selected.classList.contains("btn-primary")) {
|
||||||
setVoteCount(not_selected, Math.max(getVoteCount(not_selected) - 1, 0));
|
setVoteCount(not_selected, Math.max(getVoteCount(not_selected) - 1, 0));
|
||||||
}
|
setButtonSelected(not_selected, false);
|
||||||
if (selected.classList.contains("btn-secondary")) {
|
|
||||||
setVoteCount(selected, getVoteCount(selected) + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selected.classList.add("btn-primary");
|
if (selected.classList.contains("btn-secondary")) {
|
||||||
selected.classList.remove("btn-secondary");
|
setVoteCount(selected, getVoteCount(selected) + 1);
|
||||||
not_selected.classList.add("btn-secondary");
|
setButtonSelected(selected, true);
|
||||||
not_selected.classList.remove("btn-primary");
|
} else if (selected.classList.contains("btn-primary")) {
|
||||||
|
setVoteCount(selected, Math.max(getVoteCount(selected) - 1, 0));
|
||||||
|
setButtonSelected(selected, false);
|
||||||
|
}
|
||||||
|
|
||||||
submitForm(helpful_form, is_helpful).catch(console.error);
|
submitForm(helpful_form, is_helpful).catch(console.error);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<script src="/static/js/quick_review_voting.js"></script>
|
<script src="/static/js/quick_review_voting.js?v=2"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<script src="/static/js/quick_review_voting.js"></script>
|
<script src="/static/js/quick_review_voting.js?v=2"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<script src="/static/js/video_embed.js"></script>
|
<script src="/static/js/video_embed.js"></script>
|
||||||
<script src="/static/js/gallery_carousel.js"></script>
|
<script src="/static/js/gallery_carousel.js"></script>
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<script src="/static/js/quick_review_voting.js"></script>
|
<script src="/static/js/quick_review_voting.js?v=2"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<script src="/static/js/quick_review_voting.js"></script>
|
<script src="/static/js/quick_review_voting.js?v=2"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
{% if current_user.is_authenticated %}
|
{% if current_user.is_authenticated %}
|
||||||
<script src="/static/js/quick_review_voting.js"></script>
|
<script src="/static/js/quick_review_voting.js?v=2"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user