From cf8279616e6cda8163397499da997ece229b86d9 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Wed, 21 Sep 2022 16:52:04 +0200 Subject: [PATCH] Add user settings --- advlabdb/adminModelViews.py | 5 +- advlabdb/assistantModelViews.py | 16 +++--- advlabdb/model_dependent_funs.py | 11 +--- advlabdb/routes.py | 13 +++++ advlabdb/templates/docs/assistant.jinja.html | 56 +++++++++++--------- advlabdb/templates/macros.jinja.html | 39 ++++++++------ 6 files changed, 81 insertions(+), 59 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index c358fc4..7679dee 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -1524,8 +1524,6 @@ class DocsView(SecureAdminBaseView): def init_admin_model_views(app): - adminSpace.init_app(app) - adminSpace.add_view(StudentView(Student, url="student")) adminSpace.add_view(PartStudentView(PartStudent, url="part_student")) adminSpace.add_view(GroupView(Group, url="group")) @@ -1545,4 +1543,7 @@ def init_admin_model_views(app): adminSpace.add_view(AnalysisView(name="Analysis", url="analysis")) adminSpace.add_view(DocsView(name="Docs", url="docs")) + adminSpace.add_link(MenuLink(name="User settings", url="/user-settings")) adminSpace.add_link(MenuLink(name="Logout", url="/logout")) + + adminSpace.init_app(app) diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index ed22d54..1334438 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -27,7 +27,6 @@ from .model_dependent_funs import ( generate_new_password_field, parse_selection_mark_field, user_info_fields, - user_settings_url, ) from .model_independent_funs import randomPassword, reportBadAttempt from .models import Assistant, GroupExperiment, Semester, SemesterExperiment, User, db @@ -53,7 +52,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView): if not semester_changed: flash( Markup( - f"Active semester {active_semester} is set as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in user settings if possible." + f"Active semester {active_semester} is set as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in user settings if possible." ), "danger", ) @@ -131,7 +130,8 @@ class AssistantGroupExperimentView(SecureAssistantModelView): if group_experiment not in self.get_query(): reportBadAttempt("Assistant {current_user} tried to edit {group_experiment}") - raise ModelViewException("Unauthorized action!") + self.handle_view_exception(ModelViewException("Unauthorized action!")) + return redirect(self.url) form, appointments, experiment_marks = assistant_group_experiment_form_factory(current_user, group_experiment) @@ -261,10 +261,14 @@ class AssistantDocsView(SecureAssistantBaseView): def init_assistant_model_views(app): - assistantSpace.init_app(app) - assistantSpace.add_view(AssistantGroupExperimentView(GroupExperiment, url="group_experiment")) - assistantSpace.add_view(AssistantUserView(User, url="user")) assistantSpace.add_view(AssistantDocsView(name="Docs", url="docs")) + # Don't add to menu + # Has to be placed before assistantSpace.init_app + assistantSpace._views.append(AssistantUserView(User, url="user")) + + assistantSpace.add_link(MenuLink(name="User settings", url="/user-settings")) assistantSpace.add_link(MenuLink(name="Logout", url="/logout")) + + assistantSpace.init_app(app) diff --git a/advlabdb/model_dependent_funs.py b/advlabdb/model_dependent_funs.py index 76e0940..7a33582 100644 --- a/advlabdb/model_dependent_funs.py +++ b/advlabdb/model_dependent_funs.py @@ -13,22 +13,13 @@ from wtforms.validators import DataRequired, NumberRange, Optional from .models import MAX_MARK, MIN_MARK, Semester -def user_settings_url(): - if current_user.has_role("admin"): - role = "admin" - else: - role = "assistant" - - return url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id) - - def active_semester_str(): active_semester = current_user.active_semester active_semester_str = str(active_semester) if active_semester != Semester.lastSemester(): flash( Markup( - f"You are in the old semester {active_semester_str}! You should change your active semester in user settings." + f"You are in the old semester {active_semester_str}! You should change your active semester in user settings." ), "warning", ) diff --git a/advlabdb/routes.py b/advlabdb/routes.py index b1c5442..e03562c 100644 --- a/advlabdb/routes.py +++ b/advlabdb/routes.py @@ -48,3 +48,16 @@ def post_login(): url = url_for(endpoint_base + ".index") return redirect(url) + + +@bp.route("/user-settings") +@auth_required() +def user_settings(): + if current_user.has_role("admin"): + role = "admin" + else: + role = "assistant" + + url = url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id) + + return redirect(url) diff --git a/advlabdb/templates/docs/assistant.jinja.html b/advlabdb/templates/docs/assistant.jinja.html index b68da16..987f8b4 100644 --- a/advlabdb/templates/docs/assistant.jinja.html +++ b/advlabdb/templates/docs/assistant.jinja.html @@ -13,7 +13,7 @@

Home

- This is your home page. Here, you currently only find the number of + This is your home page. Here, you find the number of missing final experiment marks for the experiments that you are assigned to. At the latest at the end of the semester, this number should be 0. A number higher than 0 means that some oral and/or protocol marks are @@ -21,7 +21,7 @@ and protocol marks of an experiment are set.

-

Group Experiment

+

Group Experiment

This is the most important menu item. Here, you see all pairs of experiments and groups that you are responsible for. If a value in the column @@ -48,38 +48,25 @@ Oral and protocol marks are between 0 and 15!

- After editing appointment date(s) or experiment marks, click on the - Save button to save the changes. + After editing appointment date(s) or experiment marks, click on + Save to save the changes.

The changes are lost if you don't click on Save. Therefore, if you want to discard the changes, just click on the back button of your browser.

-

User

-

- Here, you find a table with only one row which is you as a user. Make sure - that the fields Phone Number, Mobile Phone Number, - Building and Room are filled and up to date, especially if - you are a new assistant. To edit these fields, click on the pen icon at the - left of the single entry in the table. After editing, click on Save. -

-

- You can generate a new random password by clicking on the pen icon, checking - the corresponding checkbox and then clicking on - Save. You will be then logged out. Your new password is displayed - above the login fields. Make sure that you save the password in a safe place. - Using a free open source password manager like - Bitwarden - or - KeepassXC - is recommended. -

-

Docs

This is a link which leads you to this page.

-

Active semester

+

User settings

+

+ In the user settings, You can change your active semester, user information + and password. Don't forget to click on Save after changing any + option. +

+ +

Active semester

An active semester is the semester you are working in. All shown experiment marks and appointments are in your active semester. By default as a new @@ -90,3 +77,22 @@ your active semester in the user settings. You should only work in an old semester if there are still experiment marks to be set in the old semester.

+ +

User information

+

+ Make sure that the fields Phone Number, Mobile Phone Number, + Building and Room are filled and up to date, especially if + you are a new assistant. +

+ +

Password

+

+ You can generate a new random password by checking the corresponding checkbox + and then clicking on Save. You will be then logged out. Your new + password is displayed above the login fields. Make sure that you save the + password in a safe place. Using a free open source password manager like + Bitwarden + or + KeepassXC + is recommended. +

diff --git a/advlabdb/templates/macros.jinja.html b/advlabdb/templates/macros.jinja.html index 1213c97..9ebec59 100644 --- a/advlabdb/templates/macros.jinja.html +++ b/advlabdb/templates/macros.jinja.html @@ -1,18 +1,25 @@ {% macro information(current_user, active_semester_str, role) %} - User: - {{ current_user }} - | Active semester: {{ active_semester_str() }} - {% if (role == "admin") and (current_user.has_role("assistant")) %} - | - Assistant space. - {% elif (role == "assistant") and (current_user.has_role("admin")) %} - | - Admin space. - {% endif %} +
+
+ User: {{ current_user }} +
+ +
+ Active semester: {{ active_semester_str() }} +
+ + {% if (role == "admin") and (current_user.has_role("assistant")) %} + + {% elif (role == "assistant") and (current_user.has_role("admin")) %} + + {% endif %} +
{% endmacro %}