Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
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
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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-Core
Commits
08f433e4
Unverified
Commit
08f433e4
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
In requests, automatically limit objects to current school.
Advances
#19
.
parent
ce20715c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
biscuit/core/mixins.py
+21
-0
21 additions, 0 deletions
biscuit/core/mixins.py
biscuit/core/settings.py
+2
-0
2 additions, 0 deletions
biscuit/core/settings.py
biscuit/core/util/core_helpers.py
+14
-0
14 additions, 0 deletions
biscuit/core/util/core_helpers.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
38 additions
and
0 deletions
biscuit/core/mixins.py
+
21
−
0
View file @
08f433e4
from
django.db
import
models
from
.util.core_helpers
import
get_current_school
class
SchoolRelatedManager
(
models
.
Manager
):
def
get_queryset
(
self
):
qs
=
super
().
get_queryset
()
school
=
get_current_school
()
if
school
:
return
qs
.
filter
(
school
=
school
)
else
:
return
qs
.
none
()
def
create
(
self
,
*
args
,
**
kwargs
):
if
'
school
'
not
in
kwargs
:
kwargs
[
'
school
'
]
=
get_current_school
()
return
super
().
create
(
*
args
,
**
kwargs
)
class
SchoolRelated
(
models
.
Model
):
class
Meta
:
abstract
=
True
objects
=
SchoolRelatedManager
()
school
=
models
.
ForeignKey
(
'
core.School
'
,
on_delete
=
models
.
CASCADE
)
This diff is collapsed.
Click to expand it.
biscuit/core/settings.py
+
2
−
0
View file @
08f433e4
...
...
@@ -25,6 +25,7 @@ INSTALLED_APPS = [
'
django.contrib.sessions
'
,
'
django.contrib.messages
'
,
'
django.contrib.staticfiles
'
,
'
django_global_request
'
,
'
easyaudit
'
,
'
bootstrap4
'
,
'
fa
'
,
...
...
@@ -40,6 +41,7 @@ INSTALLED_APPS += get_app_packages()
MIDDLEWARE
=
[
'
django.middleware.security.SecurityMiddleware
'
,
'
django.contrib.sessions.middleware.SessionMiddleware
'
,
'
django_global_request.middleware.GlobalRequestMiddleware
'
,
'
django.middleware.common.CommonMiddleware
'
,
'
django.middleware.csrf.CsrfViewMiddleware
'
,
'
django.contrib.auth.middleware.AuthenticationMiddleware
'
,
...
...
This diff is collapsed.
Click to expand it.
biscuit/core/util/core_helpers.py
+
14
−
0
View file @
08f433e4
...
...
@@ -2,6 +2,8 @@ from importlib import import_module
import
pkgutil
from
typing
import
Sequence
from
django_global_request.middleware
import
get_request
def
get_app_packages
()
->
Sequence
:
"""
Find all packages within the biscuit.apps namespace.
"""
...
...
@@ -25,3 +27,15 @@ def get_app_packages() -> Sequence:
pkgs
.
append
(
'
biscuit.apps.%s
'
%
pkg
[
1
])
return
pkgs
def
get_current_school
():
request
=
get_request
()
if
request
:
if
request
.
user
.
person
:
return
request
.
user
.
person
.
school
else
:
return
None
else
:
return
None
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
08f433e4
...
...
@@ -24,6 +24,7 @@ setup(
'
django-fa
'
,
'
django-easy-audit
'
,
'
django-local-settings
'
,
'
django-middleware-global-request
'
,
'
django-phonenumber-field[phonenumbers]
'
,
'
django-simple-menu
'
,
'
django-tables2
'
,
...
...
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