Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/apps/account/migrations/0028_alter_account_uuid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 4.2.10 on 2026-02-12 15:03

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("account", "0027_rename_has_access_to_chatbot_account_has_chatbot_access"),
]

operations = [
migrations.AlterField(
model_name="account",
name="uuid",
field=models.UUIDField(default=uuid.uuid4, unique=True),
),
]
2 changes: 1 addition & 1 deletion backend/apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Account(BaseModel, AbstractBaseUser, PermissionsMixin):
(COLABORADOR, "Colaborador"),
)

uuid = models.UUIDField(primary_key=False, default=uuid4)
uuid = models.UUIDField(primary_key=False, default=uuid4, unique=True)

email = models.EmailField("Email", unique=True)
gcp_email = models.EmailField("GCP email", null=True, blank=True) # Google Cloud Platform email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Querys(Enum):
where: {
flow_id: { _eq: $flow_id }
state: { _in: ["Success", "Failed"] }
start_time: { _is_null: false }
}
order_by: { start_time: desc }
limit: 2
Expand Down
17 changes: 17 additions & 0 deletions backend/custom/graphql_jwt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from functools import wraps
from re import findall
from typing import Any

from django.db.models import Q
from graphene import Field, ObjectType, String
Expand All @@ -9,6 +10,22 @@
from graphql_jwt.decorators import context
from graphql_jwt.relay import JSONWebTokenMutation
from graphql_jwt.settings import jwt_settings
from graphql_jwt.utils import jwt_payload


def jwt_payload_with_uuid(user, context=None) -> dict[str, Any]:
"""Custom JWT payload handler that adds the user's UUID to the token payload.

Args:
user (Account): An instance of backend.apps.account.models.Account
context (Any, optional): Django request context. Defaults to None.

Returns:
dict[str, Any]: JWT token payload with the user's UUID included.
"""
payload = jwt_payload(user, context)
payload["uuid"] = str(user.uuid)
return payload


class User(ObjectType):
Expand Down
1 change: 1 addition & 0 deletions backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"JWT_EXPIRATION_DELTA": timedelta(days=7),
"JWT_REFRESH_EXPIRATION_DELTA": timedelta(days=14),
"JWT_ALLOW_ANY_HANDLER": "backend.custom.graphql_jwt.allow_any",
"JWT_PAYLOAD_HANDLER": "backend.custom.graphql_jwt.jwt_payload_with_uuid",
}

# Translations
Expand Down
Loading