-
Notifications
You must be signed in to change notification settings - Fork 0
Update brain app and add project-specific user roles #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
LucaLumetti
left a comment
There was a problem hiding this 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
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.
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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): |
There was a problem hiding this comment.
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)
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.
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?
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.
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)
No description provided.