Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Cursus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
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®
Onboarding
AlekSIS-App-Cursus
Commits
508b0d23
Commit
508b0d23
authored
9 months ago
by
Hangzhi Yu
Browse files
Options
Downloads
Patches
Plain Diff
Use rules and differentiate between course details and course in general
parent
6cccf2aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!43
Resolve "Rethink permission handling for subject/courses"
Pipeline
#187743
passed with warnings
9 months ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/cursus/rules.py
+6
-5
6 additions, 5 deletions
aleksis/apps/cursus/rules.py
aleksis/apps/cursus/schema.py
+6
-8
6 additions, 8 deletions
aleksis/apps/cursus/schema.py
with
12 additions
and
13 deletions
aleksis/apps/cursus/rules.py
+
6
−
5
View file @
508b0d23
...
...
@@ -15,9 +15,7 @@ view_subjects_predicate = has_person & (
)
add_perm
(
"
cursus.view_subjects_rule
"
,
view_subjects_predicate
)
view_subject_predicate
=
has_person
&
(
has_global_perm
(
"
cursus.view_subject
"
)
|
has_object_perm
(
"
cursus.view_subject
"
)
)
view_subject_predicate
=
has_person
add_perm
(
"
cursus.view_subject_rule
"
,
view_subject_predicate
)
create_subject_predicate
=
has_person
&
has_global_perm
(
"
cursus.add_subject
"
)
...
...
@@ -38,12 +36,15 @@ view_courses_predicate = has_person & (
)
add_perm
(
"
cursus.view_courses_rule
"
,
view_courses_predicate
)
view_course_predicate
=
has_person
&
(
view_course_predicate
=
has_person
add_perm
(
"
cursus.view_course_rule
"
,
view_course_predicate
)
view_course_details_predicate
=
has_person
&
(
is_course_teacher
|
has_global_perm
(
"
cursus.view_course
"
)
|
has_object_perm
(
"
cursus.view_course
"
)
)
add_perm
(
"
cursus.view_course_rule
"
,
view_course_predicate
)
add_perm
(
"
cursus.view_course_
details_
rule
"
,
view_course_
details_
predicate
)
create_course_predicate
=
has_person
&
has_global_perm
(
"
cursus.add_course
"
)
add_perm
(
"
cursus.create_course_rule
"
,
create_course_predicate
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/cursus/schema.py
+
6
−
8
View file @
508b0d23
...
...
@@ -56,12 +56,9 @@ class SubjectType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectType):
@classmethod
def
get_queryset
(
cls
,
queryset
,
info
):
# FIXME: Permissions... this is just a workaround,
# because cursus.view_subject would have to be assigned manually
if
not
has_person
(
info
.
context
.
user
):
if
not
info
.
context
.
user
.
has_perm
(
"
cursus.view_subject_rule
"
):
raise
PermissionDenied
()
return
queryset
# return get_objects_for_user(info.context.user, "cursus.view_subject", Subject)
@staticmethod
def
resolve_courses
(
root
,
info
,
**
kwargs
):
...
...
@@ -132,6 +129,8 @@ class CourseType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectType):
@staticmethod
def
resolve_teachers
(
root
,
info
,
**
kwargs
):
if
not
info
.
context
.
user
.
has_perm
(
"
cursus.view_course_details_rule
"
,
root
):
raise
PermissionDenied
()
teachers
=
get_objects_for_user
(
info
.
context
.
user
,
"
core.view_person
"
,
root
.
teachers
.
all
())
# Fixme: this following code was copied from aleksis/core/schema/group.py so it should work
...
...
@@ -144,6 +143,8 @@ class CourseType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectType):
@staticmethod
def
resolve_groups
(
root
,
info
,
**
kwargs
):
if
not
info
.
context
.
user
.
has_perm
(
"
cursus.view_course_details_rule
"
,
root
):
raise
PermissionDenied
()
by_permission
=
get_objects_for_user
(
info
.
context
.
user
,
"
core.view_group
"
,
root
.
groups
.
all
()
)
...
...
@@ -156,12 +157,9 @@ class CourseType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectType):
@classmethod
def
get_queryset
(
cls
,
queryset
,
info
):
# FIXME: Permissions... this is just a workaround,
# because cursus.view_course would have to be assigned manually
if
not
has_person
(
info
.
context
.
user
):
if
not
info
.
context
.
user
.
has_perm
(
"
cursus.view_course_rule
"
):
raise
PermissionDenied
()
return
queryset
# return get_objects_for_user(info.context.user, "cursus.view_course", Course)
class
CourseBatchCreateMutation
(
DjangoBatchCreateMutation
):
...
...
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