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