mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 00:43:46 +00:00
Acl pour search.
This commit is contained in:
parent
c4e3888e7e
commit
a69ca9ff06
2 changed files with 10 additions and 12 deletions
|
@ -35,5 +35,4 @@ def can_view(user):
|
||||||
A couple (allowed, msg) where allowed is a boolean which is True if
|
A couple (allowed, msg) where allowed is a boolean which is True if
|
||||||
viewing is granted and msg is a message (can be None).
|
viewing is granted and msg is a message (can be None).
|
||||||
"""
|
"""
|
||||||
can = user.has_perms(('cableur',))
|
return True, None
|
||||||
return can, None if can else "Vous ne pouvez pas voir cette application."
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ def finish_results(results, col, order):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def search_single_word(word, filters, is_cableur, user_id,
|
def search_single_word(word, filters, user,
|
||||||
start, end, user_state, aff):
|
start, end, user_state, aff):
|
||||||
""" Construct the correct filters to match differents fields of some models
|
""" Construct the correct filters to match differents fields of some models
|
||||||
with the given query according to the given filters.
|
with the given query according to the given filters.
|
||||||
|
@ -144,8 +144,8 @@ def search_single_word(word, filters, is_cableur, user_id,
|
||||||
adherent__room__name__icontains=word
|
adherent__room__name__icontains=word
|
||||||
)
|
)
|
||||||
) & Q(state__in=user_state)
|
) & Q(state__in=user_state)
|
||||||
if not is_cableur:
|
if not User.can_view_all(user)[0]:
|
||||||
filter_users &= Q(id=user_id)
|
filter_users &= Q(id=user.id)
|
||||||
filters['users'] |= filter_users
|
filters['users'] |= filter_users
|
||||||
|
|
||||||
# Machines
|
# Machines
|
||||||
|
@ -167,8 +167,8 @@ def search_single_word(word, filters, is_cableur, user_id,
|
||||||
) | Q(
|
) | Q(
|
||||||
interface__ipv4__ipv4__icontains=word
|
interface__ipv4__ipv4__icontains=word
|
||||||
)
|
)
|
||||||
if not is_cableur:
|
if not Machine.can_view_all(user)[0]:
|
||||||
filter_machines &= Q(user__id=user_id)
|
filter_machines &= Q(user__id=user.id)
|
||||||
filters['machines'] |= filter_machines
|
filters['machines'] |= filter_machines
|
||||||
|
|
||||||
# Factures
|
# Factures
|
||||||
|
@ -243,7 +243,7 @@ def search_single_word(word, filters, is_cableur, user_id,
|
||||||
filters['whitelists'] |= filter_whitelists
|
filters['whitelists'] |= filter_whitelists
|
||||||
|
|
||||||
# Rooms
|
# Rooms
|
||||||
if '5' in aff and is_cableur:
|
if '5' in aff and Room.can_view_all(user):
|
||||||
filter_rooms = Q(
|
filter_rooms = Q(
|
||||||
details__icontains=word
|
details__icontains=word
|
||||||
) | Q(
|
) | Q(
|
||||||
|
@ -254,7 +254,7 @@ def search_single_word(word, filters, is_cableur, user_id,
|
||||||
filters['rooms'] |= filter_rooms
|
filters['rooms'] |= filter_rooms
|
||||||
|
|
||||||
# Switch ports
|
# Switch ports
|
||||||
if '6' in aff and is_cableur:
|
if '6' in aff and User.can_view_all(user):
|
||||||
filter_ports = Q(
|
filter_ports = Q(
|
||||||
room__name__icontains=word
|
room__name__icontains=word
|
||||||
) | Q(
|
) | Q(
|
||||||
|
@ -275,7 +275,7 @@ def search_single_word(word, filters, is_cableur, user_id,
|
||||||
filters['ports'] |= filter_ports
|
filters['ports'] |= filter_ports
|
||||||
|
|
||||||
# Switches
|
# Switches
|
||||||
if '7' in aff and is_cableur:
|
if '7' in aff and Switch.can_view_all(user):
|
||||||
filter_switches = Q(
|
filter_switches = Q(
|
||||||
switch_interface__domain__name__icontains=word
|
switch_interface__domain__name__icontains=word
|
||||||
) | Q(
|
) | Q(
|
||||||
|
@ -374,8 +374,7 @@ def get_results(query, request, params):
|
||||||
filters = search_single_word(
|
filters = search_single_word(
|
||||||
word,
|
word,
|
||||||
filters,
|
filters,
|
||||||
request.user.has_perms(('cableur',)),
|
request.user,
|
||||||
request.user.id,
|
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
user_state,
|
user_state,
|
||||||
|
|
Loading…
Reference in a new issue