refac: db group

This commit is contained in:
Timothy Jaeryang Baek
2025-11-28 22:48:58 -05:00
parent a7c7993bbf
commit c1d760692f
5 changed files with 109 additions and 40 deletions

View File

@@ -32,31 +32,17 @@ router = APIRouter()
@router.get("/", response_model=list[GroupResponse])
async def get_groups(share: Optional[bool] = None, user=Depends(get_verified_user)):
if user.role == "admin":
groups = Groups.get_groups()
else:
groups = Groups.get_groups_by_member_id(user.id)
group_list = []
filter = {}
if user.role != "admin":
filter["member_id"] = user.id
for group in groups:
if share is not None:
# Check if the group has data and a config with share key
if (
group.data
and "share" in group.data.get("config", {})
and group.data["config"]["share"] != share
):
continue
if share is not None:
filter["share"] = share
group_list.append(
GroupResponse(
**group.model_dump(),
member_count=Groups.get_group_member_count_by_id(group.id),
)
)
groups = Groups.get_groups(filter=filter)
return group_list
return groups
############################

View File

@@ -719,7 +719,7 @@ async def get_groups(
):
"""List SCIM Groups"""
# Get all groups
groups_list = Groups.get_groups()
groups_list = Groups.get_all_groups()
# Apply pagination
total = len(groups_list)