Compare commits

...

5 Commits

Author SHA1 Message Date
leo ef7aa6d7ba wip 2026-11-19 18:47:49 +01:00
leo c69cec942e add mail 2026-11-19 18:29:23 +01:00
leo 981b7c5ec8 wip 2026-11-19 18:26:23 +01:00
leo f52835c331 remove unrelated change 2026-11-19 12:27:06 +01:00
leo b7c725413d wip 2026-11-19 12:25:58 +01:00
43 changed files with 3528 additions and 96 deletions
+1
View File
@@ -14,6 +14,7 @@ and this project adheres to
- 🌐(i18n) add Portuguese language support
- ✨(frontend) add jittered exponential backoff to LiveKit reconnections
- ✨(frontend) tell participants when a recording is interrupted
- ✨(backend) add Drive as a recording storage method
### Changed
+6
View File
@@ -119,6 +119,7 @@ bootstrap: \
data/media \
data/static \
create-env-files \
create-docker-network \
build \
migrate \
demo \
@@ -152,11 +153,16 @@ down: ## stop and remove containers, networks, images, and volumes
@$(COMPOSE) down
.PHONY: down
create-docker-network: ## create the shared lasuite-network if it doesn't exist
@docker network create lasuite-network || true
.PHONY: create-docker-network
logs: ## display app-dev logs (follow mode)
@$(COMPOSE) logs -f app-dev
.PHONY: logs
run-backend: ## start only the backend application and all needed services
@$(MAKE) create-docker-network
@$(COMPOSE) up --force-recreate -d celery-dev --remove-orphans
@$(COMPOSE) up --force-recreate -d nginx
@$(COMPOSE) up -d livekit
+15 -8
View File
@@ -86,6 +86,7 @@ services:
networks:
- resource-server
- default
- lasuite
celery-dev:
user: ${DOCKER_USER:-1000}
@@ -102,6 +103,9 @@ services:
- /app/.venv
depends_on:
- app-dev
networks:
- default
- lasuite
app:
build:
@@ -190,32 +194,32 @@ services:
- env.d/development/kc_postgresql
keycloak:
image: quay.io/keycloak/keycloak:20.0.1
image: quay.io/keycloak/keycloak:26.3.2
volumes:
- ./docker/auth/realm.json:/opt/keycloak/data/import/realm.json
command:
- start-dev
- --features=preview
- --import-realm
- --proxy=edge
- --hostname-url=http://localhost:8083
- --hostname-admin-url=http://localhost:8083/
- --proxy-headers=xforwarded
- --hostname=http://localhost:8083
- --hostname-strict=false
- --hostname-strict-https=false
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KC_BOOTSTRAP_ADMIN_USERNAME: admin
KC_BOOTSTRAP_ADMIN_PASSWORD: admin
KC_DB: postgres
KC_DB_URL_HOST: kc_postgresql
KC_DB_URL_DATABASE: keycloak
KC_DB_PASSWORD: pass
KC_DB_USERNAME: meet
KC_DB_SCHEMA: public
PROXY_ADDRESS_FORWARDING: 'true'
ports:
- "127.0.0.1:8080:8080"
depends_on:
- kc_postgresql
networks:
- default
- lasuite
livekit:
image: livekit/livekit-server:v1.13.11
@@ -332,3 +336,6 @@ services:
networks:
default:
resource-server:
lasuite:
name: lasuite-network
external: true
+136
View File
@@ -845,6 +845,142 @@
"offline_access",
"microprofile-jwt"
]
},
{
"clientId": "drive",
"name": "",
"description": "",
"rootUrl": "",
"adminUrl": "",
"baseUrl": "",
"surrogateAuthRequired": false,
"enabled": "true",
"alwaysDisplayInConsole": false,
"clientAuthenticatorType": "client-secret",
"secret": "ThisIsAnExampleKeyForDevPurposeOnly",
"redirectUris": [
"http://localhost:3100/*",
"http://localhost:8171/*",
"http://localhost:8085/*"
],
"webOrigins": [
"http://localhost:3100",
"http://localhost:8171",
"http://localhost:8085"
],
"notBefore": 0,
"bearerOnly": false,
"consentRequired": false,
"standardFlowEnabled": true,
"implicitFlowEnabled": false,
"directAccessGrantsEnabled": false,
"serviceAccountsEnabled": false,
"publicClient": false,
"frontchannelLogout": true,
"protocol": "openid-connect",
"attributes": {
"access.token.lifespan": "-1",
"client.secret.creation.time": "1707820779",
"user.info.response.signature.alg": "RS256",
"post.logout.redirect.uris": "http://localhost:3100/*##http://localhost:8171/*##http://localhost:8085/*",
"oauth2.device.authorization.grant.enabled": "false",
"use.jwks.url": "false",
"backchannel.logout.revoke.offline.tokens": "false",
"use.refresh.tokens": "true",
"tls-client-certificate-bound-access-tokens": "false",
"oidc.ciba.grant.enabled": "false",
"backchannel.logout.session.required": "true",
"client_credentials.use_refresh_token": "false",
"acr.loa.map": "{}",
"require.pushed.authorization.requests": "false",
"display.on.consent.screen": "false",
"client.session.idle.timeout": "-1",
"token.response.type.bearer.lower-case": "false"
},
"authenticationFlowBindingOverrides": {},
"fullScopeAllowed": true,
"nodeReRegistrationTimeout": -1,
"defaultClientScopes": [
"web-origins",
"acr",
"roles",
"profile",
"email"
],
"optionalClientScopes": [
"address",
"phone",
"offline_access",
"microprofile-jwt"
]
},
{
"clientId": "deploycenter",
"name": "",
"description": "",
"rootUrl": "",
"adminUrl": "",
"baseUrl": "",
"surrogateAuthRequired": false,
"enabled": "true",
"alwaysDisplayInConsole": false,
"clientAuthenticatorType": "client-secret",
"secret": "ThisIsAnExampleKeyForDevPurposeOnly",
"redirectUris": [
"http://localhost:3100/*",
"http://localhost:8171/*",
"http://localhost:8085/*"
],
"webOrigins": [
"http://localhost:3100",
"http://localhost:8171",
"http://localhost:8085"
],
"notBefore": 0,
"bearerOnly": false,
"consentRequired": false,
"standardFlowEnabled": true,
"implicitFlowEnabled": false,
"directAccessGrantsEnabled": false,
"serviceAccountsEnabled": false,
"publicClient": false,
"frontchannelLogout": true,
"protocol": "openid-connect",
"attributes": {
"access.token.lifespan": "-1",
"client.secret.creation.time": "1707820779",
"user.info.response.signature.alg": "RS256",
"post.logout.redirect.uris": "http://localhost:3100/*##http://localhost:8171/*##http://localhost:8085/*",
"oauth2.device.authorization.grant.enabled": "false",
"use.jwks.url": "false",
"backchannel.logout.revoke.offline.tokens": "false",
"use.refresh.tokens": "true",
"tls-client-certificate-bound-access-tokens": "false",
"oidc.ciba.grant.enabled": "false",
"backchannel.logout.session.required": "true",
"client_credentials.use_refresh_token": "false",
"acr.loa.map": "{}",
"require.pushed.authorization.requests": "false",
"display.on.consent.screen": "false",
"client.session.idle.timeout": "-1",
"token.response.type.bearer.lower-case": "false"
},
"authenticationFlowBindingOverrides": {},
"fullScopeAllowed": true,
"nodeReRegistrationTimeout": -1,
"defaultClientScopes": [
"web-origins",
"acr",
"roles",
"profile",
"email"
],
"optionalClientScopes": [
"address",
"phone",
"offline_access",
"microprofile-jwt"
]
}
],
"clientScopes": [
+307
View File
@@ -0,0 +1,307 @@
# Room Recording (Beta)
La Suite Meet offers a room recording feature that is currently in beta, with ongoing improvements planned.
The feature allows users to record their room sessions. When a recording is complete, the room owner receives a notification with a link to download the recorded file. Recordings are automatically deleted after `RECORDING_EXPIRATION_DAYS`.
It uses LiveKit Egress to record room sessions. For reference, see the [LiveKit Egress repository](https://github.com/livekit/egress) and the [official documentation](https://docs.livekit.io/home/egress/overview/).
**Current Limitations**:
* Users cannot record and transcribe simultaneously. ([Issue #527](https://github.com/suitenumerique/meet/issues/527)
is on our backlog)
* Recording layout cannot be configured from the frontend. By default, the egress captures the active speaker and any shared screens. (not yet planned)
* Shareable links with an embedded video player are not yet supported. (not yet planned)
> [!NOTE]
> Questions? Open an issue on [GitHub](https://github.com/suitenumerique/meet/issues/new?assignees=&labels=bug&template=Bug_report.md) or join our [Matrix community](https://matrix.to/#/#meet-official:matrix.org).
## Special requirements
To use the room recording feature, the following components are required:
- A running [LiveKit Egress](https://github.com/livekit/egress) server capable of handling room composite recordings.
- A S3-compatible object storage that supports webhook events to notify the backend when recordings are uploaded.
- An email service to notify room owners when a recording is available for download.
- Webhook events configured between LiveKit Server and the backend.
> [!CAUTION]
> Minio supports lifecycle events; other providers may not work out of the box. There is currently a dependency on Minio, which is planned to be refactored in the future.
> [!NOTE]
> Celery isn’t in use for these async tasks yet. It’s something we’d like to add, but it’s not planned at this stage.
## How It Works
```mermaid
sequenceDiagram
participant User
participant Frontend as Frontend (React)
participant Backend as Django Backend
participant LiveKit as LiveKit API
participant Egress as LiveKit Egress
participant Storage as Object Storage
participant Room as LiveKit Room
participant Email as Email Service
User->>Frontend: Click start recording button
Frontend->>Backend: POST /api/v1.0/rooms/{id}/start-recording/
Backend->>LiveKit: Create egress request
LiveKit->>Egress: Start room composite egress
Egress->>Room: Join room as recording participant
Note over Egress,Room: Egress joins room to capture audio/video
LiveKit-->>Backend: Return egress_id
Backend->>Backend: Update Recording with worker_id
Backend-->>Frontend: HTTP 201 - Recording started
Frontend->>Frontend: Update recording status
Frontend->>Frontend: Notify other participants
Note over Frontend: Via LiveKit data channel
Note over Egress,Room: Recording in progress...
User->>Frontend: Click stop recording button
Frontend->>Backend: POST /api/v1.0/rooms/{id}/stop-recording/
Backend->>LiveKit: Stop egress request
LiveKit->>Egress: Stop recording
Egress->>Storage: Upload recorded file
Storage->>Backend: Storage event notification
Backend->>Backend: Update Recording status to SAVED
Backend->>Email: Send notification to room owner
Backend-->>Frontend: HTTP 200 - Recording stopped
Frontend->>Frontend: Update UI and notify participants
Email->>User: Send email with recording link
User->>Frontend: Navigate to /recording/{id} to download file
Frontend->>Frontend: Download recording file
```
## Configuration Options
| Option | Type | Default | Description |
| --------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **RECORDING_ENABLE** | Boolean | `False` | Enable or disable the room recording feature. |
| **RECORDING_OUTPUT_FOLDER** | String | `"recordings"` | Folder/prefix where recordings are stored in the object storage. |
| **RECORDING_WORKER_CLASSES** | Dict | `{ "screen_recording": "core.recording.worker.services.VideoCompositeEgressService", "transcript": "core.recording.worker.services.AudioCompositeEgressService" }` | Maps recording types to their worker service classes. |
| **RECORDING_EVENT_PARSER_CLASS** | String | `"core.recording.event.parsers.MinioParser"` | Class responsible for parsing storage events and updating the backend. |
| **RECORDING_ENABLE_STORAGE_EVENT_AUTH** | Boolean | `True` | Enable authentication for storage event webhook requests. |
| **RECORDING_STORAGE_EVENT_ENABLE** | Boolean | `False` | Enable handling of storage events (must configure webhook in storage). If `False`, fallback to LiveKit egress complete webhook. |
| **RECORDING_STORAGE_EVENT_TOKEN** | Secret/File | `None` | Token used to authenticate storage webhook requests, if `RECORDING_ENABLE_STORAGE_EVENT_AUTH` is enabled. |
| **RECORDING_EXPIRATION_DAYS** | Integer | `None` | Number of days before recordings expire. Should match bucket lifecycle policy. Set to `None` for no expiration. |
| **RECORDING_MAX_DURATION** | Integer | `None` | Maximum duration of a recording in milliseconds. Must be synced with the LiveKit Egress configuration. Set to None for unlimited duration. When the maximum duration is reached, the recording is automatically stopped and saved, and the user is prompted in the frontend with an alert message. |
| **RECORDING_ENCODING_ENABLED** | Boolean | `False` | When `False`, LiveKit Egress uses its built-in `H264_720P_30` preset. When `True`, the `RECORDING_ENCODING_*` values below are sent to LiveKit as advanced `EncodingOptions`. See [Tuning recording encoding](#tuning-recording-encoding). |
| **RECORDING_ENCODING_WIDTH** | Integer | `1280` | Recording video width in pixels. Only applied when `RECORDING_ENCODING_ENABLED` is `True`. |
| **RECORDING_ENCODING_HEIGHT** | Integer | `720` | Recording video height in pixels. Only applied when `RECORDING_ENCODING_ENABLED` is `True`. |
| **RECORDING_ENCODING_FRAMERATE** | Integer | `30` | Recording video framerate (fps). Directly impacts egress worker CPU (roughly linear). Only applied when `RECORDING_ENCODING_ENABLED` is `True`. |
| **RECORDING_ENCODING_VIDEO_BITRATE_KBPS** | Integer | `3000` | H.264 MAIN video bitrate in kbps. Only applied when `RECORDING_ENCODING_ENABLED` is `True`. |
| **RECORDING_ENCODING_AUDIO_BITRATE_KBPS** | Integer | `128` | AAC audio bitrate in kbps. Only applied when `RECORDING_ENCODING_ENABLED` is `True`. |
| **RECORDING_ENCODING_KEY_FRAME_INTERVAL_S** | Float | `4.0` | Keyframe interval in seconds. Drives seek granularity in the recorded MP4 (a player can only seek to keyframe boundaries). Larger values give the encoder slightly more bits for non-keyframe content at a fixed bitrate. `4.0` is a standard VOD value. Only applied when `RECORDING_ENCODING_ENABLED` is `True`. |
### Manual Storage Webhook
Storage events must be configured manually; the Kubernetes chart does not do this automatically.
1. Configure your S3 bucket to send file creation events to the backend webhook.
2. Enable events and token in settings:
```python
RECORDING_STORAGE_EVENT_ENABLE = True
RECORDING_ENABLE_STORAGE_EVENT_AUTH = True
RECORDING_STORAGE_EVENT_TOKEN = <token>
```
> [!NOTE]
> Questions? Open an issue on [GitHub](https://github.com/suitenumerique/meet/issues/new?assignees=&labels=bug&template=Bug_report.md) or join our [Matrix community](https://matrix.to/#/#meet-official:matrix.org).
## Push recordings to Drive
`RECORDING_STORAGE_METHOD` sets where a finished video recording is made available:
- `s3_email` (default): it stays in the object storage, and everyone with access
to it (its starter and the room's owners and administrators) is emailed a link
to download it.
- `drive`: it is also streamed to the [Drive](https://github.com/suitenumerique/drive)
of the user who started it, into a folder at the root of their Drive
(`RECORDING_DRIVE_FOLDER_NAME`, created when missing). The file is then shared,
as owners, with the room's owners and administrators at the time the recording
started. Drive emails them; Meet only emails the starter, with a link to the
file. The object storage copy is kept until it expires.
The method is the one set when a recording starts. Audio-only transcripts are not
concerned: they end up in Docs, through the summary service.
> [!IMPORTANT]
> Nothing falls back to the download email when a recording cannot be pushed
> to Drive. Such failures are only visible in the recording's delivery, in the
> Django admin, and in the audit log (`recording.drive.push`).
Drive is called as a resource server, on behalf of the user who started the
recording, following its
[resource server documentation](https://github.com/suitenumerique/drive/blob/main/docs/resource_server.md).
The token Meet calls it with is obtained when the recording starts, while the
user is around, and kept encrypted until the push is over.
`RECORDING_DRIVE_AUTH_METHOD` sets which token:
- `token_exchange` (default): the user's access token is exchanged with
[Menshen](https://github.com/suitenumerique/menshen) for a token targeting
Drive, revoked once the push is over. Its lifetime is set by Menshen's meet →
drive exchange rule (one hour by default): it must outlast the longest
recording, plus the time to process and push it.
- `access_token`: the user's access token itself, assumed to still be valid when
the recording is over. Long recordings may therefore fail to be pushed.
If the token cannot be obtained when the recording starts, the recording still
starts, but will not be pushed.
When the push fails, it is tried again later, up to
`RECORDING_DRIVE_PUSH_MAX_ATTEMPTS` times, while the token is valid. It runs in
a Celery worker (`CELERY_ENABLED`): without one, it would run within the
request ending the recording.
### Special requirements
- Drive accepting Meet's calls on its external API:
- with `token_exchange`: Drive's `MENSHEN_ENABLED`, with a meet → drive
exchange rule in Menshen granting the scopes Drive's `MENSHEN_REQUIRED_SCOPES`
requires.
- with `access_token`: Drive configured as an OIDC resource server accepting
Meet's audience (`OIDC_RS_ALLOWED_AUDIENCES` must contain Meet's client id).
- Drive's `EXTERNAL_API` setting allowing, on `items`, the `list`, `create`,
`children` and `upload_ended` and `destroy` actions.
- To share the file with the room's owners and administrators, Drive's
`EXTERNAL_API` must also enable `item_access` and `item_invitation` with the
`create` action, and add `list` to `users`. Otherwise the file stays in the
starter's Drive only. With `token_exchange`, Drive must also accept Menshen
tokens on these endpoints.
- `OIDC_STORE_ACCESS_TOKEN` enabled on Meet, along with
`OIDC_STORE_REFRESH_TOKEN_KEY`, the Fernet key encrypting the stored token.
### Configuration options
| Option | Type | Default | Description |
| ---------------------------------------------- | ----------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **RECORDING_STORAGE_METHOD** | String | `"s3_email"` | Where a finished video recording is made available: `s3_email` or `drive`. |
| **RECORDING_DRIVE_AUTH_METHOD** | String | `"token_exchange"` | Token Meet calls Drive with: `token_exchange` or `access_token`. |
| **RECORDING_DRIVE_FOLDER_NAME** | String | `"Visio-Recordings"` | Folder, at the root of the user's Drive, recordings are pushed to. |
| **RECORDING_DRIVE_AUDIENCE** | String | `None` | Audience Drive is registered under in Menshen. Required with `token_exchange`. |
| **RECORDING_DRIVE_SCOPE** | String | `None` | Space-separated scopes asked for in the token exchange. When empty, Menshen grants what its exchange rule allows. |
| **RECORDING_DRIVE_PUSH_MAX_ATTEMPTS** | Integer | `3` | Attempts at pushing a recording to Drive, before giving up. |
| **RECORDING_DRIVE_SIGNED_URL_EXPIRY_SECONDS** | Integer | `3600` | Lifetime of the signed URL the worker downloads the recording from. |
| **DRIVE_API_BASE_URL** | String | `None` | Base URL of Drive's external API, e.g. `https://fichiers.numerique.gouv.fr/external_api/v1.0`. |
| **DRIVE_FRONTEND_BASE_URL** | String | `None` | Base URL of Drive's interface, to link to the pushed file, e.g. `https://fichiers.numerique.gouv.fr`. |
| **MENSHEN_SERVER_URL**, **MENSHEN_CLIENT_ID**, **MENSHEN_CLIENT_SECRET** | String | `None` | Menshen, and Meet's credentials there. Required with `token_exchange`. |
| **OIDC_STORE_ACCESS_TOKEN** | Boolean | `False` | Keep the user's access token in the session, required to call Drive on their behalf. |
| **OIDC_STORE_REFRESH_TOKEN_KEY** | Secret/File | `None` | Fernet key encrypting OIDC tokens at rest. Generate one with `Fernet.generate_key()`. |
| **DRIVE_UPLOAD_STORAGE_NETLOC** | String | `None` | Development only: `host:port` to reach Drive's object storage at, when the domain Drive signs its upload URLs with only resolves from a browser. |
### Local development
Meet and Drive run as two separate compose projects, joined by the external
`lasuite-network` (`make create-docker-network`). Meet's backend containers reach
Drive's backend at `drive-app-dev:8000` (Drive's nginx does not route
`/external_api/`) and its object storage at `drive-minio:9000`.
This stack has no Menshen, so Meet's development environment uses
`RECORDING_DRIVE_AUTH_METHOD=access_token`.
On the Drive side:
```bash
OIDC_RESOURCE_SERVER_ENABLED=True
OIDC_RS_CLIENT_ID=drive
OIDC_RS_CLIENT_SECRET=ThisIsAnExampleKeyForDevPurposeOnly
OIDC_RS_AUDIENCE_CLAIM=client_id
OIDC_RS_ALLOWED_AUDIENCES=meet
```
`DRIVE_UPLOAD_STORAGE_NETLOC` is needed because Drive signs its upload URLs
with `localhost:9100`, which does not resolve from Meet's containers. The
presigned signature covers the `Host` header, so the backend keeps announcing the
signed host and only swaps the address it connects to.
## LiveKit Egress
La Suite Meet uses LiveKit Egress to record room sessions. For reference, see the [LiveKit Egress repository](https://github.com/livekit/egress) and the [official documentation](https://docs.livekit.io/home/egress/overview/).
Currently, only `RoomCompositeEgress` is supported. This mode combines all video and audio tracks from the room into a single recording.
To monitor egress workers and inspect recording status, it is recommended to install `livekit-cli`. For example, you can list active egress sessions using the following command:
```bash
$ livekit-cli list-egress
Using default project meet
+-----------------+---------------+----------------+--------------------------------------+--------------------------------+-------+
| EGRESSID | STATUS | TYPE | SOURCE | STARTED AT | ERROR |
+-----------------+---------------+----------------+--------------------------------------+--------------------------------+-------+
| EG_XXXXXXXXXXXX | EGRESS_ACTIVE | room_composite | your-room-name-XXXXXXXXXXX-XXXXXXXXX | 2024-07-05 18:11:37.073847924 | |
| | | | | +0200 CEST | |
+-----------------+---------------+----------------+--------------------------------------+--------------------------------+-------+
```
This allows you to verify which recordings are in progress, troubleshoot egress issues, and confirm that recordings are being processed correctly.
## Tuning recording encoding
By default, LiveKit Egress records with the built-in `H264_720P_30` preset: 1280×720 at 30 fps, 3000 kbps H.264 MAIN video and 128 kbps AAC audio. For a one-hour meeting this produces a file of roughly **1.4 GB**, which is often heavier than necessary for talking-head content and screen sharing.
The `RECORDING_ENCODING_*` settings let operators override this preset without modifying the source. Values are passed straight through LiveKit's `EncodingOptions.advanced` to the GStreamer pipeline (`x264enc` for video, `faac` for audio), so there are no hidden conversions — what you set is what the encoder receives.
### How values map to GStreamer
| Setting | GStreamer element | Property |
| ------------------------------------- | ----------------- | ---------------------------------- |
| `RECORDING_ENCODING_WIDTH/HEIGHT` | capsfilter | `video/x-raw,width=W,height=H` |
| `RECORDING_ENCODING_FRAMERATE` | capsfilter | `framerate=F/1` |
| `RECORDING_ENCODING_VIDEO_BITRATE_KBPS` | `x264enc` | `bitrate=kbps` (kilobits) |
| `RECORDING_ENCODING_KEY_FRAME_INTERVAL_S` | `x264enc` | `key-int-max = interval × fps` |
| `RECORDING_ENCODING_AUDIO_BITRATE_KBPS` | `faac` | `bitrate = kbps × 1000` (bits) |
The H.264 profile is fixed to MAIN and the x264 `speed-preset` to `veryfast` by LiveKit (real-time constraint) — lowering the framerate is therefore the main lever to save CPU, while lowering the bitrate is the main lever to shrink the output file.
### Reference profiles
Rough 30-minute file-size estimates assume video + audio bitrate multiplied by duration. Actual sizes vary with content (static talking heads compress better than heavy screen motion). Egress CPU figures are indicative, measured on a single Ryzen laptop core saturated by the default preset (= 100 %); scaling is roughly linear with `framerate × bitrate` but the absolute numbers depend on the host hardware.
| Profile | Resolution | FPS | Video (kbps) | Audio (kbps) | Keyframe (s) | ~ size / 30 min | Egress CPU (vs. default) | Suitable for |
| ---------------------- | ---------- | --- | ------------ | ------------ | ------------ | --------------- | ------------------------ | --------------------------------------------------- |
| Default (preset) | 1280×720 | 30 | 3000 | 128 | 4 | **~690 MB** | 100 % | Unchanged LiveKit behaviour |
| Balanced | 1280×720 | 20 | 1000 | 96 | 4 | ~240 MB | ~67 % | Mixed content, moderate motion |
| **Low CPU / small file** | 1280×720 | 15 | 600 | 64 | 4 | **~150 MB** | ~50 % | Talking-head dominant meetings + occasional slides ★ |
| Slide-heavy | 1280×720 | 15 | 900 | 64 | 4 | ~210 MB | ~55 % | Frequent dense screen sharing (decks, IDE, docs) |
| Minimum CPU | 960×540 | 15 | 500 | 64 | 4 | ~125 MB | ~30 % | Voice-first meetings, readable text not required |
| Audio-heavy fallback | 1280×720 | 10 | 400 | 96 | 4 | ~110 MB | ~35 % | Long webinars, low motion |
★ Recommended starting point for typical LaSuite Meet usage.
Environment variables for the **Low CPU / small file** profile:
```bash
RECORDING_ENCODING_ENABLED=True
RECORDING_ENCODING_WIDTH=1280
RECORDING_ENCODING_HEIGHT=720
RECORDING_ENCODING_FRAMERATE=15
RECORDING_ENCODING_VIDEO_BITRATE_KBPS=600
RECORDING_ENCODING_AUDIO_BITRATE_KBPS=64
RECORDING_ENCODING_KEY_FRAME_INTERVAL_S=4.0
```
### Caveats
- **Screen-share readability — think bits/frame, not bitrate**: at 720p, text legibility starts to break down below ~40 kbits/frame (= `bitrate ÷ framerate`). The recommended preset (600 kbps × 15 fps) sits at exactly that threshold, comfortable for talking heads with occasional slide sharing. The same 600 kbps at 30 fps would only deliver 20 kbits/frame and visibly blur dense slides — which is why **lowering framerate is a more screen-share-friendly lever than lowering bitrate**. For deck-heavy or IDE-share meetings, prefer the **Slide-heavy** profile (900 kbps × 15 fps ≈ 60 kbits/frame).
- **Motion handling**: the `veryfast` x264 preset is set by LiveKit and cannot be overridden here. Low-bitrate settings will therefore show more artefacts on fast motion than an offline re-encode with a slower preset would. This is the other reason FPS reduction is the safer tuning lever for meeting recordings.
- **Audio**: AAC at 64 kbps stereo is transparent for voice but starts to compress music noticeably. Keep 128 kbps if you expect music playback in meetings.
- **Codec choice**: H.264 MAIN is hardcoded on purpose. Switching to HEVC or VP9 would increase egress CPU cost 2×–5×, defeating the goal of this tuning.
@@ -227,6 +227,7 @@ Transcripts and summaries come from a recording, so their actions sit under `rec
| `recording.transcript.request` | The backend sends a recording to the summary service, or fails to | Actor `system`, `service.target.name` `summary`. `lasuite.details.summary_requested`, `job_id` |
| `recording.transcript.report` | The summary service reports on a transcript, or its call is refused | `service.origin.name` `summary`. `lasuite.details.job_id`, `status` |
| `recording.summary.report` | The summary service reports on a summary | As `recording.transcript.report` |
| `recording.drive.push` | A video recording is pushed to Drive, see, or will not be: no token when it starts (`authentication_failed`, actor the starter), or the push fails | Actor `system` once the recording is over, `service.target.name` `drive`. `lasuite.details.token_type`, `drive_item_id`, `share_failures` |
A recording target's `mode` is how it was captured, `screen_recording` or `transcript`, and `requested_mode` what the user asked for. They differ for a transcript with **Also start a video recording** ticked. `is_transcribed` says whether it goes to the summary service.
+18
View File
@@ -24,10 +24,16 @@ MEET_BASE_URL="http://localhost:8072"
# Media
STORAGES_STATICFILES_BACKEND=django.contrib.staticfiles.storage.StaticFilesStorage
AWS_S3_DOMAIN_REPLACE=http://localhost:9000
<<<<<<< HEAD
AWS_S3_ENDPOINT_URL=http://garage:9000
AWS_S3_ACCESS_KEY_ID=meet-access-key
AWS_S3_SECRET_ACCESS_KEY=meet-secret-access-key
AWS_S3_REGION_NAME=local
=======
AWS_S3_ENDPOINT_URL=http://meet-minio:9000
AWS_S3_ACCESS_KEY_ID=meet
AWS_S3_SECRET_ACCESS_KEY=password
>>>>>>> 9bfb46f2 (wip)
MEDIA_BASE_URL=http://localhost:3000
FILE_UPLOAD_ENABLED=True
@@ -51,6 +57,10 @@ LOGOUT_REDIRECT_URL=http://localhost:3000
OIDC_REDIRECT_ALLOWED_HOSTS=localhost:8083,localhost:3000
OIDC_AUTH_REQUEST_EXTRA_PARAMS={"acr_values": "eidas1"}
# The key below encrypts OIDC tokens at rest.
OIDC_STORE_ACCESS_TOKEN=True
OIDC_STORE_REFRESH_TOKEN_KEY=
OIDC_RS_CLIENT_ID=meet
OIDC_RS_CLIENT_SECRET=ThisIsAnExampleKeyForDevPurposeOnly
@@ -70,6 +80,14 @@ SUMMARY_SERVICE_API_TOKEN=password
SUMMARY_SERVICE_WEBHOOK_API_TOKEN=webhook-password
RECORDING_DOWNLOAD_BASE_URL=http://localhost:3000/recording
<<<<<<< HEAD
=======
# Push recordings to Drive
# DRIVE_UPLOAD_STORAGE_NETLOC is a development-only workaround.
RECORDING_PUSH_TO_DRIVE_ENABLED=True
DRIVE_API_BASE_URL=http://drive-app-dev:8000/external_api/v1.0
DRIVE_UPLOAD_STORAGE_NETLOC=drive-minio:9000
>>>>>>> 9bfb46f2 (wip)
# Recording encoding (LiveKit Egress advanced options).
# Every video recording is encoded with parameters (height, width, fps, kbps) derived
@@ -2,9 +2,15 @@ LIVEKIT_URL=ws://livekit:7880
LIVEKIT_API_KEY=devkey
LIVEKIT_API_SECRET=secret
<<<<<<< HEAD
AWS_S3_ENDPOINT_URL=garage:9000
AWS_S3_ACCESS_KEY_ID=meet-access-key
AWS_S3_SECRET_ACCESS_KEY=meet-secret-access-key
AWS_S3_REGION_NAME=local
=======
AWS_S3_ENDPOINT_URL=meet-minio:9000
AWS_S3_ACCESS_KEY_ID=meet
AWS_S3_SECRET_ACCESS_KEY=password
>>>>>>> 9bfb46f2 (wip)
AWS_STORAGE_BUCKET_NAME=meet-media-storage
AWS_S3_SECURE_ACCESS=False
@@ -0,0 +1,12 @@
LIVEKIT_URL=ws://livekit:7880
LIVEKIT_API_KEY=devkey
LIVEKIT_API_SECRET=secret
AWS_S3_ENDPOINT_URL=minio:9000
AWS_S3_ACCESS_KEY_ID=meet
AWS_S3_SECRET_ACCESS_KEY=password
AWS_STORAGE_BUCKET_NAME=meet-media-storage
AWS_S3_SECURE_ACCESS=False
SENTRY_DSN=
SENTRY_ENVIRONMENT=
+4
View File
@@ -2,7 +2,11 @@ APP_NAME="meet-app-summary-dev"
APP_API_TOKEN="password"
AWS_STORAGE_BUCKET_NAME="meet-media-storage"
<<<<<<< HEAD
AWS_S3_ENDPOINT_URL="garage:9000"
=======
AWS_S3_ENDPOINT_URL="meet-minio:9000"
>>>>>>> 9bfb46f2 (wip)
AWS_S3_SECURE_ACCESS=false
AWS_S3_ACCESS_KEY_ID="meet-access-key"
+25 -1
View File
@@ -327,6 +327,30 @@ class RecordingAccessInline(admin.TabularInline):
autocomplete_fields = ["user"]
class RecordingDeliveryInline(admin.StackedInline):
"""Read-only inline showing how a recording was delivered, and how far it got."""
model = models.RecordingDelivery
extra = 0
can_delete = False
fields = (
"method",
"status",
"user",
"token_type",
"token_expires_at",
"drive_item_id",
"error",
"created_at",
"updated_at",
)
readonly_fields = fields
def has_add_permission(self, request, obj=None):
"""Deliveries are created when a recording starts, never by hand."""
return False
@admin.action(description=_("Resend notification to external service"))
def resend_notification(modeladmin, request, queryset): # pylint: disable=unused-argument
"""Resend notification to external service for selected recordings."""
@@ -415,7 +439,7 @@ def mark_as_failed_to_stop(modeladmin, request, queryset):
class RecordingAdmin(admin.ModelAdmin):
"""Recording admin interface declaration."""
inlines = (RecordingAccessInline,)
inlines = (RecordingAccessInline, RecordingDeliveryInline)
search_fields = [
"status",
"=id",
+5
View File
@@ -46,6 +46,7 @@ from core.api.exceptions import ensure_room_not_deleted
from core.api.filters import ListFileFilter
from core.api.locks import room_locked_for_update
from core.enums import MEDIA_STORAGE_URL_PATTERN
from core.recording.delivery import service as delivery_service
from core.recording.enums import FileExtension
from core.recording.event.authentication import RecordingProcessWebhookAuthentication
from core.recording.services.metadata_collector import (
@@ -503,6 +504,9 @@ class RoomViewSet( # pylint: disable=too-many-public-methods
status=drf_status.HTTP_409_CONFLICT,
)
# Outside the transaction: it may call Menshen
delivery_service.prepare(request, recording)
worker_service = get_worker_service(mode=recording.mode)
worker_manager = WorkerServiceMediator(worker_service=worker_service)
@@ -512,6 +516,7 @@ class RoomViewSet( # pylint: disable=too-many-public-methods
models.Recording.objects.filter(pk=recording.pk).update(
status=models.RecordingStatusChoices.FAILED_TO_START
)
delivery_service.abandon(recording, "The recording failed to start.")
return drf_response.Response(
{"error": f"Recording failed to start for room {room.slug}"},
status=drf_status.HTTP_502_BAD_GATEWAY,
+1
View File
@@ -45,6 +45,7 @@ RECORDING_TRANSCRIPT_REPORT = audit.Action(
RECORDING_SUMMARY_REPORT = audit.Action(
"recording.summary.report", types=(EventType.END,)
)
RECORDING_DRIVE_PUSH = audit.Action("recording.drive.push", types=(EventType.CREATION,))
# Targets that are not models
@@ -11,7 +11,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import SuspiciousOperation, ValidationError
import requests
import httpx2
from lasuite.oidc_resource_server.backend import ResourceServerBackend as LaSuiteBackend
from menshen_client import Configuration, IntrospectionRequest, TokenExchangeClient
from menshen_client.exceptions import ResponseParsingError
@@ -402,7 +402,7 @@ class MenshenAuthentication(authentication.BaseAuthentication):
try:
response = client.introspect(IntrospectionRequest(token=token))
except (requests.RequestException, ResponseParsingError) as e:
except (httpx2.HTTPError, ResponseParsingError) as e:
logger.warning("Menshen introspection failed: %s", e)
return None
+16
View File
@@ -107,6 +107,22 @@ class UserRecordingAccessFactory(factory.django.DjangoModelFactory):
role = factory.fuzzy.FuzzyChoice(models.RoleChoices.values)
class RecordingDeliveryFactory(factory.django.DjangoModelFactory):
"""Create fake recording deliveries for testing, pushing to Drive by default.
No token is set: use `set_token` on the delivery.
"""
class Meta:
model = models.RecordingDelivery
recording = factory.SubFactory(RecordingFactory)
user = factory.SubFactory(UserFactory)
method = models.RecordingDeliveryMethodChoices.DRIVE
status = models.RecordingDeliveryStatusChoices.PENDING
token_type = models.DriveTokenTypeChoices.ACCESS_TOKEN
class TeamRecordingAccessFactory(factory.django.DjangoModelFactory):
"""Create fake recording team accesses for testing."""
@@ -0,0 +1,38 @@
# Generated by Django 5.2.17 on 2026-11-19 14:59
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0029_alter_application_client_secret_sha256'),
]
operations = [
migrations.CreateModel(
name='RecordingDelivery',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
('method', models.CharField(choices=[('s3_email', 'Object storage, with an email'), ('drive', 'Drive')], max_length=20, verbose_name='Delivery method')),
('status', models.CharField(choices=[('pending', 'Pending'), ('pushing', 'Pushing'), ('uploaded', 'Uploaded, not shared with everyone'), ('delivered', 'Delivered'), ('failed', 'Failed')], default='pending', max_length=20, verbose_name='Delivery status')),
('token_type', models.CharField(blank=True, choices=[('token_exchange', 'Token exchanged with Menshen'), ('access_token', 'OIDC access token')], max_length=20, null=True, verbose_name='Token type')),
('token', models.TextField(blank=True, editable=False, help_text='Encrypted token to call Drive on behalf of the user who started the recording. Dropped once the push is over.', null=True, verbose_name='Token')),
('token_expires_at', models.DateTimeField(blank=True, null=True, verbose_name='Token expiration')),
('drive_item_id', models.UUIDField(blank=True, null=True, verbose_name='Drive item ID')),
('error', models.TextField(blank=True, default='', verbose_name='Last error')),
('recording', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='delivery', to='core.recording', verbose_name='Recording')),
('user', models.ForeignKey(blank=True, help_text='User who started the recording, on whose behalf it is delivered.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='User')),
],
options={
'verbose_name': 'Recording delivery',
'verbose_name_plural': 'Recording deliveries',
'db_table': 'meet_recording_delivery',
},
),
]
+137
View File
@@ -107,6 +107,30 @@ class RecordingModeChoices(models.TextChoices):
TRANSCRIPT = "transcript", _("TRANSCRIPT")
class RecordingDeliveryMethodChoices(models.TextChoices):
"""Where a finished video recording is made available to its users."""
S3_EMAIL = "s3_email", _("Object storage, with an email")
DRIVE = "drive", _("Drive")
class RecordingDeliveryStatusChoices(models.TextChoices):
"""Progress of a recording delivery."""
PENDING = "pending", _("Pending")
PUSHING = "pushing", _("Pushing")
UPLOADED = "uploaded", _("Uploaded, not shared with everyone")
DELIVERED = "delivered", _("Delivered")
FAILED = "failed", _("Failed")
class DriveTokenTypeChoices(models.TextChoices):
"""Kind of token Meet calls Drive with on behalf of the user."""
TOKEN_EXCHANGE = "token_exchange", _("Token exchanged with Menshen")
ACCESS_TOKEN = "access_token", _("OIDC access token")
class RoomAccessLevel(models.TextChoices):
"""Room access level choices."""
@@ -848,6 +872,119 @@ class Recording(BaseModel):
return self.expired_at < timezone.now()
class RecordingDelivery(BaseModel):
"""How a finished recording is made available to the user.
To push to Drive, the credential needed to call it on behalf of the starter
is obtained when the recording starts and stored here, encrypted, until
the push is over.
"""
recording = models.OneToOneField(
Recording,
on_delete=models.CASCADE,
related_name="delivery",
verbose_name=_("Recording"),
)
user = models.ForeignKey(
User,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="+",
verbose_name=_("User"),
help_text=_("User who started the recording, on whose behalf it is delivered."),
)
method = models.CharField(
max_length=20,
choices=RecordingDeliveryMethodChoices.choices,
verbose_name=_("Delivery method"),
)
status = models.CharField(
max_length=20,
choices=RecordingDeliveryStatusChoices.choices,
default=RecordingDeliveryStatusChoices.PENDING,
verbose_name=_("Delivery status"),
)
token_type = models.CharField(
max_length=20,
choices=DriveTokenTypeChoices.choices,
null=True,
blank=True,
verbose_name=_("Token type"),
)
token = models.TextField(
null=True,
blank=True,
editable=False,
verbose_name=_("Token"),
help_text=_(
"Encrypted token to call Drive on behalf of the user who started the "
"recording. Dropped once the push is over."
),
)
token_expires_at = models.DateTimeField(
null=True,
blank=True,
verbose_name=_("Token expiration"),
)
drive_item_id = models.UUIDField(
null=True,
blank=True,
verbose_name=_("Drive item ID"),
)
error = models.TextField(
blank=True,
default="",
verbose_name=_("Last error"),
)
class Meta:
db_table = "meet_recording_delivery"
verbose_name = _("Recording delivery")
verbose_name_plural = _("Recording deliveries")
def __str__(self):
return (
f"Delivery of recording {self.recording_id} ({self.method}, {self.status})"
)
def set_token(self, value: str, expires_at: Optional[datetime]) -> None:
"""Keep the token, encrypted, without saving."""
self.token = utils.encrypt_secret(value)
self.token_expires_at = expires_at
def get_token(self) -> Optional[str]:
"""Return the stored token, or None if there is none left."""
if not self.token:
return None
try:
return utils.decrypt_secret(self.token)
except utils.SecretDecryptionError:
logger.exception("Could not decrypt the token of delivery %s", self.id)
return None
@property
def is_token_expired(self) -> bool:
"""Tell whether the stored token is known to be expired."""
return (
self.token_expires_at is not None
and self.token_expires_at <= timezone.now()
)
@property
def drive_url(self) -> Optional[str]:
"""Return the link to the file in Drive's interface, once it is there."""
if not self.drive_item_id or not settings.DRIVE_FRONTEND_BASE_URL:
return None
base_url = settings.DRIVE_FRONTEND_BASE_URL.rstrip("/")
return f"{base_url}/explorer/items/files/{self.drive_item_id}"
class RecordingAccess(BaseAccess):
"""Relation model to give access to a recording for a user or a team with a role."""
@@ -0,0 +1 @@
"""Make finished recordings available to their users."""
@@ -0,0 +1,152 @@
"""Tokens Meet calls Drive with, on behalf of the user who started a recording.
A token is obtained while the user is around, when the recording starts, and
used once the recording is over, from a worker. Each type of token has its
provider: how to obtain it from the request, and how to let go of it.
"""
import logging
from dataclasses import dataclass
from datetime import datetime, timedelta
from django.conf import settings
from django.utils import timezone
import httpx2
from menshen_client import (
Configuration,
RevocationRequest,
TokenExchangeClient,
TokenExchangeRequest,
TokenType,
)
from menshen_client.exceptions import ResponseParsingError
from core.models import DriveTokenTypeChoices
logger = logging.getLogger(__name__)
# Timeout of Menshen calls, in seconds: the exchange happens while the user
# waits for the recording to start.
MENSHEN_TIMEOUT = 10.0
class CredentialError(Exception):
"""Raised when a token to call Drive cannot be obtained."""
@dataclass(frozen=True)
class Credential:
"""A token to call Drive with, and when it expires if known."""
value: str
expires_at: datetime | None = None
class CredentialProvider:
"""Obtain, then let go of, one type of token."""
token_type: str
def acquire(self, request) -> Credential:
"""Obtain a token from the request of the user starting the recording."""
raise NotImplementedError
def release(self, token: str) -> None:
"""Let go of a token that will not be used anymore."""
def _get_session_access_token(request) -> str:
"""Return the user's OIDC access token, kept in their session."""
access_token = request.session.get("oidc_access_token")
if not access_token:
raise CredentialError(
"No OIDC access token in the session. Is OIDC_STORE_ACCESS_TOKEN enabled?"
)
return access_token
class AccessTokenProvider(CredentialProvider):
"""Use the user's OIDC access token itself.
Its expiration is not known: it is assumed to still be valid when the
recording is over, Drive refuses it otherwise.
"""
token_type = DriveTokenTypeChoices.ACCESS_TOKEN
def acquire(self, request) -> Credential:
"""Return the access token of the session."""
return Credential(_get_session_access_token(request))
def get_menshen_client() -> TokenExchangeClient:
"""Return a client for Menshen, authenticated as Meet. Close it after use."""
return TokenExchangeClient(
config=Configuration(
settings.MENSHEN_CLIENT_ID,
settings.MENSHEN_CLIENT_SECRET,
settings.MENSHEN_SERVER_URL,
requests_timeout=MENSHEN_TIMEOUT,
)
)
class TokenExchangeProvider(CredentialProvider):
"""Exchange the user's access token with Menshen for a token targeting Drive.
The exchanged token lasts as long as Menshen's exchange rule says, which is
meant to outlast the recording, and is revoked once the push is over.
"""
token_type = DriveTokenTypeChoices.TOKEN_EXCHANGE
def acquire(self, request) -> Credential:
"""Exchange the access token of the session."""
exchange_request = TokenExchangeRequest(
subject_token=_get_session_access_token(request),
subject_token_type=TokenType.ACCESS_TOKEN,
audience=settings.RECORDING_DRIVE_AUDIENCE,
scope=settings.RECORDING_DRIVE_SCOPE or None,
)
try:
with get_menshen_client() as client:
response = client.exchange(exchange_request)
except (httpx2.HTTPError, ResponseParsingError) as exc:
raise CredentialError(f"Menshen token exchange failed: {exc}") from exc
return Credential(
response.access_token,
timezone.now() + timedelta(seconds=response.expires_in),
)
def release(self, token: str) -> None:
"""Revoke the exchanged token, it is not needed anymore."""
try:
with get_menshen_client() as client:
client.revoke(
RevocationRequest(
token=token, token_type_hint=TokenType.ACCESS_TOKEN
)
)
except httpx2.HTTPError:
# It expires on its own anyway
logger.warning("Could not revoke an exchanged token", exc_info=True)
PROVIDERS: dict[str, CredentialProvider] = {
DriveTokenTypeChoices.ACCESS_TOKEN: AccessTokenProvider(),
DriveTokenTypeChoices.TOKEN_EXCHANGE: TokenExchangeProvider(),
}
def get_provider(token_type: str) -> CredentialProvider:
"""Return the provider of a type of token."""
return PROVIDERS[token_type]
@@ -0,0 +1,292 @@
"""Push a finished recording to the Drive of the user who started it.
The recording is streamed from the object storage to Drive, into a dedicated
folder, then shared with the room's owners and administrators, as copied when
the recording started. Only the starter is emailed. Nothing falls back to the
download email when the push fails: the object storage copy stays until it
expires.
"""
import logging
import time
from django.conf import settings
from django.utils.translation import get_language, gettext_noop
import requests
from celery.exceptions import OperationalError as CeleryOperationalError
from core import audit, auditing, models, utils
from core.recording.delivery.credentials import get_provider
from core.services.drive import API_TIMEOUT, DriveClient, DriveError
from core.tasks.mail import send_email
logger = logging.getLogger(__name__)
# (connect, read) timeouts for the download, in seconds. The read one has to
# accommodate a whole recording being relayed.
DOWNLOAD_TIMEOUT = (API_TIMEOUT[0], 1800)
# Role the room's owners and administrators get on the pushed file.
SHARE_ROLE = "owner"
def release_token(delivery: models.RecordingDelivery) -> None:
"""Let go of the delivery's token, without saving: it is a user credential.
The token is dropped even if releasing it with its provider fails.
"""
token = delivery.get_token()
if token and delivery.token_type:
try:
get_provider(delivery.token_type).release(token)
except Exception: # noqa: BLE001 # pylint: disable=broad-exception-caught
logger.warning(
"Could not release the token of recording %s",
delivery.recording_id,
exc_info=True,
)
delivery.token = None
delivery.token_expires_at = None
def audit_push(delivery: models.RecordingDelivery, *, error=None, **details) -> None:
"""Record the outcome of a push to Drive."""
outcome = audit.Outcome.SUCCESS
reason = None
if error is not None:
outcome = audit.Outcome.FAILURE
reason = (
audit.Reason.AUTHENTICATION_FAILED
if getattr(error, "status_code", None) in (401, 403)
else audit.Reason.INTERNAL_ERROR
)
audit.log(
auditing.RECORDING_DRIVE_PUSH,
actor=None,
actor_type=audit.ActorType.SYSTEM,
target=delivery.recording,
target_service="drive",
outcome=outcome,
reason=reason,
error=str(error) if error is not None else None,
token_type=delivery.token_type,
**details,
)
def fail(delivery: models.RecordingDelivery, error) -> None:
"""Clean up and log after pushing recording has failed. Notify the audit log.
A recording already uploaded stays UPLOADED: it is in Drive, only sharing
or announcing it failed.
"""
logger.error(
"Failed to push recording %s to Drive: %s", delivery.recording_id, error
)
release_token(delivery)
if delivery.status != models.RecordingDeliveryStatusChoices.UPLOADED:
delivery.status = models.RecordingDeliveryStatusChoices.FAILED
delivery.error = str(error)
delivery.save()
audit_push(delivery, error=error)
def build_filename(recording: models.Recording, user) -> str:
"""Return the name of the file in Drive, dated in the user's timezone."""
created_at = recording.created_at
if user is not None:
created_at = created_at.astimezone(user.timezone)
return f"{recording.room.slug}-{created_at:%Y-%m-%d-%H-%M}.{recording.extension}"
def get_or_create_folder(drive: DriveClient) -> dict:
"""Return the user's recordings folder, at the root of their Drive."""
name = settings.RECORDING_DRIVE_FOLDER_NAME
return drive.find_root_folder(name) or drive.create_folder(name)
def upload(drive: DriveClient, recording: models.Recording, filename, parent_id) -> str:
"""Stream the recording from the object storage to a new file, return its ID.
The recording is never held as a whole in memory or on disk. A file left
incomplete by a failure is deleted, if Drive allows it.
"""
download_url = utils.generate_download_s3_url(
recording.key,
expires_in=settings.RECORDING_DRIVE_SIGNED_URL_EXPIRY_SECONDS,
override_domain=False,
)
download_error = "Could not download the recording from the object storage"
try:
download = requests.get(download_url, stream=True, timeout=DOWNLOAD_TIMEOUT)
except requests.RequestException as exc:
raise DriveError.from_request_exception(download_error, exc) from exc
with download:
try:
download.raise_for_status()
except requests.RequestException as exc:
raise DriveError.from_request_exception(download_error, exc) from exc
content_length = download.headers.get("Content-Length")
if content_length is None:
raise DriveError(
"Object storage did not return the recording size, "
"cannot stream it to Drive."
)
item = drive.create_file(filename=filename, parent_id=parent_id)
try:
drive.upload_content(
policy_url=item["policy"],
stream=download.raw,
content_length=int(content_length),
content_type=download.headers.get(
"Content-Type", "application/octet-stream"
),
)
drive.complete_upload(item["id"])
except DriveError:
try:
drive.delete_item(item["id"])
except DriveError:
logger.warning(
"Could not delete the incomplete Drive item %s of recording %s",
item["id"],
recording.id,
)
raise
return item["id"]
def get_share_recipients(delivery: models.RecordingDelivery) -> list[str]:
"""Return the emails to share the file with: the recording owners but the starter.
Recording owners are the room's owners and administrators when the
recording started, see `Recording.grant_initial_accesses`.
"""
accesses = (
models.RecordingAccess.objects.filter(
recording_id=delivery.recording_id,
role=models.RoleChoices.OWNER,
user__isnull=False,
)
.exclude(user_id=delivery.user_id)
.select_related("user")
.order_by("created_at")
)
return [access.user.email for access in accesses if access.user.email]
def share(drive: DriveClient, delivery: models.RecordingDelivery) -> list[str]:
"""Share the file with the recording owners, return the emails it failed for."""
failures = []
for email in get_share_recipients(delivery):
try:
drive.share_with_email(str(delivery.drive_item_id), email, SHARE_ROLE)
except DriveError as exc:
logger.warning(
"Could not share recording %s with %s in Drive: %s",
delivery.recording_id,
email,
exc,
)
failures.append(email)
return failures
def notify_starter(delivery: models.RecordingDelivery) -> None:
"""Email the user who started the recording a link to the file in Drive."""
user = delivery.user
if user is None or not user.email:
logger.warning("No one to tell recording %s is in Drive", delivery.recording_id)
return
recording = delivery.recording
local_created_at = recording.created_at.astimezone(user.timezone)
try:
send_email.delay(
template="recording_saved_to_drive",
subject=gettext_noop("Your recording is in your Drive"),
recipients=[user.email],
language=user.language or get_language(),
context={
"room_name": recording.room.name,
"recording_date": local_created_at.strftime("%Y-%m-%d"),
"recording_time": local_created_at.strftime("%H:%M"),
"folder_name": settings.RECORDING_DRIVE_FOLDER_NAME,
"link": delivery.drive_url,
},
)
except (OSError, CeleryOperationalError):
logger.exception(
"Could not email the starter of recording %s", delivery.recording_id
)
def push(delivery: models.RecordingDelivery) -> None:
"""Push the recording to Drive, share it, then email the starter.
Raises:
DriveError: the recording is not in Drive. The token is kept, to try
again later.
"""
token = delivery.get_token()
if token is None:
raise DriveError("No token left to call Drive with.")
if delivery.is_token_expired:
raise DriveError("The token to call Drive with has expired.")
recording = delivery.recording
with DriveClient(token) as drive:
folder = get_or_create_folder(drive)
delivery.drive_item_id = upload(
drive, recording, build_filename(recording, delivery.user), folder["id"]
)
delivery.status = models.RecordingDeliveryStatusChoices.UPLOADED
delivery.error = ""
delivery.save()
share_failures = share(drive, delivery)
release_token(delivery)
if share_failures:
delivery.error = f"Could not share with: {', '.join(share_failures)}"
else:
delivery.status = models.RecordingDeliveryStatusChoices.DELIVERED
delivery.save()
logger.info(
"Recording %s pushed to Drive (item %s)",
recording.id,
delivery.drive_item_id,
)
audit_push(
delivery,
drive_item_id=str(delivery.drive_item_id),
share_failures=len(share_failures) or None,
)
notify_starter(delivery)
@@ -0,0 +1,135 @@
"""Choose how a recording is delivered when it starts, carry it out when it ends.
Only video recordings are concerned: an audio-only transcript ends up in Docs,
through the summary service. A video recording without a delivery, started
before deliveries existed, is delivered by email.
"""
import logging
from django.conf import settings
from django.utils import timezone
from celery.exceptions import OperationalError as CeleryOperationalError
from core import audit, auditing, models
from core.recording.delivery.credentials import CredentialError, get_provider
from core.recording.delivery.drive import release_token
from core.tasks.push_recording import push_recording_to_drive
logger = logging.getLogger(__name__)
Method = models.RecordingDeliveryMethodChoices
Status = models.RecordingDeliveryStatusChoices
def prepare(request, recording: models.Recording) -> models.RecordingDelivery | None:
"""Pick how a recording that starts will be delivered, and get what it needs.
Pushing to Drive needs a token to call it on behalf of the user, obtained
now, while they are around. When it cannot be, the recording still starts,
but will not be delivered: nothing falls back to the email.
"""
if recording.mode != models.RecordingModeChoices.SCREEN_RECORDING:
return None
delivery = models.RecordingDelivery(
recording=recording,
user=request.user,
method=settings.RECORDING_STORAGE_METHOD,
)
if delivery.method == Method.DRIVE:
delivery.token_type = settings.RECORDING_DRIVE_AUTH_METHOD
try:
credential = get_provider(delivery.token_type).acquire(request)
except CredentialError as exc:
logger.warning(
"Recording %s will not be pushed to Drive: %s", recording.id, exc
)
delivery.status = Status.FAILED
delivery.error = str(exc)
audit.log(
auditing.RECORDING_DRIVE_PUSH,
target=recording,
target_service="drive",
outcome=audit.Outcome.FAILURE,
reason=audit.Reason.AUTHENTICATION_FAILED,
error=str(exc),
token_type=delivery.token_type,
)
else:
delivery.set_token(credential.value, credential.expires_at)
delivery.save()
return delivery
def get_method(recording: models.Recording) -> str:
"""Return how a finished video recording is delivered."""
try:
return recording.delivery.method
except models.RecordingDelivery.DoesNotExist:
return Method.S3_EMAIL
def dispatch_to_drive(recording: models.Recording) -> bool:
"""Hand the push of a finished recording over to a worker.
Returns whether the recording is in Drive or on its way there.
"""
delivery = recording.delivery
if delivery.status == Status.FAILED:
logger.warning(
"Recording %s cannot be pushed to Drive: %s", recording.id, delivery.error
)
return False
# Only a PENDING delivery is pushed, so it can never be pushed
# twice, e.g. if an administrator resends the notifications of a recording.
claimed = models.RecordingDelivery.objects.filter(
pk=delivery.pk, status=Status.PENDING
).update(status=Status.PUSHING, updated_at=timezone.now())
if not claimed:
logger.info(
"Recording %s is already %s, not pushing it to Drive again",
recording.id,
delivery.status,
)
return True
try:
push_recording_to_drive.delay(str(recording.id))
except CeleryOperationalError:
logger.exception(
"Could not schedule the Drive push of recording %s", recording.id
)
# Keep the token: resending the notification tries again
models.RecordingDelivery.objects.filter(pk=delivery.pk).update(
status=Status.PENDING, updated_at=timezone.now()
)
return False
return True
def abandon(recording: models.Recording, reason: str) -> None:
"""Update delivery status and release token."""
try:
delivery = recording.delivery
except models.RecordingDelivery.DoesNotExist:
return
if delivery.status != Status.PENDING:
return
release_token(delivery)
delivery.status = Status.FAILED
delivery.error = reason
delivery.save()
@@ -17,6 +17,7 @@ from livekit import api as livekit_api
from core import audit, auditing, models, utils
from core.analytics import UserFeatureFlag, is_user_feature_flag_enabled
from core.recording.delivery import service as delivery_service
from core.tasks.mail import send_email
from core.utils import generate_download_s3_url
@@ -54,8 +55,8 @@ class NotificationService:
if recording.is_transcribed:
summary_success = self._notify_summary_service(recording)
email_success = self._notify_user_by_email(recording)
return email_success and summary_success
delivery_success = self._deliver_recording(recording)
return delivery_success and summary_success
logger.error(
"Unknown recording mode %s for recording %s",
@@ -239,6 +240,18 @@ class NotificationService:
)
return oldest_access.user if oldest_access else None
@classmethod
def _deliver_recording(cls, recording: models.Recording) -> bool:
"""Make a video recording available, by the method chosen when it started."""
if (
delivery_service.get_method(recording)
== models.RecordingDeliveryMethodChoices.DRIVE
):
return delivery_service.dispatch_to_drive(recording)
return cls._notify_user_by_email(recording)
@staticmethod
def _notify_summary_service_v1(recording: models.Recording):
"""Notify summary service about a new recording."""
@@ -4,6 +4,7 @@ from logging import getLogger
from core import models, utils
from core.models import Recording
from core.recording.delivery import service as delivery_service
from core.recording.enums import (
UNSUCCESSFUL_EVENTS,
RecordingWorkerEvent,
@@ -260,6 +261,7 @@ class RecordingEventsService:
"""
recording.status = models.RecordingStatusChoices.FAILED
recording.save()
delivery_service.abandon(recording, "The recording failed.")
cls._notify_participants(recording, RecordingWorkerEvent.FAILED)
@@ -272,6 +274,7 @@ class RecordingEventsService:
"""
recording.status = models.RecordingStatusChoices.ABORTED
recording.save()
delivery_service.abandon(recording, "The recording was aborted.")
cls._notify_participants(recording, RecordingWorkerEvent.ABORTED)
@@ -293,4 +296,4 @@ class RecordingEventsService:
if notification_succeeded
else models.RecordingStatusChoices.SAVED
)
recording.save()
recording.save(update_fields=["status", "updated_at"])
+281
View File
@@ -0,0 +1,281 @@
"""Client for La Suite Drive's external API (resource server).
Drive exposes `/external_api/v1.0/*` to applications calling it on behalf of a
user, with either the user's OIDC access token or a token exchanged with Menshen.
See https://github.com/suitenumerique/drive/blob/main/docs/resource_server.md
"""
import logging
from urllib.parse import urlparse, urlunparse
from django.conf import settings
import requests
logger = logging.getLogger(__name__)
# (connect, read) timeouts, in seconds. The upload one covers a
# whole recording being relayed to Drive's object storage.
API_TIMEOUT = (10, 30)
UPLOAD_TIMEOUT = (10, 1800)
class DriveError(Exception):
"""Raised when Drive's external API cannot fulfill a request."""
def __init__(self, message: str, *, status_code=None):
super().__init__(message)
self.status_code = status_code
@classmethod
def from_request_exception(cls, message: str, exc: requests.RequestException):
"""Build the error from a failed `requests` call, with its status code."""
response = getattr(exc, "response", None)
if response is None:
# No answer at all: connection error, timeout...
return cls(message)
status_code = response.status_code
return cls(f"{message} ({status_code})", status_code=status_code)
class SizedStream:
"""Read-only byte stream of a known size, suitable as a `requests` body.
`requests` falls back to a chunked transfer encoding when it cannot guess the
body size upfront, which presigned S3 uploads reject. Advertising the size
through `__len__` makes it send a plain `Content-Length` instead, while the
underlying stream is still consumed chunk by chunk.
"""
def __init__(self, stream, length: int):
"""Wrap `stream`, whose full content is `length` bytes long."""
self._stream = stream
self._length = length
def __len__(self) -> int:
"""Return the total size of the stream, in bytes."""
return self._length
def __iter__(self):
"""Iterate over the stream, required for `requests` to stream the body."""
return iter(self._stream)
def read(self, amt=None) -> bytes:
"""Read up to `amt` bytes from the stream."""
return self._stream.read(amt)
class DriveClient:
"""Access Drive's external API on behalf of a user.
The client is bound to a single user token: every call is performed as that
user, and Drive applies its own permissions accordingly.
"""
def __init__(self, token: str, *, base_url: str | None = None):
"""Prepare a session authenticated with the user's token."""
self._base_url = (base_url or settings.DRIVE_API_BASE_URL or "").rstrip("/")
if not self._base_url:
raise DriveError(
"Drive API is not configured, set DRIVE_API_BASE_URL to enable it."
)
if not token:
raise DriveError("A token is required to call Drive.")
self._session = requests.Session()
self._session.headers.update(
{
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
}
)
def __enter__(self):
"""Allow use as a context manager, closing the session on exit."""
return self
def __exit__(self, *args):
"""Close the underlying HTTP session."""
self.close()
def close(self):
"""Release the underlying HTTP session."""
self._session.close()
def _request(self, method, path, **kwargs):
"""Perform an authenticated call to the external API and return its body."""
url = f"{self._base_url}{path}"
kwargs.setdefault("timeout", API_TIMEOUT)
try:
response = self._session.request(method, url, **kwargs)
response.raise_for_status()
except requests.RequestException as exc:
raise DriveError.from_request_exception(
f"Drive call failed: {method} {path}", exc
) from exc
if not response.content:
return None
try:
return response.json()
except ValueError as exc:
raise DriveError(f"Drive returned a non-JSON body for {path}") from exc
def find_root_folder(self, title: str) -> dict | None:
"""Return the folder titled `title` the user created at the root of Drive.
Drive's title filter is a case-insensitive "contains" match, and the
listing also holds items shared with the user: keep only an exact match,
at the root, created by the user.
"""
body = self._request(
"GET",
"/items/",
params={"type": "folder", "title": title, "is_creator_me": "true"},
)
items = body.get("results", []) if isinstance(body, dict) else body or []
return next(
(
item
for item in items
if item.get("type") == "folder"
and item.get("title") == title
and item.get("depth") == 1
),
None,
)
def create_folder(self, title: str) -> dict:
"""Create a folder at the root of the user's Drive and return it."""
return self._request("POST", "/items/", json={"type": "folder", "title": title})
def create_file(self, *, filename: str, parent_id: str | None = None) -> dict:
"""Create a file item, in `parent_id` or at the root, and return it.
The returned item carries a `policy`: the presigned URL the content has
to be uploaded to.
"""
path = f"/items/{parent_id}/children/" if parent_id else "/items/"
item = self._request("POST", path, json={"type": "file", "filename": filename})
if not item or not item.get("policy"):
raise DriveError(
f"Drive did not return an upload policy for file '{filename}'."
)
return item
def delete_item(self, item_id: str) -> None:
"""Delete an item, which Drive moves to the user's trash.
Requires the `destroy` action on items in Drive's EXTERNAL_API setting.
"""
self._request("DELETE", f"/items/{item_id}/")
@staticmethod
def _resolve_upload_target(policy_url: str) -> tuple[str, str | None]:
"""Return the address to connect to, and the `Host` header to send.
Drive signs its upload URLs with the object storage domain meant for
browsers, which may not resolve from dev split docker compose setup.
The signature covers the `Host` header, so we swap the address we connect
to but keep announcing the original host.
"""
override = settings.DRIVE_UPLOAD_STORAGE_NETLOC
if not override:
return policy_url, None
parsed = urlparse(policy_url)
return urlunparse(parsed._replace(netloc=override)), parsed.netloc
def upload_content(self, *, policy_url: str, stream, content_length, content_type):
"""Push `stream` to the presigned URL, without buffering it as a whole."""
url, host_header = self._resolve_upload_target(policy_url)
headers = {
"Content-Type": content_type,
"Content-Length": str(content_length),
"x-amz-acl": "private",
}
if host_header:
headers["Host"] = host_header
try:
# A bare `requests.put`, not the authenticated session: the presigned
# URL carries its own credentials
response = requests.put(
url,
data=SizedStream(stream, content_length),
headers=headers,
timeout=UPLOAD_TIMEOUT,
)
response.raise_for_status()
except requests.RequestException as exc:
raise DriveError.from_request_exception(
"Upload to Drive's object storage failed", exc
) from exc
def complete_upload(self, item_id: str) -> None:
"""Inform Drive that the upload is over, making the file available."""
self._request("POST", f"/items/{item_id}/upload-ended/", json={})
def find_user_by_email(self, email: str) -> dict | None:
"""Return the active Drive user with this exact email, if any.
Drive's user search tolerates typos in emails: the returned emails are
compared with the expected one, ignoring case.
"""
users = self._request("GET", "/users/", params={"q": email}) or []
expected = email.casefold()
return next(
(
user
for user in users
if (user.get("email") or "").casefold() == expected
),
None,
)
def share_with_email(self, item_id: str, email: str, role: str) -> None:
"""Give `role` on an item to the Drive user with this email.
An existing user gets an access, an email with no Drive account yet gets
an invitation, turned into an access when they first log in. Drive emails
them in both cases.
"""
user = self.find_user_by_email(email)
if user:
self._request(
"POST",
f"/items/{item_id}/accesses/",
json={"user_id": user["id"], "role": role},
)
else:
self._request(
"POST",
f"/items/{item_id}/invitations/",
json={"email": email, "role": role},
)
+8 -1
View File
@@ -1,11 +1,18 @@
"""Celery tasks for the core app."""
"""Asynchronous tasks of the core application.
Importing the task modules here is what makes Celery's `autodiscover_tasks`
register them: it only imports the `core.tasks` package itself, never its
submodules.
"""
from core.tasks.connection_test import delete_connection_test_room
from core.tasks.file import process_file_deletion
from core.tasks.mail import send_email
from core.tasks.push_recording import push_recording_to_drive
__all__ = (
"delete_connection_test_room",
"process_file_deletion",
"push_recording_to_drive",
"send_email",
)
+82
View File
@@ -0,0 +1,82 @@
"""Task pushing a finished recording to the Drive of the user who started it."""
import logging
from django.conf import settings
from celery.exceptions import OperationalError as CeleryOperationalError
from core import models
from core.recording.delivery import drive
from core.services.drive import DriveError
from core.tasks._task import task
logger = logging.getLogger(__name__)
# Delay before the first new attempt, in seconds, doubled at each attempt.
RETRY_BASE_DELAY = 60
@task
def push_recording_to_drive(recording_id: str, attempt: int = 1) -> bool:
"""Push a recording to Drive, see `core.recording.delivery.drive`.
When the push fails, it is tried again later, by queuing this task again,
up to RECORDING_DRIVE_PUSH_MAX_ATTEMPTS times and while the token is valid.
"""
try:
delivery = models.RecordingDelivery.objects.select_related(
"recording__room", "user"
).get(recording_id=recording_id)
except models.RecordingDelivery.DoesNotExist:
logger.error("Recording %s has no delivery, cannot push it", recording_id)
return False
if delivery.status != models.RecordingDeliveryStatusChoices.PUSHING:
logger.info(
"Delivery of recording %s is %s, nothing to push",
recording_id,
delivery.status,
)
return False
try:
drive.push(delivery)
except DriveError as exc:
if (
attempt < settings.RECORDING_DRIVE_PUSH_MAX_ATTEMPTS
and not delivery.is_token_expired
):
delay = RETRY_BASE_DELAY * 2 ** (attempt - 1)
logger.warning(
"Push of recording %s to Drive failed (attempt %d), "
"trying again in %ds: %s",
recording_id,
attempt,
delay,
exc,
)
delivery.error = str(exc)
delivery.save(update_fields=["error", "updated_at"])
try:
push_recording_to_drive.apply_async(
args=(recording_id,),
kwargs={"attempt": attempt + 1},
countdown=delay,
)
except CeleryOperationalError as queue_exc:
drive.fail(delivery, queue_exc)
return False
drive.fail(delivery, exc)
return False
except Exception as exc: # noqa: BLE001 # pylint: disable=broad-exception-caught
# Not worth trying again, but the delivery must not stay PUSHING:
# nothing would ever push it again nor release its token.
logger.exception("Unexpected error pushing recording %s to Drive", recording_id)
drive.fail(delivery, exc)
return False
return True
+11
View File
@@ -3,9 +3,11 @@
from unittest import mock
import pytest
from cryptography.fernet import Fernet
from dockerflow.logging import request_id_context
from core.audit.testing import capture_audit
from core.utils import get_cipher_suite
USER = "user"
TEAM = "team"
@@ -19,6 +21,15 @@ def mock_user_get_teams():
yield mock_get_teams
@pytest.fixture
def encryption_key(settings):
"""Configure the key encrypting tokens at rest, e.g. on recording deliveries."""
settings.OIDC_STORE_REFRESH_TOKEN_KEY = Fernet.generate_key().decode()
get_cipher_suite.cache_clear()
yield settings.OIDC_STORE_REFRESH_TOKEN_KEY
get_cipher_suite.cache_clear()
@pytest.fixture
def audit_events():
"""Collect the audit events emitted during the test, as dicts."""
@@ -0,0 +1,180 @@
"""Tests for the tokens Meet calls Drive with, on behalf of a recording's starter."""
# pylint: disable=redefined-outer-name
from datetime import datetime, timedelta, timezone
from types import SimpleNamespace
from urllib.parse import parse_qs
import httpx2
import pytest
from freezegun import freeze_time
from core.models import DriveTokenTypeChoices
from core.recording.delivery.credentials import (
MENSHEN_TIMEOUT,
AccessTokenProvider,
CredentialError,
TokenExchangeProvider,
get_menshen_client,
get_provider,
)
SERVER_URL = "https://menshen.example.com"
EXCHANGE_ENDPOINT = f"{SERVER_URL}/auth/token/exchange/"
REVOCATION_ENDPOINT = f"{SERVER_URL}/auth/token/revoke/"
@pytest.fixture(autouse=True)
def menshen_settings(settings):
"""Configure Menshen, and Drive's audience there."""
settings.MENSHEN_SERVER_URL = SERVER_URL
settings.MENSHEN_CLIENT_ID = "meet"
settings.MENSHEN_CLIENT_SECRET = "meet-secret"
settings.RECORDING_DRIVE_AUDIENCE = "drive"
settings.RECORDING_DRIVE_SCOPE = None
def make_request(access_token="user-access-token"):
"""Return a request whose session holds the user's access token, if any."""
session = {"oidc_access_token": access_token} if access_token else {}
return SimpleNamespace(session=session)
def exchange_response(**overrides):
"""Return a successful token exchange response body."""
return {
"access_token": "exchanged-token",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"token_type": "bearer",
"expires_in": 7200,
"grants": [],
**overrides,
}
def test_get_provider():
"""Each token type has its provider."""
assert isinstance(
get_provider(DriveTokenTypeChoices.ACCESS_TOKEN), AccessTokenProvider
)
assert isinstance(
get_provider(DriveTokenTypeChoices.TOKEN_EXCHANGE), TokenExchangeProvider
)
def test_access_token_acquire():
"""The access token of the session is used as is, its expiration unknown."""
credential = AccessTokenProvider().acquire(make_request())
assert credential.value == "user-access-token"
assert credential.expires_at is None
def test_access_token_acquire_missing():
"""Without an access token in the session, there is no credential."""
with pytest.raises(CredentialError, match="OIDC_STORE_ACCESS_TOKEN"):
AccessTokenProvider().acquire(make_request(access_token=None))
def test_access_token_release_calls_nothing(httpx2_mock):
"""An access token is not revoked: it belongs to the user's session."""
AccessTokenProvider().release("user-access-token")
assert not httpx2_mock.get_requests()
def test_menshen_client_has_a_timeout():
"""The exchange happens while the user waits: Menshen calls are bounded."""
with get_menshen_client() as client:
assert client.config.requests_timeout == MENSHEN_TIMEOUT
@freeze_time("2026-11-19 10:00:00")
def test_token_exchange_acquire(httpx2_mock):
"""The access token of the session is exchanged for a token targeting Drive."""
httpx2_mock.add_response(
method="POST", url=EXCHANGE_ENDPOINT, json=exchange_response()
)
credential = TokenExchangeProvider().acquire(make_request())
assert credential.value == "exchanged-token"
assert credential.expires_at == datetime(
2026, 11, 19, 10, 0, tzinfo=timezone.utc
) + timedelta(seconds=7200)
request = httpx2_mock.get_request()
assert request.headers["Authorization"].startswith("Basic ")
assert parse_qs(request.content.decode()) == {
"subject_token": ["user-access-token"],
"subject_token_type": ["urn:ietf:params:oauth:token-type:access_token"],
"grant_type": ["urn:ietf:params:oauth:grant-type:token-exchange"],
"audience": ["drive"],
}
def test_token_exchange_acquire_with_scope(httpx2_mock, settings):
"""Configured scopes are asked for."""
settings.RECORDING_DRIVE_SCOPE = "drive:item:create drive:item:upload-ended"
httpx2_mock.add_response(
method="POST", url=EXCHANGE_ENDPOINT, json=exchange_response()
)
TokenExchangeProvider().acquire(make_request())
form = parse_qs(httpx2_mock.get_request().content.decode())
assert form["scope"] == ["drive:item:create drive:item:upload-ended"]
def test_token_exchange_acquire_without_session_token(httpx2_mock):
"""Without an access token in the session, Menshen is not called."""
with pytest.raises(CredentialError, match="OIDC_STORE_ACCESS_TOKEN"):
TokenExchangeProvider().acquire(make_request(access_token=None))
assert not httpx2_mock.get_requests()
@pytest.mark.parametrize(
"response",
[
{"status_code": 400, "json": {"error": "invalid_target"}},
{"status_code": 500},
{"json": {"unexpected": "field"}},
],
)
def test_token_exchange_acquire_refused(httpx2_mock, response):
"""A refused, failed or unparsable exchange gives no credential."""
httpx2_mock.add_response(method="POST", url=EXCHANGE_ENDPOINT, **response)
with pytest.raises(CredentialError, match="Menshen token exchange failed"):
TokenExchangeProvider().acquire(make_request())
def test_token_exchange_acquire_unreachable(httpx2_mock):
"""An unreachable Menshen gives no credential."""
httpx2_mock.add_exception(httpx2.ConnectError("Connection refused"))
with pytest.raises(CredentialError, match="Menshen token exchange failed"):
TokenExchangeProvider().acquire(make_request())
def test_token_exchange_release_revokes(httpx2_mock):
"""The exchanged token is revoked once it is not needed anymore."""
httpx2_mock.add_response(method="POST", url=REVOCATION_ENDPOINT)
TokenExchangeProvider().release("exchanged-token")
assert parse_qs(httpx2_mock.get_request().content.decode()) == {
"token": ["exchanged-token"],
"token_type_hint": ["urn:ietf:params:oauth:token-type:access_token"],
}
def test_token_exchange_release_failure_is_ignored(httpx2_mock, caplog):
"""A failed revocation is only logged: the token expires on its own."""
httpx2_mock.add_response(method="POST", url=REVOCATION_ENDPOINT, status_code=503)
TokenExchangeProvider().release("exchanged-token")
assert "Could not revoke an exchanged token" in caplog.text
@@ -0,0 +1,419 @@
"""Tests for the task pushing a finished recording to its starter's Drive."""
# pylint: disable=redefined-outer-name,unused-argument
import json
from datetime import timedelta
from unittest import mock
from urllib.parse import parse_qs
from django.utils import timezone
import pytest
import responses
from core import factories, models
from core.audit.testing import find_events
from core.tasks.push_recording import push_recording_to_drive
pytestmark = pytest.mark.django_db
Status = models.RecordingDeliveryStatusChoices
API = "https://drive.example.com/external_api/v1.0"
FRONTEND = "https://drive.example.com"
S3_URL = "https://s3.example.com/recordings/recording.mp4"
POLICY_URL = "https://storage.example.com/upload?X-Amz-Signature=abc"
FOLDER_ID = "0b3c0ae4-91f9-4c47-a9fa-5d7a0c3f8f01"
FILE_ID = "8e5a7b1e-3a0c-4f63-b8a8-2f1f6f0c9d12"
MENSHEN = "https://menshen.example.com"
@pytest.fixture(autouse=True)
def drive_settings(settings, encryption_key):
"""Push recordings to Drive."""
settings.RECORDING_STORAGE_METHOD = "drive"
settings.RECORDING_DRIVE_FOLDER_NAME = "Visio-Recordings"
settings.RECORDING_DRIVE_PUSH_MAX_ATTEMPTS = 3
settings.DRIVE_API_BASE_URL = API
settings.DRIVE_FRONTEND_BASE_URL = FRONTEND
settings.DRIVE_UPLOAD_STORAGE_NETLOC = None
settings.MENSHEN_SERVER_URL = MENSHEN
settings.MENSHEN_CLIENT_ID = "meet"
settings.MENSHEN_CLIENT_SECRET = "meet-secret"
@pytest.fixture(autouse=True)
def mock_download_url():
"""Sign object storage URLs without an object storage."""
with mock.patch(
"core.recording.delivery.drive.utils.generate_download_s3_url",
return_value=S3_URL,
) as mocked:
yield mocked
@pytest.fixture(autouse=True)
def mock_send_email():
"""Catch the emails sent."""
with mock.patch("core.recording.delivery.drive.send_email") as mocked:
yield mocked
@pytest.fixture
def delivery():
"""A recording being pushed: its starter, a room administrator, a member."""
starter = factories.UserFactory(email="starter@example.com", language="fr-fr")
recording = factories.RecordingFactory(
mode="screen_recording",
status="notification_succeeded",
room__name="Weekly",
room__slug="weekly",
)
factories.UserRecordingAccessFactory(
recording=recording, user=starter, role=models.RoleChoices.OWNER
)
factories.UserRecordingAccessFactory(
recording=recording,
user__email="admin@example.com",
role=models.RoleChoices.OWNER,
)
factories.UserRecordingAccessFactory(
recording=recording,
user__email="member@example.com",
role=models.RoleChoices.MEMBER,
)
factories.TeamRecordingAccessFactory(
recording=recording, role=models.RoleChoices.OWNER
)
delivery = factories.RecordingDeliveryFactory(
recording=recording, user=starter, status=Status.PUSHING
)
delivery.set_token("user-access-token", None)
delivery.save()
return delivery
def mock_upload(folder_exists=False):
"""Mock the object storage and Drive calls of a successful upload."""
responses.get(
S3_URL,
body=b"video",
headers={"Content-Length": "5"},
content_type="video/mp4",
)
responses.get(
f"{API}/items/",
json={
"count": 1 if folder_exists else 0,
"results": [
{
"id": FOLDER_ID,
"type": "folder",
"title": "Visio-Recordings",
"depth": 1,
}
]
if folder_exists
else [],
},
)
if not folder_exists:
responses.post(
f"{API}/items/",
match=[
responses.matchers.json_params_matcher(
{"type": "folder", "title": "Visio-Recordings"}
)
],
json={"id": FOLDER_ID, "type": "folder", "depth": 1},
)
responses.post(
f"{API}/items/{FOLDER_ID}/children/",
json={"id": FILE_ID, "policy": POLICY_URL},
)
responses.put(POLICY_URL)
responses.post(f"{API}/items/{FILE_ID}/upload-ended/", json={"id": FILE_ID})
def mock_share(status=201):
"""Mock sharing with the room administrator, a Drive user."""
responses.get(
f"{API}/users/",
match=[responses.matchers.query_param_matcher({"q": "admin@example.com"})],
json=[{"id": "drive-admin-id", "email": "admin@example.com"}],
)
responses.post(f"{API}/items/{FILE_ID}/accesses/", status=status, json={})
def calls_to(method, url):
"""Return the calls made with this method to this URL, ignoring the query."""
return [
call
for call in responses.calls
if call.request.method == method and call.request.url.split("?")[0] == url
]
@responses.activate
def test_push_to_drive_success(delivery, mock_send_email, audit_events):
"""The recording is streamed to a new folder, shared, and the starter emailed."""
mock_upload()
mock_share()
assert push_recording_to_drive(str(delivery.recording_id)) is True
delivery.refresh_from_db()
assert delivery.status == Status.DELIVERED
assert str(delivery.drive_item_id) == FILE_ID
assert delivery.token is None
assert delivery.error == ""
[create_file] = calls_to("POST", f"{API}/items/{FOLDER_ID}/children/")
filename = json.loads(create_file.request.body)["filename"]
assert filename.startswith("weekly-") and filename.endswith(".mp4")
assert all(
call.request.headers.get("Authorization") == "Bearer user-access-token"
for call in responses.calls
if call.request.url.startswith(API)
)
[upload] = calls_to("PUT", POLICY_URL.split("?", maxsplit=1)[0])
assert upload.request.headers["Content-Length"] == "5"
# Only the room administrator is shared with: not the starter, a member or a team
[share] = calls_to("POST", f"{API}/items/{FILE_ID}/accesses/")
assert json.loads(share.request.body) == {
"user_id": "drive-admin-id",
"role": "owner",
}
mock_send_email.delay.assert_called_once()
kwargs = mock_send_email.delay.call_args.kwargs
assert kwargs["template"] == "recording_saved_to_drive"
assert kwargs["recipients"] == ["starter@example.com"]
assert kwargs["language"] == "fr-fr"
assert kwargs["context"]["room_name"] == "Weekly"
assert kwargs["context"]["folder_name"] == "Visio-Recordings"
assert kwargs["context"]["link"] == f"{FRONTEND}/explorer/items/files/{FILE_ID}"
[event] = find_events(audit_events, "recording.drive.push")
assert event["lasuite"]["outcome"] == "success"
assert event["lasuite"]["details"]["drive_item_id"] == FILE_ID
assert "user-access-token" not in str(audit_events)
@responses.activate
def test_push_to_drive_existing_folder(delivery):
"""The user's recordings folder is reused."""
mock_upload(folder_exists=True)
mock_share()
assert push_recording_to_drive(str(delivery.recording_id)) is True
assert not calls_to("POST", f"{API}/items/")
@responses.activate
def test_push_to_drive_invites_unknown_email(delivery):
"""An administrator with no Drive account yet is invited."""
mock_upload()
responses.get(f"{API}/users/", json=[])
responses.post(f"{API}/items/{FILE_ID}/invitations/", status=201, json={})
assert push_recording_to_drive(str(delivery.recording_id)) is True
[invitation] = calls_to("POST", f"{API}/items/{FILE_ID}/invitations/")
assert json.loads(invitation.request.body) == {
"email": "admin@example.com",
"role": "owner",
}
@responses.activate
def test_push_to_drive_share_failure(delivery, mock_send_email):
"""A file that could not be shared with everyone stays uploaded, starter emailed."""
mock_upload()
mock_share(status=403)
assert push_recording_to_drive(str(delivery.recording_id)) is True
delivery.refresh_from_db()
assert delivery.status == Status.UPLOADED
assert delivery.error == "Could not share with: admin@example.com"
assert delivery.token is None
mock_send_email.delay.assert_called_once()
@responses.activate
def test_push_to_drive_failure_retries(delivery, mock_send_email):
"""A failed push is tried again later, the incomplete file deleted."""
mock_upload()
responses.replace(responses.PUT, POLICY_URL, status=503)
responses.delete(f"{API}/items/{FILE_ID}/", status=204)
with mock.patch.object(push_recording_to_drive, "apply_async") as apply_async:
assert push_recording_to_drive(str(delivery.recording_id)) is False
apply_async.assert_called_once_with(
args=(str(delivery.recording_id),), kwargs={"attempt": 2}, countdown=60
)
assert len(calls_to("DELETE", f"{API}/items/{FILE_ID}/")) == 1
delivery.refresh_from_db()
assert delivery.status == Status.PUSHING
assert delivery.get_token() == "user-access-token"
assert "503" in delivery.error
mock_send_email.delay.assert_not_called()
@responses.activate
def test_push_to_drive_failure_last_attempt(delivery, mock_send_email, audit_events):
"""After the last attempt, the push fails, and nobody is emailed."""
mock_upload()
responses.replace(responses.GET, S3_URL, status=503)
with mock.patch.object(push_recording_to_drive, "apply_async") as apply_async:
assert push_recording_to_drive(str(delivery.recording_id), attempt=3) is False
apply_async.assert_not_called()
delivery.refresh_from_db()
assert delivery.status == Status.FAILED
assert delivery.token is None
mock_send_email.delay.assert_not_called()
[event] = find_events(audit_events, "recording.drive.push")
assert event["lasuite"]["outcome"] == "failure"
assert event["event"]["reason"] == "internal_error"
@responses.activate
def test_push_to_drive_unexpected_error(delivery, mock_send_email, audit_events):
"""An unexpected error fails the push at once and releases the token."""
mock_upload()
responses.replace(
responses.POST,
f"{API}/items/{FOLDER_ID}/children/",
json={"policy": POLICY_URL},
)
with mock.patch.object(push_recording_to_drive, "apply_async") as apply_async:
assert push_recording_to_drive(str(delivery.recording_id)) is False
apply_async.assert_not_called()
delivery.refresh_from_db()
assert delivery.status == Status.FAILED
assert delivery.token is None
mock_send_email.delay.assert_not_called()
[event] = find_events(audit_events, "recording.drive.push")
assert event["lasuite"]["outcome"] == "failure"
@responses.activate
def test_push_to_drive_unexpected_error_after_upload(delivery, mock_send_email):
"""A recording already in Drive stays uploaded when sharing it crashes."""
mock_upload()
with mock.patch(
"core.recording.delivery.drive.share", side_effect=RuntimeError("boom")
):
assert push_recording_to_drive(str(delivery.recording_id)) is False
delivery.refresh_from_db()
assert delivery.status == Status.UPLOADED
assert str(delivery.drive_item_id) == FILE_ID
assert delivery.token is None
assert delivery.error == "boom"
mock_send_email.delay.assert_not_called()
@responses.activate
def test_push_to_drive_refused(delivery, mock_send_email, audit_events):
"""A refused token is audited as an authentication failure."""
responses.get(f"{API}/items/", status=401)
with mock.patch.object(push_recording_to_drive, "apply_async") as apply_async:
assert push_recording_to_drive(str(delivery.recording_id), attempt=3) is False
apply_async.assert_not_called()
delivery.refresh_from_db()
assert delivery.status == Status.FAILED
assert "401" in delivery.error
mock_send_email.delay.assert_not_called()
[event] = find_events(audit_events, "recording.drive.push")
assert event["event"]["reason"] == "authentication_failed"
@responses.activate
def test_push_to_drive_expired_token(delivery):
"""A token known to be expired is not even tried."""
delivery.token_expires_at = timezone.now() - timedelta(minutes=1)
delivery.save()
assert push_recording_to_drive(str(delivery.recording_id)) is False
assert not responses.calls
delivery.refresh_from_db()
assert delivery.status == Status.FAILED
assert "expired" in delivery.error
@responses.activate
@pytest.mark.parametrize("status", [Status.PENDING, Status.DELIVERED, Status.FAILED])
def test_push_to_drive_not_pushing(delivery, status):
"""Only a delivery handed over to the worker is pushed."""
delivery.status = status
delivery.save()
assert push_recording_to_drive(str(delivery.recording_id)) is False
assert not responses.calls
delivery.refresh_from_db()
assert delivery.status == status
def test_push_to_drive_no_delivery():
"""A recording without delivery cannot be pushed."""
recording = factories.RecordingFactory()
assert push_recording_to_drive(str(recording.id)) is False
@responses.activate
def test_push_to_drive_revokes_exchanged_token(delivery, httpx2_mock):
"""An exchanged token is revoked once the recording is in Drive."""
delivery.token_type = models.DriveTokenTypeChoices.TOKEN_EXCHANGE
delivery.set_token("exchanged-token", timezone.now() + timedelta(hours=1))
delivery.save()
mock_upload()
mock_share()
httpx2_mock.add_response(method="POST", url=f"{MENSHEN}/auth/token/revoke/")
assert push_recording_to_drive(str(delivery.recording_id)) is True
form = parse_qs(httpx2_mock.get_request().content.decode())
assert form["token"] == ["exchanged-token"]
delivery.refresh_from_db()
assert delivery.token is None
assert delivery.token_expires_at is None
@responses.activate
def test_push_to_drive_revocation_crash(delivery):
"""The token is dropped even if revoking it crashes."""
delivery.token_type = models.DriveTokenTypeChoices.TOKEN_EXCHANGE
delivery.set_token("exchanged-token", timezone.now() + timedelta(hours=1))
delivery.save()
mock_upload()
mock_share()
with mock.patch(
"core.recording.delivery.credentials.TokenExchangeProvider.release",
side_effect=RuntimeError("boom"),
):
assert push_recording_to_drive(str(delivery.recording_id)) is True
delivery.refresh_from_db()
assert delivery.status == Status.DELIVERED
assert delivery.token is None
@@ -0,0 +1,230 @@
"""Tests for choosing, then carrying out, how a recording is delivered."""
# pylint: disable=redefined-outer-name,unused-argument
from datetime import datetime, timezone
from types import SimpleNamespace
from unittest import mock
import pytest
from celery.exceptions import OperationalError as CeleryOperationalError
from core import factories, models
from core.audit.testing import find_events
from core.recording.delivery import service
from core.recording.delivery.credentials import Credential, CredentialError
pytestmark = pytest.mark.django_db
Status = models.RecordingDeliveryStatusChoices
@pytest.fixture
def drive_settings(settings, encryption_key):
"""Push recordings to Drive with the user's access token."""
settings.RECORDING_STORAGE_METHOD = "drive"
settings.RECORDING_DRIVE_AUTH_METHOD = "access_token"
def make_request(user, access_token="user-access-token"):
"""Return a request of the user, whose session holds their access token."""
session = {"oidc_access_token": access_token} if access_token else {}
return SimpleNamespace(user=user, session=session)
def test_prepare_transcript_is_not_delivered(drive_settings):
"""An audio-only transcript ends up in Docs: it gets no delivery."""
recording = factories.RecordingFactory(mode="transcript")
assert service.prepare(make_request(factories.UserFactory()), recording) is None
assert not models.RecordingDelivery.objects.exists()
def test_prepare_s3_email(settings):
"""By default, a video recording is delivered by email, needing no token."""
settings.RECORDING_STORAGE_METHOD = "s3_email"
user = factories.UserFactory()
recording = factories.RecordingFactory(mode="screen_recording")
delivery = service.prepare(make_request(user), recording)
delivery.refresh_from_db()
assert delivery.recording == recording
assert delivery.user == user
assert delivery.method == "s3_email"
assert delivery.status == Status.PENDING
assert delivery.token is None
assert delivery.token_type is None
def test_prepare_drive_access_token(drive_settings):
"""The access token is kept, encrypted, to push the recording later."""
user = factories.UserFactory()
recording = factories.RecordingFactory(mode="screen_recording")
delivery = service.prepare(make_request(user), recording)
delivery.refresh_from_db()
assert delivery.method == "drive"
assert delivery.status == Status.PENDING
assert delivery.token_type == "access_token"
assert delivery.token and "user-access-token" not in delivery.token
assert delivery.get_token() == "user-access-token"
assert delivery.token_expires_at is None
def test_prepare_drive_token_exchange(drive_settings, settings):
"""The exchanged token is kept with its expiration."""
settings.RECORDING_DRIVE_AUTH_METHOD = "token_exchange"
expires_at = datetime(2026, 11, 19, 12, 0, tzinfo=timezone.utc)
recording = factories.RecordingFactory(mode="screen_recording")
with mock.patch(
"core.recording.delivery.credentials.TokenExchangeProvider.acquire",
return_value=Credential("exchanged-token", expires_at),
) as acquire:
delivery = service.prepare(make_request(factories.UserFactory()), recording)
acquire.assert_called_once()
delivery.refresh_from_db()
assert delivery.token_type == "token_exchange"
assert delivery.get_token() == "exchanged-token"
assert delivery.token_expires_at == expires_at
def test_prepare_drive_without_token(drive_settings, audit_events):
"""Without a token, the recording will not be delivered, and nothing falls back."""
recording = factories.RecordingFactory(mode="screen_recording")
delivery = service.prepare(
make_request(factories.UserFactory(), access_token=None), recording
)
delivery.refresh_from_db()
assert delivery.method == "drive"
assert delivery.status == Status.FAILED
assert "OIDC_STORE_ACCESS_TOKEN" in delivery.error
assert delivery.token is None
[event] = find_events(audit_events, "recording.drive.push")
assert event["lasuite"]["outcome"] == "failure"
assert event["event"]["reason"] == "authentication_failed"
assert event["entity"]["target"]["id"] == str(recording.id)
def test_prepare_drive_token_exchange_refused(drive_settings, settings):
"""A refused exchange leaves the delivery failed."""
settings.RECORDING_DRIVE_AUTH_METHOD = "token_exchange"
recording = factories.RecordingFactory(mode="screen_recording")
with mock.patch(
"core.recording.delivery.credentials.TokenExchangeProvider.acquire",
side_effect=CredentialError("Menshen token exchange failed: 400"),
):
delivery = service.prepare(make_request(factories.UserFactory()), recording)
assert delivery.status == Status.FAILED
assert delivery.error == "Menshen token exchange failed: 400"
def test_get_method_without_delivery():
"""A recording started before deliveries existed is delivered by email."""
recording = factories.RecordingFactory(mode="screen_recording")
assert service.get_method(recording) == "s3_email"
def test_get_method_with_delivery():
"""The method is the one chosen when the recording started."""
delivery = factories.RecordingDeliveryFactory(method="drive")
assert service.get_method(delivery.recording) == "drive"
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_dispatch_to_drive_pending(mock_task, encryption_key):
"""A pending delivery is handed over to a worker, once."""
delivery = factories.RecordingDeliveryFactory()
assert service.dispatch_to_drive(delivery.recording) is True
mock_task.delay.assert_called_once_with(str(delivery.recording_id))
delivery.refresh_from_db()
assert delivery.status == Status.PUSHING
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_dispatch_to_drive_failed(mock_task):
"""A delivery that failed, e.g. for want of a token, is not pushed."""
delivery = factories.RecordingDeliveryFactory(status=Status.FAILED)
assert service.dispatch_to_drive(delivery.recording) is False
mock_task.delay.assert_not_called()
@pytest.mark.parametrize("status", [Status.PUSHING, Status.UPLOADED, Status.DELIVERED])
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_dispatch_to_drive_never_twice(mock_task, status):
"""A delivery already pushed, or being pushed, is not pushed again."""
delivery = factories.RecordingDeliveryFactory(status=status)
assert service.dispatch_to_drive(delivery.recording) is True
mock_task.delay.assert_not_called()
delivery.refresh_from_db()
assert delivery.status == status
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_dispatch_to_drive_broker_unavailable(mock_task, encryption_key):
"""When the push cannot be queued, the delivery stays pending with its token."""
mock_task.delay.side_effect = CeleryOperationalError("broker down")
delivery = factories.RecordingDeliveryFactory()
delivery.set_token("user-access-token", None)
delivery.save()
assert service.dispatch_to_drive(delivery.recording) is False
delivery.refresh_from_db()
assert delivery.status == Status.PENDING
assert delivery.get_token() == "user-access-token"
def test_abandon_releases_the_token(encryption_key):
"""A recording that will never be saved lets go of its token right away."""
delivery = factories.RecordingDeliveryFactory(token_type="token_exchange")
delivery.set_token("exchanged-token", None)
delivery.save()
with mock.patch(
"core.recording.delivery.credentials.TokenExchangeProvider.release"
) as release:
service.abandon(delivery.recording, "The recording failed.")
release.assert_called_once_with("exchanged-token")
delivery.refresh_from_db()
assert delivery.status == Status.FAILED
assert delivery.error == "The recording failed."
assert delivery.token is None
def test_abandon_without_delivery():
"""A recording without delivery has nothing to abandon."""
recording = factories.RecordingFactory(mode="transcript")
service.abandon(recording, "The recording failed.")
assert not models.RecordingDelivery.objects.exists()
@pytest.mark.parametrize("status", [Status.PUSHING, Status.DELIVERED, Status.FAILED])
def test_abandon_only_pending(status):
"""Only a delivery still waiting for its recording is abandoned."""
delivery = factories.RecordingDeliveryFactory(status=status)
service.abandon(delivery.recording, "The recording failed.")
delivery.refresh_from_db()
assert delivery.status == status
assert delivery.error == ""
@@ -84,6 +84,61 @@ def test_notify_external_services_screen_recording_mode_with_transcribe(
mock_notify_summary.assert_called_once_with(recording)
@mock.patch.object(NotificationService, "_notify_user_by_email", return_value=True)
def test_notify_external_services_s3_email_delivery(mock_notify_email):
"""A recording to deliver by email is emailed."""
delivery = factories.RecordingDeliveryFactory(method="s3_email", token_type=None)
assert NotificationService().notify_external_services(delivery.recording) is True
mock_notify_email.assert_called_once_with(delivery.recording)
@mock.patch.object(NotificationService, "_notify_user_by_email", return_value=True)
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_notify_external_services_drive_delivery(mock_task, mock_notify_email):
"""A recording to push to Drive is handed over to a worker, nobody emailed yet."""
delivery = factories.RecordingDeliveryFactory(recording__mode="screen_recording")
assert NotificationService().notify_external_services(delivery.recording) is True
mock_task.delay.assert_called_once_with(str(delivery.recording_id))
mock_notify_email.assert_not_called()
@mock.patch.object(NotificationService, "_notify_user_by_email", return_value=True)
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_notify_external_services_drive_delivery_failed(mock_task, mock_notify_email):
"""A recording that cannot be pushed to Drive does not fall back to the email."""
delivery = factories.RecordingDeliveryFactory(
status=models.RecordingDeliveryStatusChoices.FAILED
)
assert NotificationService().notify_external_services(delivery.recording) is False
mock_task.delay.assert_not_called()
mock_notify_email.assert_not_called()
@mock.patch.object(NotificationService, "_notify_summary_service", return_value=True)
@mock.patch.object(NotificationService, "_notify_user_by_email", return_value=True)
@mock.patch("core.recording.delivery.service.push_recording_to_drive")
def test_notify_external_services_transcript_with_video_to_drive(
mock_task, mock_notify_email, mock_notify_summary
):
"""A transcript with a video is transcribed, and its video pushed to Drive."""
delivery = factories.RecordingDeliveryFactory(
recording__mode=models.RecordingModeChoices.SCREEN_RECORDING,
recording__options={"transcribe": True, "original_mode": "transcript"},
)
assert NotificationService().notify_external_services(delivery.recording) is True
mock_notify_summary.assert_called_once_with(delivery.recording)
mock_task.delay.assert_called_once_with(str(delivery.recording_id))
mock_notify_email.assert_not_called()
def test_notify_external_services_unknown_mode(caplog):
"""Test notification for unknown recording mode."""
recording = factories.RecordingFactory()
@@ -9,7 +9,7 @@ from unittest import mock
import pytest
from core.factories import RecordingFactory
from core.factories import RecordingDeliveryFactory, RecordingFactory
from core.recording.enums import RecordingWorkerEvent
from core.recording.services.recording_events import (
RecordingEventsError,
@@ -90,6 +90,31 @@ def test_handle_failed_success(mock_notify, mode, notification_type, service):
)
@pytest.mark.parametrize(
("handler", "error"),
(
("_handle_failed", "The recording failed."),
("_handle_aborted", "The recording was aborted."),
),
)
@mock.patch("core.utils.notify_participants")
def test_handle_failure_abandons_delivery( # pylint: disable=unused-argument
mock_notify, handler, error, service, encryption_key
):
"""A recording that will never be saved lets go of its delivery's token."""
delivery = RecordingDeliveryFactory(recording__status="active")
delivery.set_token("user-access-token", None)
delivery.save()
getattr(service, handler)(delivery.recording)
delivery.refresh_from_db()
assert delivery.status == "failed"
assert delivery.error == error
assert delivery.token is None
@pytest.mark.parametrize(
("mode", "notification_type"),
(
@@ -1037,3 +1037,119 @@ def test_start_recording_anonymous_is_audited(settings):
assert event["lasuite"]["outcome"] == "denied"
assert event["lasuite"]["actor"]["type"] == "anonymous"
def _start_recording_client(room, access_token="user-access-token"):
"""Return a client of a room owner, whose session holds their access token."""
user = UserFactory()
room.accesses.create(user=user, role="owner")
client = APIClient()
client.force_login(user)
if access_token:
session = client.session
session["oidc_access_token"] = access_token
session.save()
return client, user
def test_start_recording_delivery_s3_email(
mock_worker_service_factory, mock_worker_manager, settings
):
"""By default, a video recording will be delivered by email."""
settings.RECORDING_ENABLE = True
settings.RECORDING_STORAGE_METHOD = "s3_email"
room = RoomFactory()
client, user = _start_recording_client(room)
response = client.post(
f"/api/v1.0/rooms/{room.id}/start-recording/", {"mode": "screen_recording"}
)
assert response.status_code == 201
delivery = Recording.objects.get().delivery
assert delivery.method == "s3_email"
assert delivery.user == user
assert delivery.token is None
def test_start_recording_delivery_drive(
mock_worker_service_factory, mock_worker_manager, settings, encryption_key
):
"""To push to Drive, the user's token is kept, encrypted, when the recording starts."""
settings.RECORDING_ENABLE = True
settings.RECORDING_STORAGE_METHOD = "drive"
settings.RECORDING_DRIVE_AUTH_METHOD = "access_token"
room = RoomFactory()
client, user = _start_recording_client(room)
response = client.post(
f"/api/v1.0/rooms/{room.id}/start-recording/", {"mode": "screen_recording"}
)
assert response.status_code == 201
delivery = Recording.objects.get().delivery
assert delivery.method == "drive"
assert delivery.status == "pending"
assert delivery.user == user
assert delivery.get_token() == "user-access-token"
def test_start_recording_delivery_drive_without_token(
mock_worker_service_factory, mock_worker_manager, settings, encryption_key
):
"""Without a token, the recording still starts, but will not be pushed."""
settings.RECORDING_ENABLE = True
settings.RECORDING_STORAGE_METHOD = "drive"
settings.RECORDING_DRIVE_AUTH_METHOD = "access_token"
room = RoomFactory()
client, _user = _start_recording_client(room, access_token=None)
response = client.post(
f"/api/v1.0/rooms/{room.id}/start-recording/", {"mode": "screen_recording"}
)
assert response.status_code == 201
recording = Recording.objects.get()
mock_worker_manager.start.assert_called_once_with(recording)
assert recording.delivery.method == "drive"
assert recording.delivery.status == "failed"
def test_start_recording_delivery_transcript(
mock_worker_service_factory, mock_worker_manager, settings, encryption_key
):
"""An audio-only transcript gets no delivery."""
settings.RECORDING_ENABLE = True
settings.RECORDING_STORAGE_METHOD = "drive"
settings.RECORDING_DRIVE_AUTH_METHOD = "access_token"
room = RoomFactory()
client, _user = _start_recording_client(room)
response = client.post(
f"/api/v1.0/rooms/{room.id}/start-recording/", {"mode": "transcript"}
)
assert response.status_code == 201
assert not hasattr(Recording.objects.get(), "delivery")
def test_start_recording_delivery_worker_error_releases_token(
mock_worker_service_factory, mock_worker_manager, settings, encryption_key
):
"""A recording that fails to start lets go of its token."""
settings.RECORDING_ENABLE = True
settings.RECORDING_STORAGE_METHOD = "drive"
settings.RECORDING_DRIVE_AUTH_METHOD = "access_token"
mock_worker_manager.start = mock.Mock(side_effect=RecordingStartError("boom"))
room = RoomFactory()
client, _user = _start_recording_client(room)
response = client.post(
f"/api/v1.0/rooms/{room.id}/start-recording/", {"mode": "screen_recording"}
)
assert response.status_code == 502
delivery = Recording.objects.get().delivery
assert delivery.status == "failed"
assert delivery.error == "The recording failed to start."
assert delivery.token is None
@@ -0,0 +1,301 @@
"""Tests for the client of Drive's external API."""
# pylint: disable=redefined-outer-name
import io
import json
import pytest
import requests
import responses
from core.services.drive import DriveClient, DriveError
API = "https://drive.example.com/external_api/v1.0"
ITEM_ID = "6f0b2b43-bf2b-4c4f-9a35-7f34f3c1d0a1"
@pytest.fixture(autouse=True)
def drive_settings(settings):
"""Configure Drive's external API."""
settings.DRIVE_API_BASE_URL = API
settings.DRIVE_UPLOAD_STORAGE_NETLOC = None
@pytest.fixture
def drive():
"""Return a client calling Drive with a user token."""
with DriveClient("user-token") as client:
yield client
def folder(title, depth=1, **overrides):
"""Return a folder item as Drive lists it."""
return {
"id": ITEM_ID,
"type": "folder",
"title": title,
"depth": depth,
**overrides,
}
def test_drive_client_requires_configuration(settings):
"""Without Drive's API URL, there is nothing to call."""
settings.DRIVE_API_BASE_URL = None
with pytest.raises(DriveError, match="DRIVE_API_BASE_URL"):
DriveClient("user-token")
def test_drive_client_requires_token():
"""Drive is always called on behalf of a user."""
with pytest.raises(DriveError, match="token"):
DriveClient("")
@pytest.mark.parametrize("status_code", [401, 403, 429, 500])
def test_drive_error_from_http_error(status_code):
"""An error with an answer keeps its status code."""
response = requests.Response()
response.status_code = status_code
error = DriveError.from_request_exception(
"Failed", requests.HTTPError(response=response)
)
assert error.status_code == status_code
assert str(error) == f"Failed ({status_code})"
def test_drive_error_from_connection_error():
"""An error with no answer at all has no status code."""
error = DriveError.from_request_exception(
"Failed", requests.ConnectionError("refused")
)
assert error.status_code is None
assert str(error) == "Failed"
@responses.activate
def test_find_root_folder_exact_match(drive):
"""Only a folder with that exact title, at the root, is returned."""
responses.get(
f"{API}/items/",
match=[
responses.matchers.query_param_matcher(
{"type": "folder", "title": "Visio-Recordings", "is_creator_me": "true"}
),
responses.matchers.header_matcher({"Authorization": "Bearer user-token"}),
],
json={
"count": 4,
"results": [
folder("Old Visio-Recordings", id="1"),
folder("visio-recordings", id="2"),
folder("Visio-Recordings", depth=2, id="3"),
folder("Visio-Recordings", id="4"),
],
},
)
assert drive.find_root_folder("Visio-Recordings")["id"] == "4"
@responses.activate
def test_find_root_folder_missing(drive):
"""No matching folder gives None."""
responses.get(f"{API}/items/", json={"count": 0, "results": []})
assert drive.find_root_folder("Visio-Recordings") is None
@responses.activate
def test_create_folder(drive):
"""A folder is created at the root of the user's Drive."""
responses.post(
f"{API}/items/",
match=[
responses.matchers.json_params_matcher(
{"type": "folder", "title": "Visio-Recordings"}
)
],
json=folder("Visio-Recordings"),
)
assert drive.create_folder("Visio-Recordings")["id"] == ITEM_ID
@responses.activate
def test_create_file_in_folder(drive):
"""A file is created in its folder, with an upload policy."""
responses.post(
f"{API}/items/{ITEM_ID}/children/",
match=[
responses.matchers.json_params_matcher(
{"type": "file", "filename": "room.mp4"}
)
],
json={"id": "file-id", "policy": "https://storage.example.com/upload"},
)
item = drive.create_file(filename="room.mp4", parent_id=ITEM_ID)
assert item["policy"] == "https://storage.example.com/upload"
@responses.activate
def test_create_file_at_root(drive):
"""Without a folder, a file is created at the root."""
responses.post(
f"{API}/items/",
json={"id": "file-id", "policy": "https://storage.example.com/upload"},
)
assert drive.create_file(filename="room.mp4")["id"] == "file-id"
@responses.activate
def test_create_file_without_policy(drive):
"""A file Drive gives no upload policy for cannot be uploaded."""
responses.post(f"{API}/items/", json={"id": "file-id"})
with pytest.raises(DriveError, match="upload policy"):
drive.create_file(filename="room.mp4")
@responses.activate
@pytest.mark.parametrize("status_code", [403, 502])
def test_request_failure(drive, status_code):
"""A failed call raises, with its status code."""
responses.post(f"{API}/items/", status=status_code)
with pytest.raises(DriveError) as excinfo:
drive.create_folder("Visio-Recordings")
assert excinfo.value.status_code == status_code
@responses.activate
def test_delete_item(drive):
"""Deleting an item calls its endpoint."""
responses.delete(f"{API}/items/{ITEM_ID}/", status=204)
drive.delete_item(ITEM_ID)
assert len(responses.calls) == 1
@responses.activate
def test_upload_content(drive):
"""The content is streamed to the presigned URL with its size."""
responses.put("https://storage.example.com/upload")
drive.upload_content(
policy_url="https://storage.example.com/upload",
stream=io.BytesIO(b"video"),
content_length=5,
content_type="video/mp4",
)
request = responses.calls[0].request
assert request.headers["Content-Length"] == "5"
assert request.headers["Content-Type"] == "video/mp4"
assert request.headers["x-amz-acl"] == "private"
assert "Authorization" not in request.headers
@responses.activate
def test_upload_content_storage_netloc_override(drive, settings):
"""In development, the address connected to changes, not the signed Host."""
settings.DRIVE_UPLOAD_STORAGE_NETLOC = "drive-minio:9000"
responses.put("https://drive-minio:9000/upload?X-Amz-Signature=abc")
drive.upload_content(
policy_url="https://localhost:9100/upload?X-Amz-Signature=abc",
stream=io.BytesIO(b"video"),
content_length=5,
content_type="video/mp4",
)
assert responses.calls[0].request.headers["Host"] == "localhost:9100"
@responses.activate
def test_upload_content_failure(drive):
"""A failed upload raises, with its status code."""
responses.put("https://storage.example.com/upload", status=503)
with pytest.raises(DriveError) as excinfo:
drive.upload_content(
policy_url="https://storage.example.com/upload",
stream=io.BytesIO(b"video"),
content_length=5,
content_type="video/mp4",
)
assert excinfo.value.status_code == 503
@responses.activate
def test_complete_upload(drive):
"""Drive is told when the upload is over."""
responses.post(f"{API}/items/{ITEM_ID}/upload-ended/", json={"id": ITEM_ID})
drive.complete_upload(ITEM_ID)
assert len(responses.calls) == 1
@responses.activate
def test_find_user_by_email_exact_match(drive):
"""Drive's search tolerates typos: only the exact email, ignoring case, matches."""
responses.get(
f"{API}/users/",
match=[responses.matchers.query_param_matcher({"q": "Jane@Example.com"})],
json=[
{"id": "1", "email": "jane@exemple.com"},
{"id": "2", "email": "jane@example.com"},
],
)
assert drive.find_user_by_email("Jane@Example.com")["id"] == "2"
@responses.activate
def test_find_user_by_email_typo_only(drive):
"""An email only close to the expected one is not a match."""
responses.get(f"{API}/users/", json=[{"id": "1", "email": "jane@exemple.com"}])
assert drive.find_user_by_email("jane@example.com") is None
@responses.activate
def test_share_with_email_existing_user(drive):
"""An existing Drive user gets an access."""
responses.get(
f"{API}/users/", json=[{"id": "user-id", "email": "jane@example.com"}]
)
responses.post(f"{API}/items/{ITEM_ID}/accesses/", status=201, json={})
drive.share_with_email(ITEM_ID, "jane@example.com", "owner")
assert json.loads(responses.calls[1].request.body) == {
"user_id": "user-id",
"role": "owner",
}
@responses.activate
def test_share_with_email_unknown_user(drive):
"""An email with no Drive account yet gets an invitation."""
responses.get(f"{API}/users/", json=[])
responses.post(f"{API}/items/{ITEM_ID}/invitations/", status=201, json={})
drive.share_with_email(ITEM_ID, "jane@example.com", "owner")
assert json.loads(responses.calls[1].request.body) == {
"email": "jane@example.com",
"role": "owner",
}
@@ -9,6 +9,7 @@ from datetime import timedelta
from unittest import mock
from django.utils import timezone
from django.test import override_settings
import pytest
from faker import Faker
@@ -91,7 +92,7 @@ def test_initialization(
)
@mock.patch("core.utils.notify_participants")
@mock.patch("core.services.room_management.RoomManagement.update_metadata")
def test_handle_egress_ended_success( # pylint: disable=too-many-arguments, too-many-positional-arguments
def test_handle_egress_ended_success(
mock_update_metadata, mock_notify, mode, notification_type, service
):
"""Should successfully stop recording and notify all participant."""
@@ -150,7 +151,7 @@ def test_handle_egress_updated_success(
)
@mock.patch("core.utils.notify_participants")
@mock.patch("core.services.room_management.RoomManagement.update_metadata")
def test_handle_egress_ended_metadata_update_fails( # pylint: disable=too-many-arguments, too-many-positional-arguments
def test_handle_egress_ended_metadata_update_fails(
mock_update_metadata, mock_notify, mode, notification_type, service
):
"""Should successfully stop and save recording when metadata's update fails."""
@@ -1,6 +1,7 @@
"""Tests for the external API MenshenAuthentication."""
from unittest import mock
from urllib.parse import urlencode
import pytest
import responses
@@ -45,18 +46,17 @@ def _create_room(token=TOKEN):
return client.post("/external-api/v1.0/rooms/", {}, format="json")
@responses.activate
def test_menshen_active_token():
def test_menshen_active_token(httpx2_mock):
"""An active token with a mapped scope should create a room owned by the user."""
user = UserFactory()
# Catch and mock external HTTP requests
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
httpx2_mock.add_response(
method="POST",
url=INTROSPECTION_ENDPOINT,
json=_introspection(user.sub),
match=[responses.matchers.urlencoded_params_matcher({"token": TOKEN})],
match_content=urlencode({"token": TOKEN}).encode(),
)
response = _create_room()
@@ -64,12 +64,11 @@ def test_menshen_active_token():
assert response.status_code == 201
room = Room.objects.get(id=response.data["id"])
assert room.get_role(user) == RoleChoices.OWNER
assert responses.calls[0].request.headers["Authorization"].startswith("Basic ")
assert httpx2_mock.get_request().headers["Authorization"].startswith("Basic ")
@responses.activate
@mock.patch.object(ResourceServerAuthentication, "authenticate", return_value=None)
def test_menshen_other_token_type_ignored(mock_rs_authenticate):
def test_menshen_other_token_type_ignored(mock_rs_authenticate, httpx2_mock):
"""A token sent with another scheme than Bearer should not be introspected."""
client = APIClient()
@@ -77,13 +76,12 @@ def test_menshen_other_token_type_ignored(mock_rs_authenticate):
response = client.post("/external-api/v1.0/rooms/", {}, format="json")
assert response.status_code == 401
assert len(responses.calls) == 0
assert not httpx2_mock.get_requests()
mock_rs_authenticate.assert_called_once()
@responses.activate
@mock.patch.object(ResourceServerAuthentication, "authenticate", return_value=None)
def test_menshen_disabled(mock_rs_authenticate, settings):
def test_menshen_disabled(mock_rs_authenticate, settings, httpx2_mock):
"""Menshen should not be called when disabled."""
settings.MENSHEN_ENABLED = False
@@ -91,20 +89,19 @@ def test_menshen_disabled(mock_rs_authenticate, settings):
response = _create_room()
assert response.status_code == 401
assert len(responses.calls) == 0
assert not httpx2_mock.get_requests()
mock_rs_authenticate.assert_called_once()
@responses.activate
@mock.patch.object(ResourceServerAuthentication, "authenticate", return_value=None)
def test_menshen_inactive_token_defers(mock_rs_authenticate):
def test_menshen_inactive_token_defers(mock_rs_authenticate, httpx2_mock):
"""An inactive token should defer to the next authentication backend."""
user = UserFactory()
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
httpx2_mock.add_response(
method="POST",
url=INTROSPECTION_ENDPOINT,
json=_introspection(user.sub, scope="meet:room:create", active=False),
)
@@ -114,12 +111,11 @@ def test_menshen_inactive_token_defers(mock_rs_authenticate):
mock_rs_authenticate.assert_called_once()
@responses.activate
@mock.patch.object(ResourceServerAuthentication, "authenticate", return_value=None)
def test_menshen_error_defers(mock_rs_authenticate):
def test_menshen_error_defers(mock_rs_authenticate, httpx2_mock):
"""A Menshen error should defer to the next authentication backend."""
responses.add(responses.POST, INTROSPECTION_ENDPOINT, status=500)
httpx2_mock.add_response(method="POST", url=INTROSPECTION_ENDPOINT, status_code=500)
response = _create_room()
@@ -127,14 +123,13 @@ def test_menshen_error_defers(mock_rs_authenticate):
mock_rs_authenticate.assert_called_once()
@responses.activate
@mock.patch.object(ResourceServerAuthentication, "authenticate", return_value=None)
def test_menshen_unparsable_response_defers(mock_rs_authenticate):
def test_menshen_unparsable_response_defers(mock_rs_authenticate, httpx2_mock):
"""A response the client can't parse should defer to the next backend."""
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
httpx2_mock.add_response(
method="POST",
url=INTROSPECTION_ENDPOINT,
json={"active": True, "unexpected": "field"},
)
@@ -145,7 +140,7 @@ def test_menshen_unparsable_response_defers(mock_rs_authenticate):
@responses.activate
def test_menshen_resource_server_token(settings):
def test_menshen_resource_server_token(settings, httpx2_mock):
"""End to end: a token issued by the OIDC provider is unknown to Menshen and
should still authenticate through the resource server."""
@@ -155,12 +150,13 @@ def test_menshen_resource_server_token(settings):
user = UserFactory()
token = "oidc-access-token"
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
httpx2_mock.add_response(
method="POST",
url=INTROSPECTION_ENDPOINT,
json={"active": False},
match=[responses.matchers.urlencoded_params_matcher({"token": token})],
match_content=urlencode({"token": token}).encode(),
)
# The resource server backend calls the OIDC provider with requests
responses.add(
responses.POST,
"https://oidc.example.com/introspect",
@@ -178,19 +174,18 @@ def test_menshen_resource_server_token(settings):
assert response.status_code == 201
room = Room.objects.get(id=response.data["id"])
assert room.get_role(user) == RoleChoices.OWNER
responses.assert_call_count(INTROSPECTION_ENDPOINT, 1)
assert len(httpx2_mock.get_requests(url=INTROSPECTION_ENDPOINT)) == 1
responses.assert_call_count("https://oidc.example.com/introspect", 1)
@responses.activate
def test_menshen_unmapped_scope():
def test_menshen_unmapped_scope(httpx2_mock):
"""Scopes granted for other services or other Meet actions should not grant access."""
user = UserFactory()
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
httpx2_mock.add_response(
method="POST",
url=INTROSPECTION_ENDPOINT,
json=_introspection(user.sub, scope="drive:item:create meet:room:list"),
)
@@ -201,11 +196,12 @@ def test_menshen_unmapped_scope():
assert not Room.objects.exists()
@responses.activate
def test_menshen_missing_sub():
def test_menshen_missing_sub(httpx2_mock):
"""An active token without sub should be rejected."""
responses.add(responses.POST, INTROSPECTION_ENDPOINT, json=_introspection(None))
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection(None)
)
response = _create_room()
@@ -213,14 +209,13 @@ def test_menshen_missing_sub():
assert "invalid token claims." in str(response.data).lower()
@responses.activate
def test_menshen_invalid_sub(settings):
def test_menshen_invalid_sub(settings, httpx2_mock):
"""An active token with an invalid sub should be rejected without creating a user."""
settings.OIDC_CREATE_USER = True
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("invalid\nsub")
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection("invalid\nsub")
)
response = _create_room()
@@ -230,13 +225,14 @@ def test_menshen_invalid_sub(settings):
assert not User.objects.exists()
@responses.activate
def test_menshen_inactive_user():
def test_menshen_inactive_user(httpx2_mock):
"""An active token for an inactive user should be rejected."""
user = UserFactory(is_active=False)
responses.add(responses.POST, INTROSPECTION_ENDPOINT, json=_introspection(user.sub))
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection(user.sub)
)
response = _create_room()
@@ -244,14 +240,13 @@ def test_menshen_inactive_user():
assert "user account is disabled." in str(response.data).lower()
@responses.activate
def test_menshen_unknown_user_created(settings):
def test_menshen_unknown_user_created(settings, httpx2_mock):
"""An unknown sub should create a user when OIDC_CREATE_USER is set."""
settings.OIDC_CREATE_USER = True
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
)
response = _create_room()
@@ -262,14 +257,13 @@ def test_menshen_unknown_user_created(settings):
assert user.is_active is True
@responses.activate
def test_menshen_unknown_user_not_created(settings):
def test_menshen_unknown_user_not_created(settings, httpx2_mock):
"""An unknown sub should be rejected when OIDC_CREATE_USER is unset."""
settings.OIDC_CREATE_USER = False
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
)
response = _create_room()
@@ -279,9 +273,8 @@ def test_menshen_unknown_user_not_created(settings):
assert not User.objects.filter(sub="new-sub").exists()
@responses.activate
@pytest.mark.parametrize("existing_sub", [None, "other-sub"])
def test_menshen_unknown_user_email_already_used(settings, existing_sub):
def test_menshen_unknown_user_email_already_used(settings, existing_sub, httpx2_mock):
"""An unknown sub should not create a second account with an email already
used, by a provisional user or a user with another sub, when
OIDC_FALLBACK_TO_EMAIL_FOR_IDENTIFICATION=True."""
@@ -291,8 +284,8 @@ def test_menshen_unknown_user_email_already_used(settings, existing_sub):
existing_user = UserFactory(sub=existing_sub, email="User@Example.com")
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
)
response = _create_room()
@@ -305,17 +298,16 @@ def test_menshen_unknown_user_email_already_used(settings, existing_sub):
assert not Room.objects.exists()
@responses.activate
def test_menshen_is_audited_as_application(audit_events):
def test_menshen_is_audited_as_application(audit_events, httpx2_mock):
"""A call with a Menshen token is made by the client Menshen reports, acting for
the user. Neither the token, nor the jti Menshen derives from an opaque token,
nor the email ever appear."""
user = UserFactory(email="user@example.com")
responses.add(
responses.POST,
INTROSPECTION_ENDPOINT,
httpx2_mock.add_response(
method="POST",
url=INTROSPECTION_ENDPOINT,
json=_introspection(user.sub, email="user@example.com", jti=TOKEN[:50]),
)
@@ -334,15 +326,14 @@ def test_menshen_is_audited_as_application(audit_events):
assert "user@example.com" not in str(audit_events)
@responses.activate
def test_menshen_unknown_user_created_is_audited(audit_events, settings):
def test_menshen_unknown_user_created_is_audited(audit_events, settings, httpx2_mock):
"""A user created for an unknown sub is provisioned by the client Menshen reports,
before the call it makes as that user."""
settings.OIDC_CREATE_USER = True
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
)
response = _create_room()
@@ -374,8 +365,9 @@ def test_menshen_unknown_user_created_is_audited(audit_events, settings):
assert create["user"]["id"] == str(user.pk)
@responses.activate
def test_menshen_unknown_user_email_already_used_is_audited(audit_events, settings):
def test_menshen_unknown_user_email_already_used_is_audited(
audit_events, settings, httpx2_mock
):
"""A user that is not created because its email is already used is a conflict
with the existing account, recorded with the sub that was refused."""
@@ -384,8 +376,8 @@ def test_menshen_unknown_user_email_already_used_is_audited(audit_events, settin
existing_user = UserFactory(sub=None, email="User@Example.com")
responses.add(
responses.POST, INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
httpx2_mock.add_response(
method="POST", url=INTROSPECTION_ENDPOINT, json=_introspection("new-sub")
)
response = _create_room()
@@ -0,0 +1,101 @@
"""Unit tests for the checks of the recording storage method settings."""
# pylint: disable=protected-access
from django.core.exceptions import ImproperlyConfigured
import pytest
from meet import settings
def make_configuration(**overrides):
"""Build a throwaway configuration pushing to Drive through a token exchange."""
attributes = {
"RECORDING_STORAGE_METHOD": "drive",
"RECORDING_DRIVE_AUTH_METHOD": "token_exchange",
"RECORDING_DRIVE_AUDIENCE": "drive",
"DRIVE_API_BASE_URL": "https://drive.example.com/external_api/v1.0",
"DRIVE_FRONTEND_BASE_URL": "https://drive.example.com",
"OIDC_STORE_ACCESS_TOKEN": True,
"OIDC_STORE_REFRESH_TOKEN_KEY": "key",
"MENSHEN_SERVER_URL": "https://menshen.example.com",
"MENSHEN_CLIENT_ID": "meet",
"MENSHEN_CLIENT_SECRET": "secret",
**overrides,
}
return type("StorageConfiguration", (settings.Test,), attributes)
def test_recording_storage_s3_email_needs_nothing():
"""The default method requires no other setting."""
configuration = make_configuration(
RECORDING_STORAGE_METHOD="s3_email",
RECORDING_DRIVE_AUTH_METHOD="unknown",
DRIVE_API_BASE_URL=None,
OIDC_STORE_ACCESS_TOKEN=False,
)
configuration._check_recording_storage()
def test_recording_storage_drive_with_token_exchange():
"""A complete token exchange configuration passes."""
make_configuration()._check_recording_storage()
def test_recording_storage_drive_with_access_token_needs_no_menshen():
"""The access token method does not need Menshen."""
configuration = make_configuration(
RECORDING_DRIVE_AUTH_METHOD="access_token",
RECORDING_DRIVE_AUDIENCE=None,
MENSHEN_SERVER_URL=None,
MENSHEN_CLIENT_ID=None,
MENSHEN_CLIENT_SECRET=None,
)
configuration._check_recording_storage()
def test_recording_storage_unknown_method():
"""An unknown method is refused."""
configuration = make_configuration(RECORDING_STORAGE_METHOD="ftp")
with pytest.raises(ImproperlyConfigured, match="RECORDING_STORAGE_METHOD"):
configuration._check_recording_storage()
def test_recording_storage_unknown_auth_method():
"""An unknown way to call Drive is refused."""
configuration = make_configuration(RECORDING_DRIVE_AUTH_METHOD="refresh_token")
with pytest.raises(ImproperlyConfigured, match="RECORDING_DRIVE_AUTH_METHOD"):
configuration._check_recording_storage()
@pytest.mark.parametrize(
"missing",
[
"DRIVE_API_BASE_URL",
"DRIVE_FRONTEND_BASE_URL",
"OIDC_STORE_REFRESH_TOKEN_KEY",
"MENSHEN_SERVER_URL",
"MENSHEN_CLIENT_ID",
"MENSHEN_CLIENT_SECRET",
"RECORDING_DRIVE_AUDIENCE",
],
)
def test_recording_storage_drive_missing_setting(missing):
"""Every setting the push needs is required, and named in the error."""
configuration = make_configuration(**{missing: None})
with pytest.raises(ImproperlyConfigured, match=missing):
configuration._check_recording_storage()
def test_recording_storage_drive_requires_stored_access_token():
"""Without the access token in the session, there is nothing to call Drive with."""
configuration = make_configuration(OIDC_STORE_ACCESS_TOKEN=False)
with pytest.raises(ImproperlyConfigured, match="OIDC_STORE_ACCESS_TOKEN"):
configuration._check_recording_storage()
+38
View File
@@ -19,6 +19,7 @@ from typing import List, Optional
from uuid import UUID, uuid4
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage
import aiohttp
@@ -27,6 +28,7 @@ import botocore
import magic
import phonenumbers
from asgiref.sync import async_to_sync
from cryptography.fernet import Fernet, InvalidToken
from livekit.api import ( # pylint: disable=E0611
AccessToken,
ListRoomsRequest,
@@ -457,6 +459,42 @@ def generate_upload_policy(file):
return policy
class SecretDecryptionError(Exception):
"""Raised when a stored secret cannot be decrypted."""
@lru_cache(maxsize=1)
def get_cipher_suite():
"""Return the Fernet key used to encrypt secrets at rest.
The same key as django-lasuite's OIDC token storage.
"""
key = settings.OIDC_STORE_REFRESH_TOKEN_KEY
if not key:
raise ImproperlyConfigured("OIDC_STORE_REFRESH_TOKEN_KEY setting is required.")
return Fernet(key)
def encrypt_secret(value: str) -> str:
"""Encrypt a secret meant to be stored at rest."""
return get_cipher_suite().encrypt(value.encode()).decode()
def decrypt_secret(value: str) -> str:
"""Decrypt a secret stored by `encrypt_secret`."""
try:
return get_cipher_suite().decrypt(value.encode()).decode()
except InvalidToken as exc:
raise SecretDecryptionError(
"The stored secret could not be decrypted."
) from exc
def generate_download_s3_url(
key: str, *, expires_in: int, override_domain: bool = True
):
+129
View File
@@ -695,6 +695,20 @@ class Base(Configuration):
OIDC_STORE_ID_TOKEN = values.BooleanValue(
default=True, environ_name="OIDC_STORE_ID_TOKEN", environ_prefix=None
)
# Required to call other La Suite applications on behalf of the user, e.g.
# to push a recording to their Drive.
OIDC_STORE_ACCESS_TOKEN = values.BooleanValue(
default=False, environ_name="OIDC_STORE_ACCESS_TOKEN", environ_prefix=None
)
OIDC_STORE_REFRESH_TOKEN = values.BooleanValue(
default=False, environ_name="OIDC_STORE_REFRESH_TOKEN", environ_prefix=None
)
# Fernet key used to encrypt OIDC tokens at rest, both the refresh token
# django-lasuite stores in the session and the access token stored on a
# recording. Generate one with `Fernet.generate_key()`.
OIDC_STORE_REFRESH_TOKEN_KEY = SecretFileValue(
None, environ_name="OIDC_STORE_REFRESH_TOKEN_KEY", environ_prefix=None
)
ALLOW_LOGOUT_GET_METHOD = values.BooleanValue(
default=True, environ_name="ALLOW_LOGOUT_GET_METHOD", environ_prefix=None
)
@@ -913,6 +927,72 @@ class Base(Configuration):
None, environ_name="RECORDING_MAX_DURATION", environ_prefix=None
)
# Where a finished video recording is made available (audio-only transcripts
# are not concerned):
# - "s3_email": it stays in the object storage, and everyone with access to it
# is emailed a download link.
# - "drive": it is also pushed to the Drive of the user who started it, in
# RECORDING_DRIVE_FOLDER_NAME, and shared with the room's owners and
# administrators. Only the starter is emailed, with a link to the file.
# The object storage copy is kept until it expires. Nobody is emailed when
# the push fails.
RECORDING_STORAGE_METHOD = values.Value(
"s3_email", environ_name="RECORDING_STORAGE_METHOD", environ_prefix=None
)
# How Meet calls Drive on behalf of the user who started the recording:
# - "token_exchange": their access token is exchanged with Menshen, when the
# recording starts, for a token targeting Drive (RECORDING_DRIVE_AUDIENCE).
# Its lifetime, set by Menshen's exchange rule, must outlast the recording.
# - "access_token": their access token itself, assumed to still be valid when
# the recording is over. Long recordings may fail to be pushed.
# Both require OIDC_STORE_ACCESS_TOKEN, and OIDC_STORE_REFRESH_TOKEN_KEY to
# encrypt the token while the recording runs.
RECORDING_DRIVE_AUTH_METHOD = values.Value(
"token_exchange",
environ_name="RECORDING_DRIVE_AUTH_METHOD",
environ_prefix=None,
)
# Folder, at the root of the user's Drive, recordings are pushed to. It is
# created when missing.
RECORDING_DRIVE_FOLDER_NAME = values.Value(
"Visio-Recordings",
environ_name="RECORDING_DRIVE_FOLDER_NAME",
environ_prefix=None,
)
# Audience Drive is registered under in Menshen, for "token_exchange".
RECORDING_DRIVE_AUDIENCE = values.Value(
None, environ_name="RECORDING_DRIVE_AUDIENCE", environ_prefix=None
)
# Space-separated scopes asked for in the token exchange. Menshen grants the
# ones its exchange rule allows when left empty.
RECORDING_DRIVE_SCOPE = values.Value(
None, environ_name="RECORDING_DRIVE_SCOPE", environ_prefix=None
)
# Attempts at pushing a recording to Drive, before giving up.
RECORDING_DRIVE_PUSH_MAX_ATTEMPTS = values.PositiveIntegerValue(
3, environ_name="RECORDING_DRIVE_PUSH_MAX_ATTEMPTS", environ_prefix=None
)
# Lifetime of the signed URL the worker downloads the recording from.
RECORDING_DRIVE_SIGNED_URL_EXPIRY_SECONDS = values.PositiveIntegerValue(
60 * 60,
environ_name="RECORDING_DRIVE_SIGNED_URL_EXPIRY_SECONDS",
environ_prefix=None,
)
# Base URL of Drive's external API, e.g. https://fichiers.numerique.gouv.fr/external_api/v1.0
DRIVE_API_BASE_URL = values.Value(
None, environ_name="DRIVE_API_BASE_URL", environ_prefix=None
)
# Base URL of Drive's interface, to link to the pushed file, e.g.
# https://fichiers.numerique.gouv.fr
DRIVE_FRONTEND_BASE_URL = values.Value(
None, environ_name="DRIVE_FRONTEND_BASE_URL", environ_prefix=None
)
# Development only: host:port to reach Drive's object storage at, when the
# domain Drive signs its upload URLs with is only resolvable from a browser.
DRIVE_UPLOAD_STORAGE_NETLOC = values.Value(
None, environ_name="DRIVE_UPLOAD_STORAGE_NETLOC", environ_prefix=None
)
# Recording encoding options for LiveKit Egress (video composite egress only).
# These settings affect screen recordings handled by VideoCompositeEgressService;
# they are silently ignored by AudioCompositeEgressService (audio-only transcript
@@ -1593,6 +1673,54 @@ class Base(Configuration):
f"'{cls.AUDIT_LOG_DATA_STREAM_NAMESPACE}' must not contain '-'."
)
@classmethod
def _check_recording_storage(cls):
"""Ensure the recording storage method has what it needs.
The values mirror RecordingDeliveryMethodChoices and DriveTokenTypeChoices,
models cannot be imported from the settings.
"""
methods = {"s3_email", "drive"}
if cls.RECORDING_STORAGE_METHOD not in methods:
raise ImproperlyConfigured(
f"RECORDING_STORAGE_METHOD must be one of {sorted(methods)}, "
f"got {cls.RECORDING_STORAGE_METHOD!r}."
)
if cls.RECORDING_STORAGE_METHOD != "drive":
return
auth_methods = {"token_exchange", "access_token"}
if cls.RECORDING_DRIVE_AUTH_METHOD not in auth_methods:
raise ImproperlyConfigured(
f"RECORDING_DRIVE_AUTH_METHOD must be one of {sorted(auth_methods)}, "
f"got {cls.RECORDING_DRIVE_AUTH_METHOD!r}."
)
required = [
"DRIVE_API_BASE_URL",
"DRIVE_FRONTEND_BASE_URL",
"OIDC_STORE_REFRESH_TOKEN_KEY",
]
if cls.RECORDING_DRIVE_AUTH_METHOD == "token_exchange":
required += [
"MENSHEN_SERVER_URL",
"MENSHEN_CLIENT_ID",
"MENSHEN_CLIENT_SECRET",
"RECORDING_DRIVE_AUDIENCE",
]
missing = [name for name in required if not getattr(cls, name)]
if missing:
raise ImproperlyConfigured(
f"RECORDING_STORAGE_METHOD=drive requires {', '.join(missing)}."
)
if not cls.OIDC_STORE_ACCESS_TOKEN:
raise ImproperlyConfigured(
"RECORDING_STORAGE_METHOD=drive requires OIDC_STORE_ACCESS_TOKEN: the "
"user's access token is what Meet calls Drive with, or exchanges."
)
@classmethod
def _configure_database_pool(cls):
"""Inject the psycopg pool options into the default database when enabled."""
@@ -1651,6 +1779,7 @@ class Base(Configuration):
)
cls._check_recording_encoding_maps()
cls._check_recording_storage()
cls._check_audit_log_data_stream_namespace()
cls._configure_database_pool()
+2 -1
View File
@@ -49,7 +49,7 @@ dependencies = [
"gunicorn==26.2.0",
"jsonschema==4.26.0",
"markdown==3.11.2",
"menshen-client==0.2.0",
"menshen-client==0.3.0",
"nested-multipart-parser==1.6.0",
"posthog==7.75.11",
"psycopg[binary,pool]==3.3.6",
@@ -80,6 +80,7 @@ dev = [
"django-extensions==4.1",
"drf-spectacular-sidecar==2026.10.1",
"freezegun==1.5.5",
"httpx2-pytest==2.0.0",
"ipdb==0.13.13",
"ipython==9.17.1",
"pyfakefs==6.2.0",
+89 -5
View File
@@ -167,6 +167,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/99/91/8acff4f5e50511b911bbccb72b8628a49c68ce14148cd9f6431094859a90/annotated_types-0.8.0-py3-none-any.whl", hash = "sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0", size = 13427, upload-time = "2026-07-23T20:16:12.938Z" },
]
[[package]]
name = "anyio"
version = "4.16.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "idna" },
{ name = "typing-extensions", marker = "python_full_version < '3.15'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/a1/98/7e457a3b014976887a050561955c0b76e1e7e2d6e27b78ecef2ef80518f2/anyio-4.16.0.tar.gz", hash = "sha256:59bb03251907983d1603d27c3087ddb1e93299ea2163adcdba37899a4fb12ffb", size = 310971, upload-time = "2026-11-01T11:20:07.282Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a9/16/7757fb84c819accc7d7e9af5291b261e4abb8627ee040f99e7d35ef2457a/anyio-4.16.0-py3-none-any.whl", hash = "sha256:c66ae634e0b8228396b801741beb3294326d4b6102f7bba4041c0dfb58c29026", size = 134521, upload-time = "2026-11-01T11:20:05.59Z" },
]
[[package]]
name = "asgiref"
version = "3.12.1"
@@ -1141,6 +1154,66 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/fe/85/7522a52e5e2f42faf1a129113ab63e548c42e103e9af395b7bfe65e403e2/gunicorn-26.2.0-py3-none-any.whl", hash = "sha256:bd249d0b3f7972f7432f0a6b6ff3b3ee2d129f70cd1ff6c09a9dd9e29a2b88e3", size = 228389, upload-time = "2026-08-24T15:05:57.67Z" },
]
[[package]]
name = "h11"
version = "0.16.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" },
]
[[package]]
name = "httpcore2"
version = "2.16.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "h11" },
{ name = "truststore" },
]
sdist = { url = "https://files.pythonhosted.org/packages/92/9d/df40b41f7db0370f82019820709244e7b660c52aa3da3c9e5c4e8141f6e6/httpcore2-2.16.2.tar.gz", hash = "sha256:6c519d0f7b44f7269fa9bbb4d2763db395a4a2370f046d8e8e0a4b38227815d2", size = 70064, upload-time = "2026-11-16T10:12:19.491Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/2a/e8/009c347feac27f8960605aa98d55ed263b5870dd4fd80b82fd1d00d5716c/httpcore2-2.16.2-py3-none-any.whl", hash = "sha256:16051ae2a42f776007543f32de9349a317b23d2cbb4e1456b4bac0e88b87419a", size = 85551, upload-time = "2026-11-16T10:12:16.674Z" },
]
[[package]]
name = "httpx2"
version = "2.16.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "anyio", marker = "sys_platform != 'emscripten'" },
{ name = "httpcore2", marker = "sys_platform != 'emscripten'" },
{ name = "httpx2-jsfetch", marker = "sys_platform == 'emscripten'" },
{ name = "idna" },
{ name = "truststore", marker = "sys_platform != 'emscripten'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/1c/77/6515121dc5ac3c743ad1bff5afe635bcd1a3f23cc40db3c5c89f7d02917d/httpx2-2.16.2.tar.gz", hash = "sha256:748b615678f07d8e3b183efe81ad13b655ca88bfc56ce4589219b2d442860574", size = 103370, upload-time = "2026-11-16T10:12:20.49Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/77/de/8c4306a3d6aa2495111986addf33a9e561eff4c47552e4c4b9251160d0ad/httpx2-2.16.2-py3-none-any.whl", hash = "sha256:f05c13aade4c45dbf1c9060647a1058f0acad62398fad96e741269edb33d46f5", size = 97893, upload-time = "2026-11-16T10:12:18.192Z" },
]
[[package]]
name = "httpx2-jsfetch"
version = "1.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/cd/c4/0e5636363151a2a1795e0a77617168b9ca438e1748ec05fc9b5687f93d64/httpx2_jsfetch-1.0.tar.gz", hash = "sha256:70a0e3eabfef7cce5ad9c629f7d01ca05e418f586646f4ddf14782e4c1454c60", size = 6872, upload-time = "2026-08-07T00:13:07.492Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/9b/43/832f631d32e4f1211caa2ba368317739fe71f0b8530e4c9d15dc454bac2a/httpx2_jsfetch-1.0-py3-none-any.whl", hash = "sha256:cb916b707601e69a07721aabc8f3f6659be3a6893bc1ff5c6f9e02241df2da32", size = 6382, upload-time = "2026-08-07T00:13:06.567Z" },
]
[[package]]
name = "httpx2-pytest"
version = "2.0.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "httpx2" },
{ name = "pytest" },
]
sdist = { url = "https://files.pythonhosted.org/packages/fe/2e/66762cb820f4857a8038181ee4deb679905dbd5a1447a7e82993e1c5ddc0/httpx2_pytest-2.0.0.tar.gz", hash = "sha256:0f7e3777be96016bb070c12a64f99e0f1d9437b5b374c7ca331bc95a398cd946", size = 60492, upload-time = "2026-09-04T09:09:57.791Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/42/77/f100314adb8bc833bd224616e269c8a5feb196b0baa9f7d634d2f36c4e1e/httpx2_pytest-2.0.0-py3-none-any.whl", hash = "sha256:b8a63711bc40edc163c22268800d50e21c4266bb9571240bcd0cbfaf69c33cf6", size = 21304, upload-time = "2026-09-04T09:09:56.392Z" },
]
[[package]]
name = "icdiff"
version = "2.0.10"
@@ -1428,6 +1501,7 @@ dev = [
{ name = "django-extensions" },
{ name = "drf-spectacular-sidecar" },
{ name = "freezegun" },
{ name = "httpx2-pytest" },
{ name = "ipdb" },
{ name = "ipython" },
{ name = "pyfakefs" },
@@ -1472,7 +1546,7 @@ requires-dist = [
{ name = "jsonschema", specifier = "==4.26.0" },
{ name = "livekit-api", specifier = "==1.2.2" },
{ name = "markdown", specifier = "==3.11.2" },
{ name = "menshen-client", specifier = "==0.2.0" },
{ name = "menshen-client", specifier = "==0.3.0" },
{ name = "mozilla-django-oidc", specifier = "==5.0.2" },
{ name = "nested-multipart-parser", specifier = "==1.6.0" },
{ name = "phonenumbers", specifier = "==9.0.41" },
@@ -1495,6 +1569,7 @@ dev = [
{ name = "django-extensions", specifier = "==4.1" },
{ name = "drf-spectacular-sidecar", specifier = "==2026.10.1" },
{ name = "freezegun", specifier = "==1.5.5" },
{ name = "httpx2-pytest", specifier = "==2.0.0" },
{ name = "ipdb", specifier = "==0.13.13" },
{ name = "ipython", specifier = "==9.17.1" },
{ name = "pyfakefs", specifier = "==6.2.0" },
@@ -1512,14 +1587,14 @@ dev = [
[[package]]
name = "menshen-client"
version = "0.2.0"
version = "0.3.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "requests" },
{ name = "httpx2" },
]
sdist = { url = "https://files.pythonhosted.org/packages/57/a2/5862b0a39d5f96301e1daff146445f591b1980412c20417162f5cfd6aa34/menshen_client-0.2.0.tar.gz", hash = "sha256:548c4224c38b2c844a76325b5a4b65da520ea9eba23aafb004da0f430a7e4fcf", size = 6326, upload-time = "2026-10-13T10:19:34.344Z" }
sdist = { url = "https://files.pythonhosted.org/packages/46/6c/71057f698c261b20bb969387494072010d4fea3029a5480942546c6d5443/menshen_client-0.3.0.tar.gz", hash = "sha256:b1a1d12a6277988e657e24ccc8a9ecf487d170bb9b0a0b10b1214eb8ee260308", size = 7611, upload-time = "2026-11-02T15:06:20.427Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/53/4d/932efd81c340d12d07b1c33633c6e7a4a2d0c9086ac0da7ffe9a1ce17068/menshen_client-0.2.0-py3-none-any.whl", hash = "sha256:415eaba30184452bc393b528c6088ed6e37cbd00ce60716aef9e2d9bd0697221", size = 7149, upload-time = "2026-10-13T10:19:33.272Z" },
{ url = "https://files.pythonhosted.org/packages/a5/c5/bef9dba4e39cd05aabe74d3488c393b4b2f963587df78c29b6ecdabe4a99/menshen_client-0.3.0-py3-none-any.whl", hash = "sha256:6cddbf3024a661cac72ea47fbe0bcfc4355ef51d39b944708a736835803be1f2", size = 7923, upload-time = "2026-11-02T15:06:19.288Z" },
]
[[package]]
@@ -2615,6 +2690,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/ad/66/0d785f0bc5e4315a96c989bb476d0fc07ea4f85132550c7b156ca2035d52/traitlets-5.16.1-py3-none-any.whl", hash = "sha256:f775618166caa0396c8e337099240f2bd3e5e917d203b2e6fbe21a58d3cb1f6b", size = 86211, upload-time = "2026-08-03T08:32:34.48Z" },
]
[[package]]
name = "truststore"
version = "0.10.5"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/ee/9f/c5201d42a484c061e528825fc8e2d565f5abd50a4ced6fb7d29c4ec99b2b/truststore-0.10.5.tar.gz", hash = "sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd", size = 28091, upload-time = "2026-10-12T22:27:31.808Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/51/e9/3a7820be2bb0fe53b6bc9c3be26d3d1158004e4c3ab953aa6840b955b1e9/truststore-0.10.5-py3-none-any.whl", hash = "sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c", size = 19017, upload-time = "2026-10-12T22:27:30.377Z" },
]
[[package]]
name = "types-protobuf"
version = "7.35.1.20260906"
@@ -0,0 +1,64 @@
<mjml>
<mj-include path="./partial/header.mjml" />
<mj-body mj-class="bg--blue-100">
<!--
We load django tags here so they appear in the body of the HTML output.
This ensures html-to-text also includes them in the plain text template.
-->
<mj-raw>{% load i18n static extra_tags %}</mj-raw>
<mj-wrapper css-class="wrapper" padding="5px 25px 0px 25px">
<mj-section css-class="wrapper-logo">
<mj-column>
<mj-image
align="center"
src="{{logo_img}}"
width="320px"
alt="{%trans 'Logo email' %} {{brandname}}"
/>
</mj-column>
</mj-section>
<mj-section mj-class="bg--white-100" padding="0px 20px 60px 20px">
<mj-column>
<mj-text align="center">
<h1>{% trans "Your recording is in your Drive!"%}</h1>
</mj-text>
<!-- Main Message -->
<mj-text>
{% blocktrans %}
Your recording of "{{room_name}}" on {{recording_date}} at {{recording_time}} has been saved to the "{{folder_name}}" folder of your Drive.
{% endblocktrans %}
</mj-text>
<mj-button
href="{{link}}"
background-color="#000091"
color="white"
padding-bottom="30px"
>
{% trans "Open in Drive"%}
</mj-button>
<mj-text>
{% blocktrans %}
If you have any questions or need assistance, please contact our support team at {{support_email}}.
{% endblocktrans %}
</mj-text>
<mj-divider
border-width="1px"
border-style="solid"
border-color="#DDDDDD"
width="30%"
align="center"
/>
<!-- Signature -->
<mj-text>
<p>
{% blocktrans %}
Thank you for using {{brandname}}.
{% endblocktrans %}
</p>
</mj-text>
</mj-column>
</mj-section>
</mj-wrapper>
</mj-body>
</mjml>