Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDE
nk20
Commits
e2d2d2cc
Commit
e2d2d2cc
authored
5 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
Anonymous users have no right
parent
d494a3e7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!10
Système de droits
Pipeline
#7979
passed with stages
in 4 minutes and 22 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/permission/backends.py
+10
-3
10 additions, 3 deletions
apps/permission/backends.py
with
10 additions
and
3 deletions
apps/permission/backends.py
+
10
−
3
View file @
e2d2d2cc
...
...
@@ -2,15 +2,15 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from
django.contrib.auth.backends
import
ModelBackend
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
,
AnonymousUser
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models
import
Q
,
F
from
note.models
import
Note
,
NoteUser
,
NoteClub
,
NoteSpecial
from
note_kfet.middlewares
import
get_current_session
from
permission.models
import
Permission
from
member.models
import
Membership
,
Club
from
.models
import
Permission
class
PermissionBackend
(
ModelBackend
):
"""
...
...
@@ -66,6 +66,10 @@ class PermissionBackend(ModelBackend):
:return: A query that corresponds to the filter to give to a queryset
"""
if
user
is
None
or
isinstance
(
user
,
AnonymousUser
):
# Anonymous users can't do anything
return
Q
(
pk
=-
1
)
if
user
.
is_superuser
and
get_current_session
().
get
(
"
permission_mask
"
,
0
)
>=
42
:
# Superusers have all rights
return
Q
()
...
...
@@ -86,6 +90,9 @@ class PermissionBackend(ModelBackend):
return
query
def
has_perm
(
self
,
user_obj
,
perm
,
obj
=
None
):
if
user_obj
is
None
or
isinstance
(
user_obj
,
AnonymousUser
):
return
False
if
user_obj
.
is_superuser
and
get_current_session
().
get
(
"
permission_mask
"
,
0
)
>=
42
:
return
True
...
...
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