1
0
Fork 0
forked from sr2/cloud-api

feat: condensed user get endpoints

The process also added improved ORM relationships for multiple models.
This commit is contained in:
Chris Milne 2026-05-25 12:06:24 +01:00
parent 4ff184fe86
commit a80767d870
5 changed files with 39 additions and 65 deletions

View file

@ -4,10 +4,13 @@ Database models for user module
Models:
- User - id[pk], email, first_name, last_name, oidc_id
"""
from collections import defaultdict
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship
from src.database import Base
from src.iam.models import Group
class User(Base):
@ -19,8 +22,25 @@ class User(Base):
last_name = Column(String)
oidc_id = Column(String, index=True, unique=True)
organisations = relationship(
organisation_rel = relationship(
"Organisation",
secondary="orgusers",
back_populates="users"
back_populates="user_rel"
)
@property
def organisations(self):
return [org.name for org in self.organisation_rel]
group_rel = relationship(
"Group",
secondary="user_groups",
back_populates="user_rel"
)
@property
def groups(self):
result = defaultdict(list)
for group in self.group_rel:
result[group.org_rel.name].append(group.name)
return dict(result)