1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Add page lock button

This commit is contained in:
Steffo 2019-02-03 19:34:17 +01:00
parent eb08b51e59
commit 9de4513290
6 changed files with 125 additions and 75 deletions

View file

@ -225,11 +225,17 @@ ul {
margin-left: -1em;
}
&.admin {
&.list-admin {
&::before {
color: #ffff00;
}
}
&.list-locked {
&::before {
color: #555555;
}
}
}
}

View file

@ -84,3 +84,9 @@ class DIARIOSEARCH:
class ERRORS:
INVALID_SYNTAX = "⚠ Non hai specificato un termine da cercare!\nSintassi: <pre>/{command} (termine)</pre>"
RESULTS_TOO_LONG = "⚠ Sono presenti troppi risultati da visualizzare! Prova a restringere la ricerca."
# Wiki notifications
class WIKI:
PAGE_LOCKED = '🔒 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata bloccata da <b>{user}</b>.'
PAGE_UNLOCKED = '🔓 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata sbloccata da <b>{user}</b>.'

View file

@ -5,7 +5,7 @@
<div class="lower-box">
<ul class="multicolumn">
{% for royal in royals %}
<li class="{% if royal.role == "Admin" %}admin{% endif %}"><a href="/profile/{{ royal.username }}">{{ royal.username }}</a></li>
<li class="{% if royal.role == "Admin" %}list-admin{% endif %}"><a href="/profile/{{ royal.username }}">{{ royal.username }}</a></li>
{% endfor %}
</ul>
</div>

View file

@ -11,7 +11,7 @@
<div class="lower-box">
<ul class="multicolumn">
{% for page in wiki_pages %}
<li><a href="/wiki/{{ page.key }}">{{ page.key }}</a></li>
<li class="{% if page.locked %}list-locked{% endif %}"><a href="/wiki/{{ page.key }}">{{ page.key }}</a></li>
{% endfor %}
</ul>
{% if g.user %}

View file

@ -47,7 +47,7 @@
{% if g.user %}
<div class="wiki-edit">
<h4>Modifica</h4>
<form action="{{ url_for('page_wiki', key=key) }}" method="POST">
<form action="{{ url_for('page_wiki_edit', key=key) }}" method="POST">
<textarea oninput="newEdit()" class="content" name="content" placeholder="Inserisci il Markdown per la pagina qui.">{% if wiki_page %}{{ wiki_page.content }}{% endif %}</textarea><br>
<input class="reason" name="reason" type="text" placeholder="Motivo per la modifica"><br>
<input class="submit" type="submit" onmouseenter="onEnter()" onmouseleave="onExit()" value="Invia">
@ -59,5 +59,10 @@
<span>🔒 Pagina bloccata: non possono essere effettuate ulteriori modifiche.</span>
</div>
{% endif %}
{% if g.user.role == "Admin" %}
<form action="{{ url_for('page_wiki_lock', key=key) }}" method="POST">
<input class="submit" type="submit" value="Blocca/Sblocca pagina">
</form>
{% endif %}
</div>
{% endblock %}

View file

@ -13,6 +13,7 @@ import sql_queries
import random
import re
import functools
import strings
from sqlalchemy.orm.collections import InstrumentedList
from raven.contrib.flask import Sentry
@ -228,11 +229,9 @@ def page_game(name: str):
return render_template("game.html", mini_type=game, mini_data=query)
@app.route("/wiki/<key>", methods=["GET", "POST"])
@app.route("/wiki/<key>")
def page_wiki(key: str):
fl_g.session = db.Session()
wiki_page = fl_g.session.query(db.WikiEntry).filter_by(key=key).one_or_none()
if request.method == "GET":
wiki_latest_edit = fl_g.session.query(db.WikiLog).filter_by(edited_key=key) \
.order_by(db.WikiLog.timestamp.desc()).first()
if wiki_page is None:
@ -257,13 +256,15 @@ def page_wiki(key: str):
r'</div>', converted_md)
return render_template("wikipage.html", key=key, wiki_page=wiki_page, converted_md=Markup(converted_md),
wiki_log=wiki_latest_edit)
elif request.method == "POST":
if not fl_g.user:
return redirect(url_for("page_login"))
@app.route("/wiki/<key>/edit", methods=["POST"])
@require_login
def page_wiki_edit(key: str):
wiki_page = fl_g.session.query(db.WikiEntry).filter_by(key=key).one_or_none()
if wiki_page.locked:
abort(403)
return
user = fl_g.session.query(db.Royal).filter_by(id=fl_g.user.id).one()
new_content = request.form.get("content")
# Create new page
if wiki_page is None:
@ -280,21 +281,21 @@ def page_wiki(key: str):
fioryg_chance = -(5000/difference) + 100
fioryg_roll = random.randrange(0, 100)
if fioryg_roll > fioryg_chance:
user.fiorygi += 1
fl_g.user.fiorygi += 1
else:
fioryg_chance = -1
fioryg_roll = -2
edit_reason = request.form.get("reason")
new_log = db.WikiLog(editor=user, edited_key=key, timestamp=datetime.datetime.now(), reason=edit_reason)
new_log = db.WikiLog(editor=fl_g.user, edited_key=key, timestamp=datetime.datetime.now(), reason=edit_reason)
fl_g.session.add(new_log)
fl_g.session.commit()
message = f' La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata' \
f' modificata da' \
f' <a href="https://ryg.steffo.eu/profile/{user.username}">{user.username}</a>' \
f' <a href="https://ryg.steffo.eu/profile/{fl_g.user.username}">{fl_g.user.username}</a>' \
f' {"(" + edit_reason + ")" if edit_reason else ""}' \
f' [{"+" if difference > 0 else ""}{difference}]\n'
if fioryg_roll > fioryg_chance:
message += f"⭐️ {user.username} è stato premiato con 1 fioryg per la modifica!"
message += f"⭐️ {fl_g.user.username} è stato premiato con 1 fioryg per la modifica!"
try:
telegram_bot.send_message(config["Telegram"]["main_group"], message,
parse_mode="HTML", disable_web_page_preview=True, disable_notification=True)
@ -303,6 +304,38 @@ def page_wiki(key: str):
return redirect(url_for("page_wiki", key=key))
@app.route("/wiki/<key>/lock", methods=["POST"])
@require_login
def page_wiki_lock(key: str):
wiki_page = fl_g.session.query(db.WikiEntry).filter_by(key=key).one_or_none()
if wiki_page is None:
abort(404)
return
if fl_g.user.role != "Admin":
abort(403)
return
wiki_page.locked = not wiki_page.locked
try:
if wiki_page.locked:
telegram_bot.send_message(config["Telegram"]["main_group"],
strings.safely_format_string(strings.WIKI.PAGE_LOCKED,
key=key,
user=fl_g.user.username),
parse_mode="HTML",
disable_notification=True)
else:
telegram_bot.send_message(config["Telegram"]["main_group"],
strings.safely_format_string(strings.WIKI.PAGE_UNLOCKED,
key=key,
user=fl_g.user.username),
parse_mode="HTML",
disable_notification=True)
except Exception:
pass
fl_g.session.commit()
return redirect(url_for("page_wiki", key=key))
@app.route("/diario")
@require_login
def page_diario():