Novo Ambiente| Atualização 2
This commit is contained in:
parent
d2c8745c45
commit
68972edc7d
Binary file not shown.
Binary file not shown.
|
|
@ -133,7 +133,9 @@ def login():
|
|||
|
||||
conn.unbind()
|
||||
logging.info(f"Login bem-sucedido para usuário: {username_full}")
|
||||
return jsonify({'msg': 'Login bem-sucedido', 'token': token}), 200
|
||||
# No final da função login, após gerar o token
|
||||
return jsonify({'msg': 'Login bem-sucedido', 'token': token, 'domain': domain}), 200
|
||||
|
||||
else:
|
||||
conn.unbind()
|
||||
logging.warning(f"Falha na autenticação LDAP para o usuário: {username_full}")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from flask import Blueprint, jsonify, request
|
||||
import requests
|
||||
from .auth import token_required
|
||||
|
||||
# Blueprint para rotas relacionadas ao Zammad
|
||||
zammad = Blueprint('zammad', __name__)
|
||||
|
|
@ -10,7 +11,13 @@ zammad_token = "kT0IXO8aVhPoTLcMRNL290rqd9jbRhhM0zf8MgBo3n00NLChToSU6rOGnMgWA0M2
|
|||
|
||||
# Rota para listar tickets
|
||||
@zammad.route('/tickets', methods=['GET'])
|
||||
@token_required
|
||||
def listar_tickets():
|
||||
domain = request.args.get('domain')
|
||||
|
||||
if not domain:
|
||||
return jsonify({"error": "Domínio não fornecido"}), 400
|
||||
|
||||
try:
|
||||
# Cabeçalho de autenticação para a API Zammad
|
||||
headers = {
|
||||
|
|
@ -19,16 +26,32 @@ def listar_tickets():
|
|||
}
|
||||
|
||||
# Faz a requisição para a API Zammad
|
||||
url = f"{base_url}/tickets"
|
||||
url = f"{base_url}/tickets?domain={domain}" # Construindo a URL com o parâmetro 'domain'
|
||||
|
||||
response = requests.get(url, headers=headers, timeout=10) # Timeout adicionado para evitar requisições travadas
|
||||
|
||||
# Processa a resposta
|
||||
if response.status_code == 200:
|
||||
tickets = response.json()
|
||||
return jsonify(tickets), 200
|
||||
tickets_filtrados =[
|
||||
{
|
||||
"title": ticket.get("title"),
|
||||
"type": ticket.get("type"),
|
||||
"created_at": ticket.get("created_at"),
|
||||
"close_at": ticket.get("close_at"),
|
||||
"state_id": ticket.get("state_id"),
|
||||
"pending_time": ticket.get("pending_time"),
|
||||
"number": ticket.get("number"),
|
||||
"organization_id": ticket.get("organization_id"),
|
||||
"customer_id": ticket.get("customer_id"),
|
||||
}
|
||||
for ticket in tickets
|
||||
]
|
||||
|
||||
return jsonify(tickets_filtrados), 200
|
||||
else:
|
||||
return jsonify({
|
||||
"error": f"Erro ao buscar tickets: {response.status_code}",
|
||||
"error": f"Erro ao buscar tickets: {response.status_code}",
|
||||
"details": response.text
|
||||
}), response.status_code
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue