Skip to content

Conversation

@kev98
Copy link
Collaborator

@kev98 kev98 commented Dec 1, 2025

No description provided.

@LucaLumetti LucaLumetti self-requested a review December 1, 2025 17:26
Copy link
Collaborator

@LucaLumetti LucaLumetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Facciamo insieme un check del middleware, il resto direi sia ok

if not hasattr(request, 'user') or not request.user.is_authenticated:
return None

# Determine app by first URL segment (fallback to 'maxillo')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questo fallback to maxillo non sono convinto sia giusto. Se non c'è, deve portare alla landing page

pass
else:
from maxillo.models import UserProfile
profile, _ = UserProfile.objects.get_or_create(user=request.user)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questo dovrebbe chiamarsi MaxilloUserProfile

app_key = path_parts[0] if path_parts else 'maxillo'

try:
if app_key == 'brain':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qui può essere solo 'brain' o 'maxillo' e la cosa che cambia è solo la classe che viene usata.
farei qualcosa del tipo:
ProjectUserProfile = MaxilloUserProfile if 'maxillo' else BrainUserProfile
ProjectUserProfile.objects.get_or_create...

the default role.
"""

def process_request(self, request):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questo viene chiamato ogni volta che viene caricata una pagina? Si riesce ad evitare?
Se user.profile è settato e la sua classe matcha l'url -> fine, niente .get_or_create(user=request.user)

try:
if app_key == 'brain':
# Prefer an existing related object, create if missing
if hasattr(request.user, 'brain_profile') and getattr(request.user, 'brain_profile'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brain_profile da dove potrebbe arrivare?

request.user.profile = profile
except Exception:
# In case of any DB errors during auth or when running management commands,
# avoid failing the whole request — leave user.profile unset.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In caso di errore -> landing page con user.profile unset (se esiste)

@LucaLumetti LucaLumetti marked this pull request as draft December 3, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants