Skip to content

Commit a7e8654

Browse files
committed
Changed how users are added to organizations, and now shows all other team members in an org.
1 parent d38b9ba commit a7e8654

File tree

12 files changed

+195
-262
lines changed

12 files changed

+195
-262
lines changed

backend/app/api/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919
api_router.include_router(users.router)
2020
api_router.include_router(utils.router)
2121
api_router.include_router(items.router)
22-
api_router.include_router(organizations.router, prefix="/organizations", tags=["organizations"])
22+
api_router.include_router(
23+
organizations.router, prefix="/organizations", tags=["organizations"]
24+
)
2325
api_router.include_router(projects.router, prefix="/projects", tags=["projects"])
24-
api_router.include_router(project_access.router, prefix="/projects", tags=["project-access"])
25-
api_router.include_router(invitations.router, prefix="/invitations", tags=["invitations"])
26+
api_router.include_router(
27+
project_access.router, prefix="/projects", tags=["project-access"]
28+
)
29+
api_router.include_router(
30+
invitations.router, prefix="/invitations", tags=["invitations"]
31+
)
2632
api_router.include_router(galleries.router, prefix="/galleries", tags=["galleries"])
2733

2834

backend/app/api/routes/galleries.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def read_galleries(
4747
raise HTTPException(status_code=403, detail="Not enough permissions")
4848
else:
4949
# Team member must be in same organization
50-
if not current_user.organization_id or project.organization_id != current_user.organization_id:
50+
if (
51+
not current_user.organization_id
52+
or project.organization_id != current_user.organization_id
53+
):
5154
raise HTTPException(status_code=403, detail="Not enough permissions")
5255

5356
galleries = crud.get_galleries_by_project(
@@ -65,14 +68,18 @@ def read_galleries(
6568

6669
# Get galleries for all accessible projects
6770
galleries = []
68-
for pid in project_ids[skip:skip+limit]:
71+
for pid in project_ids[skip : skip + limit]:
6972
project_galleries = crud.get_galleries_by_project(
7073
session=session, project_id=pid, skip=0, limit=100
7174
)
7275
galleries.extend(project_galleries)
7376

7477
count = sum(
75-
len(crud.get_galleries_by_project(session=session, project_id=pid, skip=0, limit=1000))
78+
len(
79+
crud.get_galleries_by_project(
80+
session=session, project_id=pid, skip=0, limit=1000
81+
)
82+
)
7683
for pid in project_ids
7784
)
7885
else:
@@ -147,7 +154,10 @@ def read_gallery(session: SessionDep, current_user: CurrentUser, id: uuid.UUID)
147154
raise HTTPException(status_code=403, detail="Not enough permissions")
148155
else:
149156
# Team member must be in same organization
150-
if not current_user.organization_id or project.organization_id != current_user.organization_id:
157+
if (
158+
not current_user.organization_id
159+
or project.organization_id != current_user.organization_id
160+
):
151161
raise HTTPException(status_code=403, detail="Not enough permissions")
152162

153163
return gallery

backend/app/api/routes/invitations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,3 @@ def delete_invitation(
102102
session.delete(invitation)
103103
session.commit()
104104
return {"message": "Invitation deleted"}
105-

backend/app/api/routes/organizations.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ def read_organization(
6767
raise HTTPException(status_code=404, detail="Organization not found")
6868

6969
# Only allow viewing own organization (unless superuser)
70-
if not current_user.is_superuser and current_user.organization_id != organization_id:
70+
if (
71+
not current_user.is_superuser
72+
and current_user.organization_id != organization_id
73+
):
7174
raise HTTPException(
7275
status_code=403,
7376
detail="Not enough permissions",
@@ -93,7 +96,10 @@ def update_organization(
9396
raise HTTPException(status_code=404, detail="Organization not found")
9497

9598
# Only allow updating own organization (unless superuser)
96-
if not current_user.is_superuser and current_user.organization_id != organization_id:
99+
if (
100+
not current_user.is_superuser
101+
and current_user.organization_id != organization_id
102+
):
97103
raise HTTPException(
98104
status_code=403,
99105
detail="Not enough permissions",
@@ -106,4 +112,3 @@ def update_organization(
106112
session.refresh(organization)
107113

108114
return organization
109-

backend/app/api/routes/project_access.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def grant_project_access(
4545
raise HTTPException(status_code=404, detail="Project not found")
4646

4747
# Check if current user's organization owns the project
48-
if not current_user.organization_id or current_user.organization_id != project.organization_id:
48+
if (
49+
not current_user.organization_id
50+
or current_user.organization_id != project.organization_id
51+
):
4952
raise HTTPException(
5053
status_code=403,
5154
detail="You don't have permission to manage this project",
@@ -128,9 +131,7 @@ def revoke_project_access(
128131
raise HTTPException(status_code=403, detail="Access denied")
129132

130133
# Revoke access
131-
crud.delete_project_access(
132-
session=session, project_id=project_id, user_id=user_id
133-
)
134+
crud.delete_project_access(session=session, project_id=project_id, user_id=user_id)
134135
return Message(message="Access revoked successfully")
135136

136137

@@ -175,4 +176,3 @@ def update_project_access_permissions(
175176
session=session, db_access=db_access, access_in=access_in
176177
)
177178
return access
178-

backend/app/api/routes/users.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,11 @@ def read_clients(
6262
)
6363

6464
count_statement = (
65-
select(func.count())
66-
.select_from(User)
67-
.where(User.user_type == "client")
65+
select(func.count()).select_from(User).where(User.user_type == "client")
6866
)
6967
count = session.exec(count_statement).one()
7068

71-
statement = (
72-
select(User)
73-
.where(User.user_type == "client")
74-
.offset(skip)
75-
.limit(limit)
76-
)
69+
statement = select(User).where(User.user_type == "client").offset(skip).limit(limit)
7770
users = session.exec(statement).all()
7871

7972
return UsersPublic(data=users, count=count)
@@ -207,6 +200,48 @@ def register_user(session: SessionDep, user_in: UserRegister) -> Any:
207200
return user
208201

209202

203+
@router.get("/organization-members", response_model=UsersPublic)
204+
def get_organization_members(
205+
session: SessionDep,
206+
current_user: CurrentUser,
207+
skip: int = 0,
208+
limit: int = 100,
209+
) -> Any:
210+
"""
211+
Get all members of the current user's organization.
212+
Accessible by team members to see their organization members.
213+
"""
214+
if getattr(current_user, "user_type", None) != "team_member":
215+
raise HTTPException(
216+
status_code=403, detail="Only team members can view organization members"
217+
)
218+
219+
if not current_user.organization_id:
220+
raise HTTPException(
221+
status_code=400,
222+
detail="You must be part of an organization to view members",
223+
)
224+
225+
count_statement = (
226+
select(func.count())
227+
.select_from(User)
228+
.where(User.organization_id == current_user.organization_id)
229+
.where(User.user_type == "team_member")
230+
)
231+
count = session.exec(count_statement).one()
232+
233+
statement = (
234+
select(User)
235+
.where(User.organization_id == current_user.organization_id)
236+
.where(User.user_type == "team_member")
237+
.offset(skip)
238+
.limit(limit)
239+
)
240+
users = session.exec(statement).all()
241+
242+
return UsersPublic(data=users, count=count)
243+
244+
210245
@router.get("/pending", response_model=UsersPublic)
211246
def get_pending_users(
212247
session: SessionDep,
@@ -219,7 +254,9 @@ def get_pending_users(
219254
Accessible by team members to invite people to their organization.
220255
"""
221256
if getattr(current_user, "user_type", None) != "team_member":
222-
raise HTTPException(status_code=403, detail="Only team members can invite users")
257+
raise HTTPException(
258+
status_code=403, detail="Only team members can invite users"
259+
)
223260

224261
from sqlmodel import select
225262

@@ -255,7 +292,10 @@ def assign_user_to_organization(
255292
Team members can assign users to their own organization.
256293
Superusers can assign to any organization.
257294
"""
258-
if getattr(current_user, "user_type", None) != "team_member" and not current_user.is_superuser:
295+
if (
296+
getattr(current_user, "user_type", None) != "team_member"
297+
and not current_user.is_superuser
298+
):
259299
raise HTTPException(status_code=403, detail="Not enough permissions")
260300

261301
user = session.get(User, user_id)
@@ -269,11 +309,15 @@ def assign_user_to_organization(
269309
else:
270310
# Team members assign to their own organization
271311
if not current_user.organization_id:
272-
raise HTTPException(status_code=400, detail="You must be part of an organization to invite others")
312+
raise HTTPException(
313+
status_code=400,
314+
detail="You must be part of an organization to invite others",
315+
)
273316
target_org_id = current_user.organization_id
274317

275318
# Verify organization exists
276319
from app.models import Organization
320+
277321
org = session.get(Organization, target_org_id)
278322
if not org:
279323
raise HTTPException(status_code=404, detail="Organization not found")

backend/app/core/db.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def init_db(session: Session) -> None:
2929
if not user:
3030
# Create the superuser's organization
3131
organization_in = OrganizationCreate(
32-
name="Admin Organization",
33-
description="Organization for admin user"
32+
name="Admin Organization", description="Organization for admin user"
3433
)
3534
organization = crud.create_organization(
3635
session=session, organization_in=organization_in

backend/app/crud.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ def delete_project_access(
345345
*, session: Session, project_id: uuid.UUID, user_id: uuid.UUID
346346
) -> None:
347347
"""Remove a user's access to a project"""
348-
access = get_project_access(
349-
session=session, project_id=project_id, user_id=user_id
350-
)
348+
access = get_project_access(session=session, project_id=project_id, user_id=user_id)
351349
if access:
352350
session.delete(access)
353351
session.commit()

0 commit comments

Comments
 (0)