1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +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; margin-left: -1em;
} }
&.admin { &.list-admin {
&::before { &::before {
color: #ffff00; color: #ffff00;
} }
} }
&.list-locked {
&::before {
color: #555555;
}
}
} }
} }

View file

@ -83,4 +83,10 @@ class DIARIOSEARCH:
class ERRORS: class ERRORS:
INVALID_SYNTAX = "⚠ Non hai specificato un termine da cercare!\nSintassi: <pre>/{command} (termine)</pre>" 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." 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"> <div class="lower-box">
<ul class="multicolumn"> <ul class="multicolumn">
{% for royal in royals %} {% 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 %} {% endfor %}
</ul> </ul>
</div> </div>

View file

@ -11,7 +11,7 @@
<div class="lower-box"> <div class="lower-box">
<ul class="multicolumn"> <ul class="multicolumn">
{% for page in wiki_pages %} {% 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 %} {% endfor %}
</ul> </ul>
{% if g.user %} {% if g.user %}

View file

@ -47,7 +47,7 @@
{% if g.user %} {% if g.user %}
<div class="wiki-edit"> <div class="wiki-edit">
<h4>Modifica</h4> <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> <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="reason" name="reason" type="text" placeholder="Motivo per la modifica"><br>
<input class="submit" type="submit" onmouseenter="onEnter()" onmouseleave="onExit()" value="Invia"> <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> <span>🔒 Pagina bloccata: non possono essere effettuate ulteriori modifiche.</span>
</div> </div>
{% endif %} {% 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> </div>
{% endblock %} {% endblock %}

View file

@ -13,6 +13,7 @@ import sql_queries
import random import random
import re import re
import functools import functools
import strings
from sqlalchemy.orm.collections import InstrumentedList from sqlalchemy.orm.collections import InstrumentedList
from raven.contrib.flask import Sentry from raven.contrib.flask import Sentry
@ -228,79 +229,111 @@ def page_game(name: str):
return render_template("game.html", mini_type=game, mini_data=query) 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): 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() 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) \
wiki_latest_edit = fl_g.session.query(db.WikiLog).filter_by(edited_key=key) \ .order_by(db.WikiLog.timestamp.desc()).first()
.order_by(db.WikiLog.timestamp.desc()).first() if wiki_page is None:
if wiki_page is None: return render_template("wikipage.html", key=key)
return render_template("wikipage.html", key=key) # Embed YouTube videos
# Embed YouTube videos converted_md = markdown2.markdown(wiki_page.content.replace("<", "&lt;"),
converted_md = markdown2.markdown(wiki_page.content.replace("<", "&lt;"), extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"])
extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"]) converted_md = re.sub(r"{https?://(?:www\.)?(?:youtube\.com/watch\?.*?&?v=|youtu.be/)([0-9A-Za-z-]+).*?}",
converted_md = re.sub(r"{https?://(?:www\.)?(?:youtube\.com/watch\?.*?&?v=|youtu.be/)([0-9A-Za-z-]+).*?}", r'<div class="youtube-embed">'
r'<div class="youtube-embed">' r' <iframe src="https://www.youtube-nocookie.com/embed/\1?rel=0&amp;showinfo=0"'
r' <iframe src="https://www.youtube-nocookie.com/embed/\1?rel=0&amp;showinfo=0"' r' frameborder="0"'
r' frameborder="0"' r' allow="autoplay; encrypted-media"'
r' allow="autoplay; encrypted-media"' r' allowfullscreen'
r' allowfullscreen' r' width="640px"'
r' width="640px"' r' height="320px">'
r' height="320px">' r' </iframe>'
r' </iframe>' r'</div>', converted_md)
r'</div>', converted_md) converted_md = re.sub(r"{https?://clyp.it/([a-z0-9]+)}",
converted_md = re.sub(r"{https?://clyp.it/([a-z0-9]+)}", r'<div class="clyp-embed">'
r'<div class="clyp-embed">' r' <iframe width="100%" height="160" src="https://clyp.it/\1/widget" frameborder="0">'
r' <iframe width="100%" height="160" src="https://clyp.it/\1/widget" frameborder="0">' r' </iframe>'
r' </iframe>' r'</div>', converted_md)
r'</div>', converted_md) return render_template("wikipage.html", key=key, wiki_page=wiki_page, converted_md=Markup(converted_md),
return render_template("wikipage.html", key=key, wiki_page=wiki_page, converted_md=Markup(converted_md), wiki_log=wiki_latest_edit)
wiki_log=wiki_latest_edit)
elif request.method == "POST":
if not fl_g.user: @app.route("/wiki/<key>/edit", methods=["POST"])
return redirect(url_for("page_login")) @require_login
if wiki_page.locked: def page_wiki_edit(key: str):
abort(403) wiki_page = fl_g.session.query(db.WikiEntry).filter_by(key=key).one_or_none()
return if wiki_page.locked:
user = fl_g.session.query(db.Royal).filter_by(id=fl_g.user.id).one() abort(403)
new_content = request.form.get("content") return
# Create new page new_content = request.form.get("content")
if wiki_page is None: # Create new page
difference = len(new_content) if wiki_page is None:
wiki_page = db.WikiEntry(key=key, content=new_content) difference = len(new_content)
fl_g.session.add(wiki_page) wiki_page = db.WikiEntry(key=key, content=new_content)
fl_g.session.flush() fl_g.session.add(wiki_page)
# Edit existing page fl_g.session.flush()
else: # Edit existing page
difference = len(new_content) - len(wiki_page.content) else:
wiki_page.content = new_content difference = len(new_content) - len(wiki_page.content)
# Award fiorygi wiki_page.content = new_content
if difference > 50: # Award fiorygi
fioryg_chance = -(5000/difference) + 100 if difference > 50:
fioryg_roll = random.randrange(0, 100) fioryg_chance = -(5000/difference) + 100
if fioryg_roll > fioryg_chance: fioryg_roll = random.randrange(0, 100)
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)
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' {"(" + edit_reason + ")" if edit_reason else ""}' \
f' [{"+" if difference > 0 else ""}{difference}]\n'
if fioryg_roll > fioryg_chance: if fioryg_roll > fioryg_chance:
message += f"⭐️ {user.username} è stato premiato con 1 fioryg per la modifica!" fl_g.user.fiorygi += 1
try: else:
telegram_bot.send_message(config["Telegram"]["main_group"], message, fioryg_chance = -1
parse_mode="HTML", disable_web_page_preview=True, disable_notification=True) fioryg_roll = -2
except Exception: edit_reason = request.form.get("reason")
pass new_log = db.WikiLog(editor=fl_g.user, edited_key=key, timestamp=datetime.datetime.now(), reason=edit_reason)
return redirect(url_for("page_wiki", key=key)) 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/{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"⭐️ {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)
except Exception:
pass
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") @app.route("/diario")