feat: logout | testes permissoes | redirecionamento com base no gupo do usuario

This commit is contained in:
2025-01-14 16:53:07 -03:00
parent 9b4e1cfca4
commit b06e1d22e3
10 changed files with 28 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
{% extends "base.html" %}
{% load static %}
{% load custom_filter_tag %}
{% block 'title' %}
@@ -41,12 +43,13 @@ Detalhes {{comanda.name}}
{% endif %}
<button class="button" id="imprimirFichas"
{% if comanda.status != 'OPEN'%}
<button class="button" id="imprimirFichas"
style="display: none;"
{% endif %}
onclick="imprimirFichas()">Fichas</button>
{% endif %}
{% if user|groupUser:"Gerente" %}
<button class="button" id="imprimirFichas" hx-get="{% url 'reopenComanda' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="reloadPage()"
{% if comanda.status == 'OPEN'%}
style="display: none;"
@@ -55,6 +58,8 @@ Detalhes {{comanda.name}}
{% endif %}
>Reabrir</button>
{% endif %}
</div>
<div>

View File

@@ -13,3 +13,8 @@ def filter_total(value):
for produto in consumo:
total += produto.product.price
return f'R$ {total}'
@register.filter(name='groupUser')
def has_group(user, group_name):
return user.groups.filter(name=group_name).exists()

Binary file not shown.

View File

@@ -3,6 +3,7 @@
{% block 'head' %}
<link rel="stylesheet" href="{% static 'home/css/home.css' %}">

View File

@@ -26,7 +26,7 @@ def home(request):
@group_required(groupName='Gerente')
def chartCuisine(request):
print(request.user.id)
print(request.user.groups.all())
print(request.user.is_authenticated)
# fulano = User()
tFila = []

View File

@@ -1,5 +1,6 @@
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.forms import AuthenticationForm
@@ -17,7 +18,10 @@ def login_view(request):
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
if request.user.groups.filter(name='Admin').exists() or request.user.groups.filter(name='Gerente').exists() :
return redirect('home')
else:
return redirect('comandas')
else:
pass
# Mensagem de erro: Credenciais inválidas

View File

@@ -1,4 +1,6 @@
{% load static %}
{% load custom_filter_tag %}
<!DOCTYPE html>
@@ -21,14 +23,15 @@
<nav class="nav-bar">
<div class="logo">
<h1>
<!-- RRBEC -->
<img src="{% static 'midia/logo.png' %}" width="60">
</h1>
</div>
<div class="nav-list">
<ul>
{% if user|groupUser:"Gerente" %}
<li class="nav-item"><a href="{% url 'home' %}" class="nav-link">Início</a></li>
{% endif %}
<li class="nav-item"><a href="{% url 'comandas' %}" class="nav-link">Comandas</a></li>
<li class="nav-item"><a href="{% url 'pedidos' %}" class="nav-link">Cozinha</a></li>
<li class="nav-item"><a href="{% url 'viewBalcao' %}" class="nav-link">Balcão</a></li>
@@ -59,7 +62,9 @@
</nav>
<div class="mobile-menu">
<ul>
{% if user|groupUser:"Gerente" %}
<li class="nav-item"><a href="{% url 'home' %}" class="nav-link">Início</a></li>
{% endif %}
<li class="nav-item"><a href="{% url 'comandas' %}" class="nav-link">Comandas</a></li>
<li class="nav-item"><a href="{% url 'pedidos' %}" class="nav-link">Cozinha</a></li>
<li class="nav-item"><a href="{% url 'mapMesas' %}" class="nav-link">Mapa</a></li>