mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Fix admin lockout check
This commit is contained in:
parent
52506fc47f
commit
300d869ed8
1 changed files with 177 additions and 41 deletions
|
@ -101,7 +101,15 @@ class UserView(SecureAdminModelView):
|
|||
|
||||
can_view_details = True
|
||||
|
||||
column_list = ["first_name", "last_name", "email", "active", "roles", "assistant", "active_semester"]
|
||||
column_list = [
|
||||
"first_name",
|
||||
"last_name",
|
||||
"email",
|
||||
"active",
|
||||
"roles",
|
||||
"assistant",
|
||||
"active_semester",
|
||||
]
|
||||
column_details_list = column_list + [
|
||||
"phone_number",
|
||||
"mobile_phone_number",
|
||||
|
@ -110,9 +118,18 @@ class UserView(SecureAdminModelView):
|
|||
"create_datetime",
|
||||
"update_datetime",
|
||||
]
|
||||
column_searchable_list = ["first_name", "last_name", "email"]
|
||||
column_filters = ["active", "active_semester"]
|
||||
column_editable_list = ["active"]
|
||||
column_searchable_list = [
|
||||
"first_name",
|
||||
"last_name",
|
||||
"email",
|
||||
]
|
||||
column_filters = [
|
||||
"active",
|
||||
"active_semester",
|
||||
]
|
||||
column_editable_list = [
|
||||
"active",
|
||||
]
|
||||
|
||||
def create_form(self, obj=None):
|
||||
form = self.CreateForm
|
||||
|
@ -167,7 +184,8 @@ class UserView(SecureAdminModelView):
|
|||
|
||||
def on_model_change(self, form, model, is_created):
|
||||
if not is_created:
|
||||
if model == current_user and not form.active.data:
|
||||
if model == current_user:
|
||||
if not form.active.data:
|
||||
raise ModelViewException("Tried to deactiavte yourself as user!")
|
||||
if not model.has_role("admin"):
|
||||
raise ModelViewException("Tried to remove your admin role!")
|
||||
|
@ -196,7 +214,12 @@ class RoleView(SecureAdminModelView):
|
|||
can_export = False
|
||||
can_set_page_size = False
|
||||
|
||||
column_list = ["name", "description", "permissions", "update_datetime"]
|
||||
column_list = [
|
||||
"name",
|
||||
"description",
|
||||
"permissions",
|
||||
"update_datetime",
|
||||
]
|
||||
|
||||
|
||||
class SemesterView(SecureAdminModelView):
|
||||
|
@ -233,9 +256,20 @@ class SemesterView(SecureAdminModelView):
|
|||
can_delete = False
|
||||
can_view_details = True
|
||||
|
||||
column_list = ["label", "year", "parts"]
|
||||
column_details_list = column_list + ["semester_experiments", "active_users", "groups"]
|
||||
column_searchable_list = ["label", "year"]
|
||||
column_list = [
|
||||
"label",
|
||||
"year",
|
||||
"parts",
|
||||
]
|
||||
column_details_list = column_list + [
|
||||
"semester_experiments",
|
||||
"active_users",
|
||||
"groups",
|
||||
]
|
||||
column_searchable_list = [
|
||||
"label",
|
||||
"year",
|
||||
]
|
||||
|
||||
def customCreateModel(self, form):
|
||||
return Semester.customInitFromOldSemester(
|
||||
|
@ -270,9 +304,18 @@ class PartView(SecureAdminModelView):
|
|||
can_view_details = True
|
||||
|
||||
column_sortable_list = []
|
||||
column_list = ["program", "number", "semester"]
|
||||
column_details_list = column_list + ["part_students"]
|
||||
form_columns = ["program", "number"]
|
||||
column_list = [
|
||||
"program",
|
||||
"number",
|
||||
"semester",
|
||||
]
|
||||
column_details_list = column_list + [
|
||||
"part_students",
|
||||
]
|
||||
form_columns = [
|
||||
"program",
|
||||
"number",
|
||||
]
|
||||
|
||||
form_extra_fields = {
|
||||
"program": QuerySelectField(
|
||||
|
@ -290,14 +333,36 @@ class PartView(SecureAdminModelView):
|
|||
class StudentView(SecureAdminModelView):
|
||||
can_view_details = True
|
||||
|
||||
column_list = ["student_number", "first_name", "last_name", "uni_email", "contact_email", "part_students"]
|
||||
column_descriptions = {"contact_email": "The preferred contact email address if entered by the student"}
|
||||
column_details_list = column_list + ["bachelor_thesis", "bachelor_thesis_work_group", "note"]
|
||||
column_list = [
|
||||
"student_number",
|
||||
"first_name",
|
||||
"last_name",
|
||||
"uni_email",
|
||||
"contact_email",
|
||||
"part_students",
|
||||
]
|
||||
column_descriptions = {
|
||||
"contact_email": "The preferred contact email address if entered by the student",
|
||||
}
|
||||
column_details_list = column_list + [
|
||||
"bachelor_thesis",
|
||||
"bachelor_thesis_work_group",
|
||||
"note",
|
||||
]
|
||||
|
||||
column_sortable_list = ["student_number", "first_name", "last_name"]
|
||||
column_searchable_list = column_sortable_list + ["uni_email", "contact_email"]
|
||||
column_sortable_list = [
|
||||
"student_number",
|
||||
"first_name",
|
||||
"last_name",
|
||||
]
|
||||
column_searchable_list = column_sortable_list + [
|
||||
"uni_email",
|
||||
"contact_email",
|
||||
]
|
||||
|
||||
form_excluded_columns = ["part_students"]
|
||||
form_excluded_columns = [
|
||||
"part_students",
|
||||
]
|
||||
|
||||
form_args = {
|
||||
"uni_email": {"validators": [Email()]},
|
||||
|
@ -354,9 +419,19 @@ class PartStudentView(SecureAdminModelView):
|
|||
|
||||
form = EditForm
|
||||
|
||||
column_list = ["student", "part", "group", "final_part_mark", "experiment_marks"]
|
||||
column_list = [
|
||||
"student",
|
||||
"part",
|
||||
"group",
|
||||
"final_part_mark",
|
||||
"experiment_marks",
|
||||
]
|
||||
|
||||
column_filters = ["part", "student", "group"]
|
||||
column_filters = [
|
||||
"part",
|
||||
"student",
|
||||
"group",
|
||||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return PartStudent.part.has(Part.semester == userActiveSemester())
|
||||
|
@ -400,8 +475,18 @@ class GroupView(SecureAdminModelView):
|
|||
|
||||
return CustomForm
|
||||
|
||||
column_list = ["number", "semester", "program", "part_students", "group_experiments"]
|
||||
column_filters = ["number", "semester", "program"]
|
||||
column_list = [
|
||||
"number",
|
||||
"semester",
|
||||
"program",
|
||||
"part_students",
|
||||
"group_experiments",
|
||||
]
|
||||
column_filters = [
|
||||
"number",
|
||||
"semester",
|
||||
"program",
|
||||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return Group.semester == userActiveSemester()
|
||||
|
@ -421,9 +506,18 @@ class GroupView(SecureAdminModelView):
|
|||
class ExperimentView(SecureAdminModelView):
|
||||
can_view_details = True
|
||||
|
||||
column_filters = ["active"]
|
||||
column_list = ["number", "program", "title", "active"]
|
||||
column_descriptions = {"active": "Active experiments are present in new semesters"}
|
||||
column_filters = [
|
||||
"active",
|
||||
]
|
||||
column_list = [
|
||||
"number",
|
||||
"program",
|
||||
"title",
|
||||
"active",
|
||||
]
|
||||
column_descriptions = {
|
||||
"active": "Active experiments are present in new semesters",
|
||||
}
|
||||
column_details_list = column_list + [
|
||||
"description",
|
||||
"wiki_link",
|
||||
|
@ -440,7 +534,9 @@ class ExperimentView(SecureAdminModelView):
|
|||
form_columns = column_details_list.copy()
|
||||
form_columns.remove("semester_experiments")
|
||||
|
||||
column_editable_list = ["active"]
|
||||
column_editable_list = [
|
||||
"active",
|
||||
]
|
||||
|
||||
form_args = {
|
||||
"wiki_link": {"validators": [URL()]},
|
||||
|
@ -481,9 +577,17 @@ class SemesterExperimentView(SecureAdminModelView):
|
|||
|
||||
can_view_details = True
|
||||
|
||||
column_list = ["experiment", "assistants", "semester"]
|
||||
column_details_list = column_list + ["group_experiments"]
|
||||
column_filters = ["experiment"]
|
||||
column_list = [
|
||||
"experiment",
|
||||
"assistants",
|
||||
"semester",
|
||||
]
|
||||
column_details_list = column_list + [
|
||||
"group_experiments",
|
||||
]
|
||||
column_filters = [
|
||||
"experiment",
|
||||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return SemesterExperiment.semester == userActiveSemester()
|
||||
|
@ -500,7 +604,12 @@ class AssistantView(SecureAdminModelView):
|
|||
|
||||
can_view_details = True
|
||||
|
||||
column_list = ["user.first_name", "user.last_name", "user", "semester_experiments"]
|
||||
column_list = [
|
||||
"user.first_name",
|
||||
"user.last_name",
|
||||
"user",
|
||||
"semester_experiments",
|
||||
]
|
||||
column_details_list = column_list + [
|
||||
"user.phone_number",
|
||||
"user.mobile_phone_number",
|
||||
|
@ -509,9 +618,18 @@ class AssistantView(SecureAdminModelView):
|
|||
"appointments",
|
||||
"experiment_marks",
|
||||
]
|
||||
column_searchable_list = ["user.first_name", "user.last_name", "user.email"]
|
||||
column_filters = ["user.active"]
|
||||
form_excluded_columns = ["experiment_marks", "appointments"]
|
||||
column_searchable_list = [
|
||||
"user.first_name",
|
||||
"user.last_name",
|
||||
"user.email",
|
||||
]
|
||||
column_filters = [
|
||||
"user.active",
|
||||
]
|
||||
form_excluded_columns = [
|
||||
"experiment_marks",
|
||||
"appointments",
|
||||
]
|
||||
|
||||
form_extra_fields = {
|
||||
"user": QuerySelectField(
|
||||
|
@ -578,8 +696,17 @@ class GroupExperimentView(SecureAdminModelView):
|
|||
|
||||
can_edit = False
|
||||
|
||||
column_list = ["group", "semester_experiment", "appointments", "experiment_marks"]
|
||||
column_filters = ["group", "semester_experiment.experiment", "appointments"]
|
||||
column_list = [
|
||||
"group",
|
||||
"semester_experiment",
|
||||
"appointments",
|
||||
"experiment_marks",
|
||||
]
|
||||
column_filters = [
|
||||
"group",
|
||||
"semester_experiment.experiment",
|
||||
"appointments",
|
||||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
||||
|
@ -640,7 +767,10 @@ class AppointmentView(SecureAdminModelView):
|
|||
"group_experiment.semester_experiment.experiment",
|
||||
"assistant.user",
|
||||
]
|
||||
column_editable_list = ["date", "special"]
|
||||
column_editable_list = [
|
||||
"date",
|
||||
"special",
|
||||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return Appointment.group_experiment.has(
|
||||
|
@ -778,8 +908,14 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
class ProgramView(SecureAdminModelView):
|
||||
can_view_details = True
|
||||
|
||||
column_list = ["label"]
|
||||
form_excluded_columns = ["parts", "experiments", "groups"]
|
||||
column_list = [
|
||||
"label",
|
||||
]
|
||||
form_excluded_columns = [
|
||||
"parts",
|
||||
"experiments",
|
||||
"groups",
|
||||
]
|
||||
column_details_list = column_list + form_excluded_columns
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue