Skip to content

Commit c338594

Browse files
committed
enable organization_id updates and visibility-based filtering
1 parent d5b223b commit c338594

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

app/api/v1/services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async def create_service(
211211
async def list_services(
212212
service_type: Optional[str] = Query(None, description="Filter by service type"),
213213
is_active: Optional[bool] = Query(None, description="Filter by active status"),
214-
organization_id: Optional[str] = Query(None, description="Filter by organization"),
214+
organization_id: Optional[str] = Query(None, description="Visibility filter - returns global services + org-specific services"),
215215
page: int = Query(1, ge=1, description="Page number"),
216216
page_size: int = Query(50, ge=1, le=100, description="Items per page"),
217217
db: AsyncSession = Depends(get_db)
@@ -221,7 +221,7 @@ async def list_services(
221221
222222
- **service_type**: Filter by service type
223223
- **is_active**: Filter by active status
224-
- **organization_id**: Filter by organization (free-form string)
224+
- **organization_id**: Visibility filter - returns global services (no org) plus services matching this org ID
225225
- **page**: Page number (default: 1)
226226
- **page_size**: Items per page (default: 50, max: 100)
227227
"""

app/schemas/service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class ServiceUpdate(BaseModel):
349349
route: Optional[str] = Field(None, min_length=1, max_length=100)
350350
service_type: Optional[str] = None
351351
description: Optional[Dict[str, str]] = None
352+
organization_id: Optional[str] = Field(None, max_length=100)
352353
is_active: Optional[bool] = None
353354
flavors: Optional[List[ServiceFlavorCreate]] = None
354355
metadata: Optional[Dict[str, Any]] = None

app/services/service_service.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from typing import Optional
44
from uuid import UUID
5-
from sqlalchemy import select, func, and_
5+
from sqlalchemy import select, func, and_, or_
66
from sqlalchemy.ext.asyncio import AsyncSession
77
from sqlalchemy.exc import IntegrityError
88
from sqlalchemy.orm import selectinload, joinedload
@@ -326,8 +326,13 @@ async def get_services(
326326
if is_active is not None:
327327
filters.append(Service.is_active == is_active)
328328
if organization_id:
329-
# Strict filter: only services with this exact organization_id
330-
filters.append(Service.organization_id == organization_id)
329+
# Visibility filter: show global services (no org) + services for this org
330+
# Services with a different organization_id are excluded
331+
filters.append(or_(
332+
Service.organization_id.is_(None),
333+
Service.organization_id == "",
334+
Service.organization_id == organization_id
335+
))
331336

332337
if filters:
333338
query = query.where(and_(*filters))

frontend/components/services/ServiceForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ export function ServiceForm({ service, onSuccess, onCancel }: ServiceFormProps)
6161
const onSubmit = async (data: ServiceFormData) => {
6262
try {
6363
if (service) {
64-
// Update existing service (only name and description)
64+
// Update existing service
6565
await updateMutation.mutateAsync({
6666
id: service.id,
6767
data: {
6868
name: data.name,
6969
description: data.description,
70+
organization_id: data.organization_id || '',
7071
},
7172
});
7273
} else {

frontend/types/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export interface CreateServiceRequest {
229229
export interface UpdateServiceRequest {
230230
name?: string;
231231
description?: Partial<I18nDescription>;
232+
organization_id?: string;
232233
default_template_id?: string | null;
233234
}
234235

0 commit comments

Comments
 (0)