Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nounous
re2o
Commits
b589b59c
Commit
b589b59c
authored
May 27, 2017
by
Gabriel Detraz
Committed by
root
May 28, 2017
Browse files
Propriefie les tests de droits
parent
f7e347f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
re2o/context_processors.py
View file @
b589b59c
...
...
@@ -27,13 +27,18 @@ def context_user(request):
user
=
request
.
user
if
user
.
is_authenticated
():
interfaces
=
user
.
user_interfaces
()
is_cableur
=
user
.
is_cableur
is_bureau
=
user
.
is_bureau
is_bofh
=
user
.
is_bofh
is_trez
=
user
.
is_trez
is_infra
=
user
.
is_infra
else
:
interfaces
=
None
is_cableur
=
user
.
has_perms
((
'cableur'
,))
is_bureau
=
user
.
has_perms
((
'bureau'
,))
is_bofh
=
user
.
has_perms
((
'bofh'
,))
is_trez
=
user
.
has_perms
((
'trésorier'
,))
is_infra
=
user
.
has_perms
((
'infra'
,))
is_cableur
=
False
is_bureau
=
False
is_bofh
=
False
is_trez
=
False
is_infra
=
False
return
{
'request_user'
:
user
,
'is_cableur'
:
is_cableur
,
...
...
users/models.py
View file @
b589b59c
...
...
@@ -216,6 +216,30 @@ class User(AbstractBaseUser):
def
has_perm
(
self
,
perm
,
obj
=
None
):
return
True
def
has_right
(
self
,
right
):
return
Right
.
objects
.
filter
(
user
=
self
).
filter
(
right
=
ListRight
.
objects
.
get
(
listright
=
right
)).
exists
()
@
cached_property
def
is_bureau
(
self
):
return
Right
.
objects
.
filter
(
user
=
self
).
filter
(
right
=
ListRight
.
objects
.
get
(
listright
=
'bureau'
)).
exists
()
@
cached_property
def
is_bofh
(
self
):
return
Right
.
objects
.
filter
(
user
=
self
).
filter
(
right
=
ListRight
.
objects
.
get
(
listright
=
'bofh'
)).
exists
()
@
cached_property
def
is_cableur
(
self
):
return
self
.
has_right
(
'cableur'
)
or
self
.
has_right
(
'bureau'
)
or
self
.
has_right
(
'infra'
)
or
self
.
has_right
(
'bofh'
)
@
cached_property
def
is_trez
(
self
):
return
Right
.
objects
.
filter
(
user
=
self
).
filter
(
right
=
ListRight
.
objects
.
get
(
listright
=
'trésorier'
)).
exists
()
@
cached_property
def
is_infra
(
self
):
return
Right
.
objects
.
filter
(
user
=
self
).
filter
(
right
=
ListRight
.
objects
.
get
(
listright
=
'infra'
)).
exists
()
@
cached_property
def
end_adhesion
(
self
):
date_max
=
Cotisation
.
objects
.
filter
(
vente__in
=
Vente
.
objects
.
filter
(
facture__in
=
Facture
.
objects
.
filter
(
user
=
self
).
exclude
(
valid
=
False
))).
aggregate
(
models
.
Max
(
'date_end'
))[
'date_end__max'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment