feat: org id in get user/self/db
This commit is contained in:
parent
6aad2e560f
commit
bb4965ab07
2 changed files with 22 additions and 26 deletions
|
|
@ -18,33 +18,29 @@ from src.database import Base
|
|||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "user"
|
||||
__tablename__ = "user"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
email = Column(String)
|
||||
first_name = Column(String)
|
||||
last_name = Column(String)
|
||||
oidc_id = Column(String, index=True, unique=True)
|
||||
id = Column(Integer, primary_key=True)
|
||||
email = Column(String)
|
||||
first_name = Column(String)
|
||||
last_name = Column(String)
|
||||
oidc_id = Column(String, index=True, unique=True)
|
||||
|
||||
organisation_rel = relationship(
|
||||
"Organisation",
|
||||
secondary="orgusers",
|
||||
back_populates="user_rel"
|
||||
)
|
||||
organisation_rel = relationship(
|
||||
"Organisation", secondary="orgusers", back_populates="user_rel"
|
||||
)
|
||||
|
||||
@property
|
||||
def organisations(self):
|
||||
return [org.name for org in self.organisation_rel]
|
||||
@property
|
||||
def organisations(self):
|
||||
return [{"name": org.name, "id": org.id} for org in self.organisation_rel]
|
||||
|
||||
group_rel = relationship(
|
||||
"Group",
|
||||
secondary="user_groups",
|
||||
back_populates="user_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)
|
||||
@property
|
||||
def groups(self):
|
||||
result = defaultdict(list)
|
||||
for group in self.group_rel:
|
||||
result[group.org_rel.name].append(group.name)
|
||||
return dict(result)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class UserResponse(CustomBaseModel):
|
|||
first_name: str
|
||||
last_name: str
|
||||
email: str
|
||||
organisations: list[Optional[str]]
|
||||
organisations: list[Optional[dict[str, str|int]]]
|
||||
groups: Optional[dict[str, list[str]]] = None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue