Commit 47ac0eb3 authored by LEVY-FALK Hugo's avatar LEVY-FALK Hugo Committed by root

Acl pour search.

parent 7de35951
...@@ -35,5 +35,4 @@ def can_view(user): ...@@ -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): ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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): ...@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment