Skip to content

✨(front) Allow to pick files from drive if set up. #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ The application uses a new environment file structure with `.defaults` and `.loc
| `AI_MODEL` | None | Default model used for AI features | Optional |
| `AI_FEATURE_SUMMARY_ENABLED` | `False` | Default enabled mode for summary AI features | Required |

### External Services

#### Drive

| Variable | Default | Description | Required |
|----------|---------|-------------|----------|
| `DRIVE_BASE_URL` | None | Base URL to access Drive endpoints | Optional |



## Legend

- **Required**: Must be set for the application to function
Expand Down
8 changes: 6 additions & 2 deletions env.d/development/backend.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ MTA_OUT_SMTP_PASSWORD=pass
MDA_API_SECRET=my-shared-secret-mda
SALT_KEY=ThisIsAnExampleSaltForDevPurposeOnly

# AI
# AI
AI_BASE_URL=
AI_API_KEY=
AI_MODEL=

AI_FEATURE_SUMMARY_ENABLED=False
AI_FEATURE_SUMMARY_ENABLED=False

# Interoperability
# Drive - https://github.com/suitenumerique/drive
DRIVE_BASE_URL=
19 changes: 19 additions & 0 deletions src/backend/core/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@
"AI_FEATURE_SUMMARY_ENABLED": {
"type": "boolean",
"readOnly": true
},
"DRIVE": {
"type": "object",
"description": "The URLs of the Drive external service.",
"properties": {
"sdk_url": {
"type": "string",
"readOnly": true
},
"api_url": {
"type": "string",
"readOnly": true
}
},
"readOnly": true,
"required": [
"sdk_url",
"api_url"
]
}
},
"required": [
Expand Down
28 changes: 28 additions & 0 deletions src/backend/core/api/viewsets/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ class ConfigView(drf.views.APIView):
"type": "boolean",
"readOnly": True,
},
"DRIVE": {
"type": "object",
"description": "The URLs of the Drive external service.",
"properties": {
"sdk_url": {
"type": "string",
"readOnly": True,
},
"api_url": {
"type": "string",
"readOnly": True,
},
},
"readOnly": True,
"required": ["sdk_url", "api_url"],
},
},
"required": [
"ENVIRONMENT",
Expand Down Expand Up @@ -83,7 +99,19 @@ def get(self, request):
if hasattr(settings, setting):
dict_settings[setting] = getattr(settings, setting)

# AI Features
dict_settings["AI_ENABLED"] = is_ai_enabled()
dict_settings["AI_FEATURE_SUMMARY_ENABLED"] = is_ai_summary_enabled()

# Drive service
if base_url := settings.DRIVE_CONFIG.get("base_url"):
dict_settings.update(
{
"DRIVE": {
"sdk_url": f"{base_url}{settings.DRIVE_CONFIG.get('sdk_url')}",
"api_url": f"{base_url}{settings.DRIVE_CONFIG.get('api_url')}",
}
}
)

return drf.response.Response(dict_settings)
20 changes: 20 additions & 0 deletions src/backend/core/tests/api/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AI_BASE_URL=None,
AI_MODEL=None,
AI_FEATURE_SUMMARY_ENABLED=False,
DRIVE_CONFIG={"base_url": None},
)
@pytest.mark.parametrize("is_authenticated", [False, True])
def test_api_config(is_authenticated):
Expand All @@ -47,3 +48,22 @@ def test_api_config(is_authenticated):
"AI_ENABLED": False,
"AI_FEATURE_SUMMARY_ENABLED": False,
}


@override_settings(
DRIVE_CONFIG={
"base_url": "http://localhost:8902",
"sdk_url": "/sdk",
"api_url": "/api/v1.0",
}
)
def test_api_config_with_external_services():
"""If Drive external service is configured, it should be included in the configuration."""
client = APIClient()

response = client.get("/api/v1.0/config/")
assert response.status_code == HTTP_200_OK
assert response.json().get("DRIVE") == {
"sdk_url": "http://localhost:8902/sdk",
"api_url": "http://localhost:8902/api/v1.0",
}
12 changes: 12 additions & 0 deletions src/backend/messages/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@ class Base(Configuration):
environ_prefix=None,
)

# External services
# Settings related to the interoperability with external services
# that messages is able to use
# 1. Drive - https://github.com/suitenumerique/drive
DRIVE_CONFIG = {
"base_url": values.Value(
default=None, environ_name="DRIVE_BASE_URL", environ_prefix=None
),
"sdk_url": "/sdk",
"api_url": "/api/v1.0",
}

# pylint: disable=invalid-name
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
44 changes: 44 additions & 0 deletions src/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@blocknote/core": "0.33.0",
"@blocknote/mantine": "0.33.0",
"@blocknote/react": "0.33.0",
"@gouvfr-lasuite/drive-sdk": "0.0.1",
"@gouvfr-lasuite/ui-kit": "0.8.2",
"@hookform/resolvers": "5.1.1",
"@openfun/cunningham-react": "3.2.0",
Expand All @@ -33,8 +34,8 @@
"@viselect/react": "3.9.0",
"clsx": "2.1.1",
"date-fns": "4.1.0",
"downshift": "9.0.10",
"dompurify": "3.2.6",
"downshift": "9.0.10",
"i18next": "25.3.0",
"next": "15.3.4",
"posthog-js": "1.257.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* This is the messages API schema.
* OpenAPI spec version: 1.0.0 (v1.0)
*/
import type { ConfigRetrieve200DRIVE } from "./config_retrieve200_driv_e";

export type ConfigRetrieve200 = {
readonly ENVIRONMENT: string;
Expand All @@ -18,4 +19,6 @@ export type ConfigRetrieve200 = {
readonly LANGUAGE_CODE: string;
readonly AI_ENABLED: boolean;
readonly AI_FEATURE_SUMMARY_ENABLED: boolean;
/** The URLs of the Drive external service. */
readonly DRIVE?: ConfigRetrieve200DRIVE;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Generated by orval v7.10.0 🍺
* Do not edit manually.
* messages API
* This is the messages API schema.
* OpenAPI spec version: 1.0.0 (v1.0)
*/

/**
* The URLs of the Drive external service.
*/
export type ConfigRetrieve200DRIVE = {
readonly sdk_url: string;
readonly api_url: string;
};
1 change: 1 addition & 0 deletions src/frontend/src/features/api/gen/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from "./blob_upload_create201";
export * from "./blob_upload_create_body";
export * from "./change_flag_request_request";
export * from "./config_retrieve200";
export * from "./config_retrieve200_driv_e";
export * from "./contact";
export * from "./contacts_list_params";
export * from "./dnscheck_response";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
width: 100%;
}

.c__field--error > .attachment-uploader {
border-color: var(--c--theme--colors--danger-600);
}

.attachment-uploader {
padding: var(--c--theme--spacings--base);
background-color: var(--c--components--forms-input--background-color);
Expand Down Expand Up @@ -131,4 +135,9 @@
flex-direction: column;
box-sizing: border-box;
position: relative;
}
}

.drive-attachment-picker:disabled {
cursor: wait;
pointer-events: auto;
}
Loading