Skip to content

Invitations: Paginer la page des collaborateurs d’une structure [GEN-2309] - #6521

Merged
tonial merged 7 commits into
masterfrom
alaurent/paginate_colleagues
Jul 18, 2025
Merged

tonial merged 7 commits into
masterfrom
alaurent/paginate_colleagues

Conversation

@tonial

@tonial tonial commented Jul 12, 2025 •

Copy link
Copy Markdown
Contributor

🤔 Pourquoi ?

Pour éviter d'avoir trop de membres et générer des requêtes trop lourdes
précédé de #6523

Cette PR est suivie pas une autre pour reprendre les vues invite_* pour être DRY et limiter les invitations en cours -> #6535

🍰 Comment ?

Décrivez en quelques mots la solution retenue et mise en oeuvre, les difficultés ou problèmes rencontrés. Attirez l'attention sur les décisions d'architecture ou de conception importantes.

🚨 À vérifier

  • Mettre à jour le CHANGELOG_breaking_changes.md ?
  • Ajouter l'étiquette « Bug » ?

🏝️ Comment tester ?

Les instructions pour reproduire le problème, les profils de test, le parcours spécifique à utiliser, etc. Si vous disposez d'une recette jetable, mettre l'URL pour tester dans cette partie.

💻 Captures d'écran

@tonial
tonial requested a review from francoisfreitag July 12, 2025 09:22
@tonial tonial self-assigned this Jul 12, 2025
@tonial tonial added the no-changelog Ne doit pas figurer dans le journal des changements. label Jul 12, 2025
@notion-workspace

Copy link
Copy Markdown

@tonial
tonial force-pushed the alaurent/paginate_colleagues branch 3 times, most recently from abac1f0 to b7ad910 Compare July 14, 2025 06:52
@tonial
tonial changed the base branch from master to alaurent/refactor_invitations July 14, 2025 06:53
@tonial
tonial requested a review from rsebille July 14, 2025 06:54
@tonial
tonial force-pushed the alaurent/refactor_invitations branch from e1d6874 to ff6e918 Compare July 14, 2025 19:42
@tonial
tonial force-pushed the alaurent/paginate_colleagues branch from b7ad910 to 18e2fbb Compare July 14, 2025 19:42
@tonial tonial added modifié Modifié dans le changelog. and removed no-changelog Ne doit pas figurer dans le journal des changements. labels Jul 15, 2025
@tonial tonial changed the title Tech: Paginer la page des collaborateurs d’une structure [GEN-2309] Invitations: Paginer la page des collaborateurs d’une structure [GEN-2309] Jul 15, 2025
@tonial tonial added the 1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC label Jul 15, 2025
@github-actions

Copy link
Copy Markdown

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@tonial
tonial force-pushed the alaurent/paginate_colleagues branch from 18e2fbb to 354b8ba Compare July 15, 2025 14:08
@tonial
tonial force-pushed the alaurent/refactor_invitations branch from ff6e918 to 5ea2520 Compare July 15, 2025 14:08
Base automatically changed from alaurent/refactor_invitations to master July 15, 2025 14:29
@tonial
tonial force-pushed the alaurent/paginate_colleagues branch 2 times, most recently from 75930a8 to b9a7081 Compare July 16, 2025 05:18
Comment thread itou/common_apps/organizations/views.py Outdated
Comment thread itou/www/companies_views/views.py Outdated
Comment on lines +732 to +740
self.organization = get_current_company_or_404(request)
if not self.organization.is_active:
raise PermissionDenied

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Le boulot est déjà globalement fait par le middleware :

Suggested change
self.organization = get_current_company_or_404(request)
if not self.organization.is_active:
raise PermissionDenied
self.organization = request.current_organization

Ce qui devrais même permettre de le monter dans BaseMemberList.

Et il restera plus qu'à ajouter un UserPassesTestMixin() pour s'assurer du type :).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ajouté dans un commit


class BaseMemberList(ListView):
def get_queryset(self):
memberships = getattr(self.organization, self.membership_related_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

C'est un tout autre sujet mais ça pourrais valoir le coup de normaliser le related_name à l'occasion, ça irais dans la continuité du choix d'"organisation" comme nom commun à toutes les structures.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

C'est vrai qu'on pourrait avoir
company.memberships
organization.memberships
institution.memberships

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Je viens de découvrir qu'on a une property membership qui le fait :)
(mais je vais plutôt aller changer le related name à la place)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🎁 #6559

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avec cette généralisation il me semble que context_object_name n'est plus utile maintenant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

En effet, il fallait juste corriger le organization.is_authorized (que j'ai remplacé par requets.from_authorized_prescriber dans un autre commit)

Comment thread tests/www/companies_views/test_members_views.py Outdated
</tbody>
</table>
</div>
{% include "includes/pagination.html" with page=page_obj %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avec cet ajout je me serais attendu à voir un snapshot bougé aussi 🤔.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

La pagination n'est affichée que s'il y a plus d'une page, on n'a pas de snapshot pour ce cas (j'ai préféré juste regarder s'il y avait le lien vers la page 1)

Comment thread itou/www/invitations_views/views.py Outdated
Comment thread itou/www/invitations_views/views.py Outdated
Comment on lines +156 to +159
max_invitation = MAX_ACTIVE_INVITATION - organization.invitations.pending().count()
if max_invitation < 1:
messages.error(request, f"Vous ne pouvez avoir plus de {MAX_ACTIVE_INVITATION} invitations.")
return HttpResponseRedirect(back_url)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plutôt que max_invitation je propose invitation_left pour ne pas donner l'impression d'une valeur absolue et découpler de la constante.

D'ailleurs j'ai l'impression que cette logique pourrais être mise en commun pour tout les types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pour le second point, c'est fait dans la PR suivante ou je refonds les 3 vues
J'aurais pu refondre avant d'ajouter les limites mais je me suis dit que c'était pas trop grave de le faire après, et ça limitait la taille de cette PR.

Comment thread tests/www/institutions_views/test_views.py Outdated
Comment thread tests/www/invitations_views/test_companies.py Outdated

@tonial tonial left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

J'ai pris en compte tous les commentaires.
J'ai décidé de sortir la partie limitation des invitations dans la PR qui suit (vu que j'y re-ecrit les vues d'invitations).
COmme ça on n'a plus que la pagination ici !


class BaseMemberList(ListView):
def get_queryset(self):
memberships = getattr(self.organization, self.membership_related_name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

C'est vrai qu'on pourrait avoir
company.memberships
organization.memberships
institution.memberships

</tbody>
</table>
</div>
{% include "includes/pagination.html" with page=page_obj %}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

La pagination n'est affichée que s'il y a plus d'une page, on n'a pas de snapshot pour ce cas (j'ai préféré juste regarder s'il y avait le lien vers la page 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

En effet, il fallait juste corriger le organization.is_authorized (que j'ai remplacé par requets.from_authorized_prescriber dans un autre commit)

Comment thread itou/www/companies_views/views.py Outdated
Comment on lines +732 to +740
self.organization = get_current_company_or_404(request)
if not self.organization.is_active:
raise PermissionDenied

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ajouté dans un commit

Comment thread itou/www/invitations_views/views.py Outdated
Comment on lines +156 to +159
max_invitation = MAX_ACTIVE_INVITATION - organization.invitations.pending().count()
if max_invitation < 1:
messages.error(request, f"Vous ne pouvez avoir plus de {MAX_ACTIVE_INVITATION} invitations.")
return HttpResponseRedirect(back_url)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pour le second point, c'est fait dans la PR suivante ou je refonds les 3 vues
J'aurais pu refondre avant d'ajouter les limites mais je me suis dit que c'était pas trop grave de le faire après, et ça limitait la taille de cette PR.

@tonial
tonial force-pushed the alaurent/paginate_colleagues branch from b9a7081 to 57aca5c Compare July 17, 2025 14:14
Comment thread itou/common_apps/organizations/views.py Outdated
Comment thread itou/www/prescribers_views/views.py
@tonial
tonial force-pushed the alaurent/paginate_colleagues branch from 57aca5c to bbad355 Compare July 17, 2025 15:47
@tonial
tonial requested review from rsebille and xavfernandez July 17, 2025 15:50

@xavfernandez xavfernandez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Jolie mise en commun 👍

@tonial
tonial added this pull request to the merge queue Jul 18, 2025
@tonial
tonial removed this pull request from the merge queue due to a manual request Jul 18, 2025
@tonial
tonial added this pull request to the merge queue Jul 18, 2025
Merged via the queue into master with commit 5313afb Jul 18, 2025
@tonial
tonial deleted the alaurent/paginate_colleagues branch July 18, 2025 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1-recette-jetable [Payé à l’heure] Crée une recette jetable sur CC modifié Modifié dans le changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants