1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Prevent assistants from viewing or changing marks in semesters marked as done

This commit is contained in:
Mo 2022-09-19 14:24:00 +02:00
parent bc0da570cd
commit 8020762261

View file

@ -7,6 +7,7 @@ from flask_admin.model.template import EndpointLinkRowAction
from flask_login import current_user from flask_login import current_user
from flask_security.changeable import admin_change_password from flask_security.changeable import admin_change_password
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from markupsafe import Markup
from wtforms.validators import DataRequired from wtforms.validators import DataRequired
from .advlabdb_independent_funs import ( from .advlabdb_independent_funs import (
@ -26,6 +27,7 @@ from .model_dependent_funs import (
generate_new_password_field, generate_new_password_field,
parse_selection_mark_field, parse_selection_mark_field,
user_info_fields, user_info_fields,
user_settings_url,
) )
from .model_independent_funs import randomPassword, reportBadAttempt from .model_independent_funs import randomPassword, reportBadAttempt
from .models import Assistant, GroupExperiment, Semester, SemesterExperiment, User, db from .models import Assistant, GroupExperiment, Semester, SemesterExperiment, User, db
@ -39,6 +41,19 @@ assistantSpace = FlaskAdmin(
class AssistantGroupExperimentView(SecureAssistantModelView): class AssistantGroupExperimentView(SecureAssistantModelView):
def is_accessible(self):
active_semester = current_user.active_semester
if active_semester.done:
flash(
Markup(
f"Active semester {active_semester} is marked as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in <a href='{ user_settings_url() }'>user settings</a>."
),
"danger",
)
return False
return super().is_accessible()
column_display_actions = True column_display_actions = True
column_list = [ column_list = [