fix(user): filter out soft-deleted memberships and organizations
Add get_active_memberships() method to User model that filters out soft-deleted memberships and memberships of deleted organizations. Update all usages of organization_memberships to use this method, ensuring consistent handling of soft-deleted records across the codebase. Also add deleted_at filters to CA queries in SSH helpers.
This commit is contained in:
@@ -116,9 +116,24 @@ class User(BaseModel):
|
||||
is not None
|
||||
)
|
||||
|
||||
def get_active_memberships(self):
|
||||
"""Get active (non-deleted) organization memberships with active organizations.
|
||||
|
||||
Returns:
|
||||
List of OrganizationMember instances where:
|
||||
- membership.deleted_at is None
|
||||
- organization exists and organization.deleted_at is None
|
||||
"""
|
||||
return [
|
||||
m for m in self.organization_memberships
|
||||
if m.deleted_at is None
|
||||
and m.organization
|
||||
and m.organization.deleted_at is None
|
||||
]
|
||||
|
||||
def get_organizations(self):
|
||||
"""Get all organizations the user is a member of."""
|
||||
return [membership.organization for membership in self.organization_memberships]
|
||||
"""Get all active organizations the user is a member of."""
|
||||
return [membership.organization for membership in self.get_active_memberships()]
|
||||
|
||||
def has_totp_enabled(self) -> bool:
|
||||
"""Check if user has TOTP enabled and verified.
|
||||
|
||||
Reference in New Issue
Block a user