Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Alsijil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Alsijil
Commits
7c0a44c8
Verified
Commit
7c0a44c8
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Ensure that original teachers only can view substituted lessons
parent
c2e98047
No related branches found
No related tags found
1 merge request
!158
Resolve "Check permission rules if they handle lessons with substitutions correctly"
Pipeline
#6275
passed
4 years ago
Stage: test
Stage: build
Stage: publish
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/alsijil/rules.py
+7
-1
7 additions, 1 deletion
aleksis/apps/alsijil/rules.py
aleksis/apps/alsijil/util/predicates.py
+34
-4
34 additions, 4 deletions
aleksis/apps/alsijil/util/predicates.py
with
41 additions
and
5 deletions
aleksis/apps/alsijil/rules.py
+
7
−
1
View file @
7c0a44c8
...
...
@@ -15,6 +15,7 @@ from .util.predicates import (
is_group_member
,
is_group_owner
,
is_group_role_assignment_group_owner
,
is_lesson_original_teacher
,
is_lesson_parent_group_owner
,
is_lesson_participant
,
is_lesson_teacher
,
...
...
@@ -23,6 +24,7 @@ from .util.predicates import (
is_owner_of_any_group
,
is_person_group_owner
,
is_person_primary_group_owner
,
is_personal_note_lesson_original_teacher
,
is_personal_note_lesson_parent_group_owner
,
is_personal_note_lesson_teacher
,
is_teacher
,
...
...
@@ -32,6 +34,7 @@ from .util.predicates import (
view_register_object_predicate
=
has_person
&
(
is_none
# View is opened as "Current lesson"
|
is_lesson_teacher
|
is_lesson_original_teacher
|
is_lesson_participant
|
is_lesson_parent_group_owner
|
has_global_perm
(
"
alsijil.view_lesson
"
)
...
...
@@ -46,6 +49,7 @@ add_perm("alsijil.view_lesson_menu", has_person)
view_lesson_personal_notes_predicate
=
view_register_object_predicate
&
(
~
is_lesson_participant
|
is_lesson_teacher
|
is_lesson_original_teacher
|
has_global_perm
(
"
alsijil.view_personalnote
"
)
|
has_lesson_group_object_perm
(
"
core.view_personalnote_group
"
)
)
...
...
@@ -63,6 +67,7 @@ add_perm("alsijil.edit_register_object_personalnote", edit_lesson_personal_note_
view_personal_note_predicate
=
has_person
&
(
(
is_own_personal_note
&
is_site_preference_set
(
"
alsijil
"
,
"
view_own_personal_notes
"
))
|
is_personal_note_lesson_teacher
|
is_personal_note_lesson_original_teacher
|
is_personal_note_lesson_parent_group_owner
|
has_global_perm
(
"
alsijil.view_personalnote
"
)
|
has_personal_note_group_perm
(
"
core.view_personalnote_group
"
)
...
...
@@ -71,7 +76,7 @@ add_perm("alsijil.view_personalnote", view_personal_note_predicate)
# Edit personal note
edit_personal_note_predicate
=
view_personal_note_predicate
&
(
~
is_own_personal_note
~
is_own_personal_note
&
~
is_personal_note_lesson_original_teacher
|
has_global_perm
(
"
alsijil.view_personalnote
"
)
|
has_personal_note_group_perm
(
"
core.edit_personalnote_group
"
)
)
...
...
@@ -242,6 +247,7 @@ add_perm("alsijil.delete_grouprole", delete_group_role_predicate)
view_assigned_group_roles_predicate
=
(
is_group_owner
|
is_lesson_teacher
|
is_lesson_original_teacher
|
is_lesson_parent_group_owner
|
has_global_perm
(
"
alsjil.assign_grouprole
"
)
|
has_object_perm
(
"
alsijil.assign_grouprole
"
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/alsijil/util/predicates.py
+
34
−
4
View file @
7c0a44c8
...
...
@@ -22,8 +22,22 @@ def is_none(user: User, obj: Any) -> bool:
def
is_lesson_teacher
(
user
:
User
,
obj
:
Union
[
LessonPeriod
,
Event
,
ExtraLesson
])
->
bool
:
"""
Predicate for teachers of a lesson.
Checks whether the person linked to the user is a teacher
in the lesson or the substitution linked to the given LessonPeriod.
Checks whether the person linked to the user is a teacher in the register object.
If the register object is a lesson period and has a substitution linked,
this will **only** check if the person is one of the substitution teachers.
"""
if
obj
:
return
user
.
person
in
obj
.
get_teachers
().
all
()
return
False
@predicate
def
is_lesson_original_teacher
(
user
:
User
,
obj
:
Union
[
LessonPeriod
,
Event
,
ExtraLesson
])
->
bool
:
"""
Predicate for teachers of a lesson.
Checks whether the person linked to the user is a teacher in the register object.
If the register object is a lesson period and has a substitution linked,
this will **also** check if the person is one of the substitution teachers.
"""
if
obj
:
if
isinstance
(
obj
,
LessonPeriod
)
and
user
.
person
in
obj
.
lesson
.
teachers
.
all
():
...
...
@@ -205,10 +219,26 @@ def is_own_personal_note(user: User, obj: PersonalNote) -> bool:
@predicate
def
is_personal_note_lesson_teacher
(
user
:
User
,
obj
:
PersonalNote
)
->
bool
:
"""
Predicate for teachers of a lesson referred to in the lesson period of a personal note.
"""
Predicate for teachers of a register object linked to a personal note.
Checks whether the person linked to the user is a teacher
in the register object linked to the personal note.
If the register object is a lesson period and has a substitution linked,
this will **only** check if the person is one of the substitution teachers.
"""
if
hasattr
(
obj
,
"
register_object
"
):
return
user
.
person
in
obj
.
register_object
.
get_teachers
().
all
()
return
False
@predicate
def
is_personal_note_lesson_original_teacher
(
user
:
User
,
obj
:
PersonalNote
)
->
bool
:
"""
Predicate for teachers of a register object linked to a personal note.
Checks whether the person linked to the user is a teacher
in the lesson or the substitution linked to the LessonPeriod of the given PersonalNote.
in the register object linked to the personal note.
If the register object is a lesson period and has a substitution linked,
this will **also** check if the person is one of the substitution teachers.
"""
if
hasattr
(
obj
,
"
register_object
"
):
if
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment