search_app.py


Overview

search_app.py is a Flask-based REST API endpoint module responsible for managing Search App entities within the InfiniFlow system. It exposes routes for creating, updating, retrieving details, listing, and deleting Search Apps. The module enforces authentication and authorization using Flask-Login and integrates tightly with backend services for data validation, persistence, and querying.

Key responsibilities include:


Classes and Functions

This module does not define any classes; instead, it defines several Flask route handler functions that implement the API endpoints for Search App management.

1. create()

Purpose

Creates a new Search App record for the authenticated user (tenant).

Route and Method

Decorators

Parameters

Workflow

Returns

Usage Example (cURL)

curl -X POST /create \
  -H "Content-Type: application/json" \
  -d '{"name": "My Search App", "description": "A sample search app"}' \
  -b "session=<user_session_cookie>"

2. update()

Purpose

Updates an existing Search App's properties.

Route and Method

Decorators

Parameters

Workflow

Returns

Usage Example (cURL)

curl -X POST /update \
  -H "Content-Type: application/json" \
  -d '{
        "search_id": "uuid-1234",
        "name": "Updated Search App",
        "search_config": {"setting": "new_value"},
        "tenant_id": "tenant-5678"
      }' \
  -b "session=<user_session_cookie>"

3. detail()

Purpose

Retrieves detailed information about a specific Search App if the user has permission.

Route and Method

Decorators

Parameters

Workflow

Returns

Usage Example (cURL)

curl -X GET "/detail?search_id=uuid-1234" \
  -b "session=<user_session_cookie>"

4. list_search_app()

Purpose

Lists Search Apps filtered by owner IDs, keywords, pagination, and sorting options.

Route and Method

Decorators

Parameters

Workflow

Returns

Usage Example (cURL)

curl -X POST "/list?page=1&page_size=10&orderby=create_time&desc=true" \
  -H "Content-Type: application/json" \
  -d '{"owner_ids": ["tenant-123", "tenant-456"]}' \
  -b "session=<user_session_cookie>"

5. rm()

Purpose

Deletes a Search App if the user is authorized.

Route and Method

Decorators

Parameters

Workflow

Returns

Usage Example (cURL)

curl -X POST /rm \
  -H "Content-Type: application/json" \
  -d '{"search_id": "uuid-1234"}' \
  -b "session=<user_session_cookie>"

Important Implementation Details


Interaction with Other System Components


Mermaid Class Diagram

classDiagram
    class SearchService {
        +save(**kwargs) bool
        +update_by_id(search_id, data) bool
        +get_by_id(search_id) (bool, SearchApp)
        +query(**filters) list
        +accessible4deletion(search_id, user_id) bool
        +delete_by_id(search_id) bool
        +get_detail(search_id) dict
        +get_by_tenant_ids(tenant_ids, user_id, page, page_size, orderby, desc, keywords) (list, int)
    }

    class TenantService {
        +get_by_id(tenant_id) (bool, Tenant)
    }

    class UserTenantService {
        +query(user_id) list
    }

    class DB {
        +atomic() contextmanager
    }

    class Flask_Routes {
        +create()
        +update()
        +detail()
        +list_search_app()
        +rm()
    }

    Flask_Routes ..> SearchService : uses
    Flask_Routes ..> TenantService : uses
    Flask_Routes ..> UserTenantService : uses
    Flask_Routes ..> DB : uses

Summary

search_app.py is a critical API module in the InfiniFlow backend for managing Search Apps. It ensures robust validation, secure multi-tenant access, and consistent CRUD operations. By coordinating with multiple service layers and enforcing strict request contracts, it maintains data integrity and a seamless user experience for managing Search Apps.

This file is intended to be part of a larger system where Search Apps represent configurable search configurations or workflows owned by tenants in the InfiniFlow platform.