Update brain app and add project-specific user roles#2
Conversation
LucaLumetti
left a comment
There was a problem hiding this comment.
Facciamo insieme un check del middleware, il resto direi sia ok
toothfairy/middleware.py
Outdated
| if not hasattr(request, 'user') or not request.user.is_authenticated: | ||
| return None | ||
|
|
||
| # Determine app by first URL segment (fallback to 'maxillo') |
There was a problem hiding this comment.
Questo fallback to maxillo non sono convinto sia giusto. Se non c'è, deve portare alla landing page
toothfairy/middleware.py
Outdated
| pass | ||
| else: | ||
| from maxillo.models import UserProfile | ||
| profile, _ = UserProfile.objects.get_or_create(user=request.user) |
There was a problem hiding this comment.
Questo dovrebbe chiamarsi MaxilloUserProfile
toothfairy/middleware.py
Outdated
| app_key = path_parts[0] if path_parts else 'maxillo' | ||
|
|
||
| try: | ||
| if app_key == 'brain': |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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)
toothfairy/middleware.py
Outdated
| 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'): |
There was a problem hiding this comment.
brain_profile da dove potrebbe arrivare?
toothfairy/middleware.py
Outdated
| 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. |
There was a problem hiding this comment.
In caso di errore -> landing page con user.profile unset (se esiste)
No description provided.