-
Notifications
You must be signed in to change notification settings - Fork 25
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
Réusinage de la désactivation d’un membre d’une organisation #5510
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ def has_member(self, user): | |
def has_admin(self, user): | ||
return self.active_admin_members.filter(pk=user.pk).exists() | ||
|
||
def add_or_activate_member(self, user): | ||
def add_or_activate_membership(self, user): | ||
"""Add user to organization members, or activate membership if already there""" | ||
|
||
updated = self.memberships.filter(user=user).update(is_active=True) | ||
|
@@ -83,6 +83,25 @@ def add_or_activate_member(self, user): | |
is_admin = not self.members.exists() | ||
self.memberships.create(user=user, is_admin=is_admin) | ||
|
||
def deactivate_membership(self, membership, *, updated_by): | ||
""" | ||
Deleting the membership was a possibility but we would have lost | ||
the member activity history. We need it to show to other members | ||
which job applications this user was managing before leaving the organization. | ||
""" | ||
membership_organization_id = getattr(membership, f"{self.members.source_field_name}_id") | ||
if membership_organization_id != self.pk: | ||
raise ValueError( | ||
f"Cannot deactivate users from other organizations. {membership_organization_id=} {self.pk=}." | ||
) | ||
membership.is_active = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je verrais bien un There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bonne remarque, mieux vaut être ceinture bretelles, comme on accepte le membership en paramètre, on devrait vérifier qu’il s’agit de la bonne organisation 👍 |
||
# If this member is invited again, he should no still be an administrator. | ||
# Remove admin rights as a precaution. | ||
membership.is_admin = False | ||
membership.updated_by = updated_by | ||
membership.save(update_fields=["is_active", "is_admin", "updated_by"]) | ||
self.member_deactivation_email(membership.user).send() | ||
|
||
@property | ||
def active_members(self): | ||
memberships = self.memberships.active() | ||
|
@@ -238,19 +257,6 @@ class Meta: | |
class Meta: | ||
abstract = True | ||
|
||
def deactivate_membership_by_user(self, updated_by): | ||
""" | ||
Deleting the membership was a possibility but we would have lost | ||
the member activity history. We need it to show to other members | ||
which job applications this user was managing before leaving the organization. | ||
""" | ||
self.is_active = False | ||
# If this member is invited again, he should no still be an administrator. | ||
# Remove admin rights as a precaution. | ||
self.is_admin = False | ||
self.updated_by = updated_by | ||
return True | ||
|
||
def set_admin_role(self, is_admin, updated_by): | ||
self.is_admin = is_admin | ||
self.updated_by = updated_by | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ def test_send_invitation(self): | |
|
||
|
||
class TestPrescriberWithOrgInvitation: | ||
def test_add_or_activate_member_to_organization(self): | ||
def test_add_or_activate_membership_to_organization(self): | ||
invitation = PrescriberWithOrgSentInvitationFactory(email="[email protected]") | ||
PrescriberFactory(email=invitation.email) | ||
org_members = invitation.organization.members.count() | ||
|
@@ -154,7 +154,7 @@ def test_email_invitation(self): | |
|
||
|
||
class TestCompanyInvitation: | ||
def test_add_or_activate_member_to_company(self): | ||
def test_add_or_activate_membership_to_company(self): | ||
invitation = EmployerInvitationFactory(email="[email protected]") | ||
EmployerFactory(email=invitation.email) | ||
employers = invitation.company.members.count() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -645,7 +645,7 @@ def test_callback_ft_users_unknown_safir_already_in_org(self, client, pro_connec | |
**dataclasses.asdict(ProConnectPrescriberData.from_user_info(pro_connect.oidc_userinfo)) | ||
) | ||
org = PrescriberPoleEmploiFactory(code_safir_pole_emploi="00000") | ||
org.add_or_activate_member(user) | ||
org.add_or_activate_membership(user) | ||
|
||
oidc_userinfo = pro_connect.oidc_userinfo_with_safir.copy() | ||
oidc_userinfo["email"] = "[email protected]" | ||
|
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.
Je brancherais bien aussi l'admin sur cette méthode en remplaçant les case "delete" par un "désactiver" :)
(mais je peux le faire moi dans une prochaine PR à la limite)
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.
Je vais faire, on a déjà prévu ce branchement pour #5430.