Added the editor2 user to the test site.

This commit is contained in:
依瑪貓 2023-02-06 23:28:21 +08:00
parent 52351c52bc
commit 7873e16cc3
4 changed files with 12 additions and 6 deletions

View File

@ -91,9 +91,9 @@ def create_app(is_testing: bool = False) -> Flask:
return user.id
can_view: t.Callable[[], bool] = lambda: auth.current_user() is not None \
and auth.current_user().username in ["viewer", "editor"]
and auth.current_user().username in ["viewer", "editor", "editor2"]
can_edit: t.Callable[[], bool] = lambda: auth.current_user() is not None \
and auth.current_user().username == "editor"
and auth.current_user().username in ["editor", "editor2"]
accounting.init_app(app, user_utils=UserUtils(),
can_view_func=can_view, can_edit_func=can_edit)
@ -106,7 +106,7 @@ def init_db_command() -> None:
"""Initializes the database."""
db.create_all()
from .auth import User
for username in ["viewer", "editor", "nobody"]:
for username in ["viewer", "editor", "editor2", "nobody"]:
if User.query.filter(User.username == username).first() is None:
db.session.add(User(username=username))
db.session.commit()

View File

@ -58,7 +58,8 @@ def login() -> redirect:
:return: The redirection to the home page.
"""
if request.form.get("username") not in ["viewer", "editor", "nobody"]:
if request.form.get("username") not in ["viewer", "editor", "editor2",
"nobody"]:
return redirect(url_for("auth.login"))
session["user"] = request.form.get("username")
return redirect(url_for("home.home"))

View File

@ -29,6 +29,7 @@ First written: 2023/1/27
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button class="btn btn-primary" type="submit" name="username" value="viewer">{{ _("Viewer") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="editor">{{ _("Editor") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="editor2">{{ _("Editor2") }}</button>
<button class="btn btn-primary" type="submit" name="username" value="nobody">{{ _("Nobody") }}</button>
</form>

View File

@ -9,8 +9,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Mia! Accounting Flask Demonstration 0.0.0\n"
"Report-Msgid-Bugs-To: imacat@mail.imacat.idv.tw\n"
"POT-Creation-Date: 2023-01-28 13:42+0800\n"
"PO-Revision-Date: 2023-01-28 13:42+0800\n"
"POT-Creation-Date: 2023-02-06 23:25+0800\n"
"PO-Revision-Date: 2023-02-06 23:26+0800\n"
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
"Language: zh_Hant\n"
"Language-Team: zh_Hant <imacat@mail.imacat.idv.tw>\n"
@ -51,6 +51,10 @@ msgid "Editor"
msgstr "記帳者"
#: tests/test_site/templates/login.html:32
msgid "Editor2"
msgstr "記帳者2"
#: tests/test_site/templates/login.html:33
msgid "Nobody"
msgstr "沒有權限者"