OXYGENHUB
◆ image-check oxygenhub / crates / hub / src / web / admin.rs
19.4 KiB · Rust · last changed Adding an assistant: provider presets and the endpoint's own model list 1 month ago source blame history raw
19bb31ff Andy McCall ↶ 1
//! Site administration (hub spec §6.3 `/admin/*`): accounts, registration
2
//! mode and invitations, the audit log.
3
4
use super::settings::csrf;
5
use super::{filters, Error, Page, Shell};
6
use crate::auth::{self, Viewer};
7
use crate::db::accounts;
8
use crate::Shared;
9
use askama::Template;
10
use axum::extract::{Form, State};
11
use serde::Deserialize;
12
13
#[derive(Template)]
14
#[template(path = "admin.html")]
15
pub struct AdminPage {
16
    shell: Shell,
17
    accounts: Vec<accounts::Account>,
18
    orgs: Vec<accounts::Organisation>,
19
    mode: String,
20
    invitations: Vec<(String, Option<i64>, i64)>,
21
    audit: Vec<accounts::AuditRow>,
22
    repos: usize,
23
    notice: Option<String>,
3556d08e Andy McCall ↶ 24
    /// Mail settings (#101): the SMTP URL with its password masked, the
25
    /// From address, whether mail is on, and the administrator's own
26
    /// address for a test message.
27
    mail_smtp: String,
28
    mail_from: String,
29
    mail_enabled: bool,
30
    my_email: String,
e8e7158b Andy McCall ↶ 31
    /// The audit log's next page: rows older than this id (#110).
32
    audit_older: Option<i64>,
e71846aa Andy McCall ↶ 33
    /// The site's AI assistants and prompt (#97).
34
    assistants: super::assistants::Panel,
2a83f530 Andy McCall ↶ 35
    /// The site's Flow variables (#102).
36
    variables: super::variables::Panel,
4ac01a73 Andy McCall ↶ 37
    /// The site's Flow secrets (#107).
38
    secrets: super::secrets::Panel,
83940d53 Andy McCall ↶ 39
    /// Sign-in providers (#106).
40
    providers: Vec<super::signin::ProviderView>,
19bb31ff Andy McCall ↶ 41
}
42
43
fn require_admin(viewer: &Viewer, shell: &Shell) -> Result<accounts::Account, Error> {
44
    match viewer.account() {
45
        Some(a) if a.is_admin => Ok(a.clone()),
46
        _ => Err(Error::not_found(shell.clone())),
47
    }
48
}
49
50
async fn admin_page(app: &Shared, shell: Shell, notice: Option<String>) -> Result<Page<AdminPage>, Error> {
e8e7158b Andy McCall ↶ 51
    admin_page_at(app, shell, notice, None).await
52
}
53
54
/// The audit log shows this many rows a page.
55
const AUDIT_PAGE: i64 = 50;
56
57
async fn admin_page_at(app: &Shared, shell: Shell, notice: Option<String>, audit_before: Option<i64>) -> Result<Page<AdminPage>, Error> {
19bb31ff Andy McCall ↶ 58
    let e = |e| Error::from_db(shell.clone(), e);
59
    let accounts_list = accounts::accounts(&app.db).await.map_err(e)?;
60
    let orgs = accounts::orgs(&app.db).await.map_err(e)?;
61
    let mode = super::session::registration_mode(app).await;
62
    let invitations = accounts::invitations(&app.db).await.map_err(e)?;
e8e7158b Andy McCall ↶ 63
    let mut audit = accounts::audit_page(&app.db, audit_before, AUDIT_PAGE + 1).await.map_err(e)?;
64
    let audit_older = if audit.len() as i64 > AUDIT_PAGE {
65
        audit.truncate(AUDIT_PAGE as usize);
66
        audit.last().map(|r| r.id)
67
    } else {
68
        None
69
    };
19bb31ff Andy McCall ↶ 70
    let repos = crate::db::repos::list(&app.db).await.map_err(e)?.len();
3556d08e Andy McCall ↶ 71
    let mail = crate::mail::settings(app);
72
    let my_email = match shell.user.as_deref() {
73
        Some(u) => accounts::account_by_name(&app.db, u).await.map_err(e)?.map(|a| a.email).unwrap_or_default(),
74
        None => String::new(),
75
    };
e71846aa Andy McCall ↶ 76
    let assistants = super::assistants::panel(app, &site_assistants()).await.map_err(e)?;
2a83f530 Andy McCall ↶ 77
    let variables = super::variables::panel(app, &site_assistants()).await.map_err(e)?;
4ac01a73 Andy McCall ↶ 78
    let secrets = super::secrets::panel(app, &site_assistants()).await.map_err(e)?;
83940d53 Andy McCall ↶ 79
    let providers = super::signin::provider_views(app).await.map_err(e)?;
3556d08e Andy McCall ↶ 80
    Ok(Page(AdminPage {
83940d53 Andy McCall ↶ 81
        providers,
e71846aa Andy McCall ↶ 82
        assistants,
2a83f530 Andy McCall ↶ 83
        variables,
4ac01a73 Andy McCall ↶ 84
        secrets,
3556d08e Andy McCall ↶ 85
        shell,
86
        accounts: accounts_list,
87
        orgs,
88
        mode,
89
        invitations,
90
        audit,
91
        repos,
92
        notice,
93
        mail_smtp: crate::mail::masked(&mail.smtp),
94
        mail_from: mail.from.clone(),
95
        mail_enabled: !mail.smtp.is_empty() && !mail.from.is_empty(),
96
        my_email,
e8e7158b Andy McCall ↶ 97
        audit_older,
3556d08e Andy McCall ↶ 98
    }))
99
}
100
101
#[derive(Deserialize)]
102
pub struct MailForm {
103
    #[serde(rename = "_csrf")]
104
    csrf_token: String,
105
    #[serde(default)]
106
    smtp: String,
107
    #[serde(default)]
108
    from: String,
109
}
110
111
/// `POST /admin/mail`: the SMTP URL and From address (#101). The URL
112
/// comes back masked, so a masked value left as it was keeps the stored
113
/// one; an empty URL turns mail off.
114
pub async fn set_mail(State(app): State<Shared>, viewer: Viewer, Form(f): Form<MailForm>) -> Result<Page<AdminPage>, Error> {
115
    let shell = Shell::new(&app, "/admin", &viewer);
116
    let me = require_admin(&viewer, &shell)?;
117
    csrf(&viewer, &f.csrf_token, &shell)?;
118
    let current = crate::mail::settings(&app);
119
    let smtp = f.smtp.trim();
120
    let smtp = if !current.smtp.is_empty() && smtp == crate::mail::masked(&current.smtp) { current.smtp.clone() } else { smtp.to_string() };
121
    let from = f.from.trim().to_string();
122
    if !smtp.is_empty() && !(smtp.starts_with("smtp://") || smtp.starts_with("smtps://") || smtp.starts_with("file://")) {
123
        return admin_page(
124
            &app,
125
            shell,
126
            Some("The SMTP URL starts with smtp:// or smtps:// (file:///dir writes messages to a directory, for testing).".into()),
127
        )
128
        .await;
129
    }
130
    if !smtp.is_empty() && from.is_empty() {
131
        return admin_page(&app, shell, Some("A From address is needed: OxygenHub <[email protected]>.".into())).await;
132
    }
133
    crate::mail::save(&app, &smtp, &from).await.map_err(|e| Error::from_db(shell.clone(), e))?;
134
    accounts::audit(&app.db, Some(&me), "admin.mail", if smtp.is_empty() { "off" } else { "on" }, &from).await.ok();
135
    admin_page(&app, shell, Some(if smtp.is_empty() { "Mail is off.".into() } else { "Mail settings saved.".into() })).await
136
}
137
138
/// `POST /admin/mail/test`: a message to the administrator's own address.
139
pub async fn test_mail(
140
    State(app): State<Shared>,
141
    viewer: Viewer,
142
    Form(f): Form<super::session::CsrfForm>,
143
) -> Result<Page<AdminPage>, Error> {
144
    let shell = Shell::new(&app, "/admin", &viewer);
145
    let me = require_admin(&viewer, &shell)?;
146
    csrf(&viewer, &f.csrf, &shell)?;
147
    if !crate::mail::enabled(&app) {
148
        return admin_page(&app, shell, Some("Mail is off; save an SMTP URL and a From address first.".into())).await;
149
    }
150
    if me.email.is_empty() {
151
        return admin_page(&app, shell, Some("Your account has no email address to send the test to.".into())).await;
152
    }
153
    let notice = match crate::mail::send(
154
        &app,
155
        me.name(),
156
        &me.email,
157
        "Test message",
158
        "This is a test message from your hub's mail settings. If you can read it, mail works.",
159
    )
160
    .await
161
    {
162
        Ok(()) => format!("Sent a test message to {}.", me.email),
163
        Err(e) => format!("Sending failed: {e}"),
164
    };
165
    admin_page(&app, shell, Some(notice)).await
19bb31ff Andy McCall ↶ 166
}
167
e8e7158b Andy McCall ↶ 168
#[derive(Deserialize)]
169
pub struct IndexQuery {
170
    audit_before: Option<i64>,
171
}
172
173
pub async fn index(
174
    State(app): State<Shared>,
175
    viewer: Viewer,
176
    axum::extract::Query(q): axum::extract::Query<IndexQuery>,
177
) -> Result<Page<AdminPage>, Error> {
19bb31ff Andy McCall ↶ 178
    let shell = Shell::new(&app, "/admin", &viewer);
179
    require_admin(&viewer, &shell)?;
e8e7158b Andy McCall ↶ 180
    admin_page_at(&app, shell, None, q.audit_before).await
19bb31ff Andy McCall ↶ 181
}
182
183
#[derive(Deserialize)]
184
pub struct ModeForm {
185
    #[serde(rename = "_csrf")]
186
    csrf_token: String,
187
    mode: String,
188
}
189
190
pub async fn set_mode(State(app): State<Shared>, viewer: Viewer, Form(f): Form<ModeForm>) -> Result<Page<AdminPage>, Error> {
191
    let shell = Shell::new(&app, "/admin", &viewer);
192
    let me = require_admin(&viewer, &shell)?;
193
    csrf(&viewer, &f.csrf_token, &shell)?;
194
    if !matches!(f.mode.as_str(), "open" | "invite" | "closed") {
195
        return Err(Error::bad(shell, "mode is open, invite or closed"));
196
    }
197
    accounts::set_setting(&app.db, "registration_mode", &f.mode).await.map_err(|e| Error::from_db(shell.clone(), e))?;
198
    accounts::audit(&app.db, Some(&me), "admin.registration", &f.mode, "").await.ok();
199
    admin_page(&app, shell, Some(format!("Registration is {}.", f.mode))).await
200
}
201
202
pub async fn invite(State(app): State<Shared>, viewer: Viewer, Form(f): Form<super::session::CsrfForm>) -> Result<Page<AdminPage>, Error> {
203
    let shell = Shell::new(&app, "/admin", &viewer);
204
    let me = require_admin(&viewer, &shell)?;
205
    csrf(&viewer, &f.csrf, &shell)?;
206
    let code = auth::random_hex(12);
207
    accounts::create_invitation(&app.db, &code, Some(me.id)).await.map_err(|e| Error::from_db(shell.clone(), e))?;
208
    accounts::audit(&app.db, Some(&me), "admin.invite", &code, "").await.ok();
209
    admin_page(&app, shell, Some(format!("Invitation created: {}/register?invite={code}", app.config.base_url()))).await
210
}
211
212
#[derive(Deserialize)]
213
pub struct AccountForm {
214
    #[serde(rename = "_csrf")]
215
    csrf_token: String,
216
    username: String,
217
    action: String,
6a178055 Andy McCall ↶ 218
    /// For delete: the username typed again.
219
    #[serde(default)]
220
    confirm: String,
19bb31ff Andy McCall ↶ 221
}
222
223
pub async fn account(State(app): State<Shared>, viewer: Viewer, Form(f): Form<AccountForm>) -> Result<Page<AdminPage>, Error> {
224
    let shell = Shell::new(&app, "/admin", &viewer);
225
    let me = require_admin(&viewer, &shell)?;
226
    csrf(&viewer, &f.csrf_token, &shell)?;
227
    let Some(target) = accounts::account_by_name(&app.db, f.username.trim()).await.map_err(|e| Error::from_db(shell.clone(), e))? else {
228
        return admin_page(&app, shell, Some("No such account.".into())).await;
229
    };
6a178055 Andy McCall ↶ 230
    if target.id == me.id && matches!(f.action.as_str(), "ban" | "demote" | "disable" | "delete") {
19bb31ff Andy McCall ↶ 231
        return admin_page(&app, shell, Some("Not on yourself.".into())).await;
232
    }
233
    let e = |e| Error::from_db(shell.clone(), e);
6a178055 Andy McCall ↶ 234
    // The hub must keep an admin who can sign in (oxygenhub#81).
235
    if target.is_admin && matches!(f.action.as_str(), "disable" | "delete") {
236
        let others =
237
            accounts::accounts(&app.db).await.map_err(e)?.into_iter().filter(|a| a.is_admin && !a.blocked() && a.id != target.id).count();
238
        if others == 0 {
239
            return admin_page(&app, shell, Some(format!("{} is the last admin who can sign in.", target.username))).await;
240
        }
241
    }
242
    if f.action == "delete" {
243
        if f.confirm.trim() != target.username {
244
            return admin_page(&app, shell, Some(format!("Not deleted: type {} to confirm.", target.username))).await;
245
        }
246
        let repos = crate::db::repos::list_by_owner(&app.db, &target.username).await.map_err(e)?;
247
        let orgs = accounts::orgs_owned_only_by(&app.db, target.id).await.map_err(e)?;
248
        if !repos.is_empty() || !orgs.is_empty() {
249
            let mut held: Vec<String> = repos.iter().map(|r| r.slug()).collect();
250
            held.extend(orgs.iter().map(|o| format!("organisation {o} (sole owner)")));
251
            return admin_page(
252
                &app,
253
                shell,
254
                Some(format!("Not deleted: {} still owns {}. Transfer or delete them first.", target.username, held.join(", "))),
255
            )
256
            .await;
257
        }
258
        accounts::delete_account(&app.db, target.id, &target.username).await.map_err(e)?;
259
        accounts::audit(&app.db, Some(&me), "admin.account.delete", &target.username, "").await.ok();
260
        return admin_page(&app, shell, Some(format!("{} deleted; the name stays retired.", target.username))).await;
261
    }
34beb1a7 Andy McCall ↶ 262
    if f.action == "reset_link" {
6a178055 Andy McCall ↶ 263
        if target.blocked() {
264
            return admin_page(&app, shell, Some("A banned or disabled account cannot be reset.".into())).await;
34beb1a7 Andy McCall ↶ 265
        }
266
        let url = super::recovery::admin_reset_link(&app, &me, &target).await.map_err(e)?;
267
        return admin_page(
268
            &app,
269
            shell,
270
            Some(format!("Reset link for {} (works once, for 24 hours; shown only now): {url}", target.username)),
271
        )
272
        .await;
273
    }
19bb31ff Andy McCall ↶ 274
    match f.action.as_str() {
275
        "ban" => accounts::set_banned(&app.db, target.id, true).await.map_err(e)?,
276
        "unban" => accounts::set_banned(&app.db, target.id, false).await.map_err(e)?,
6a178055 Andy McCall ↶ 277
        "disable" => accounts::set_disabled(&app.db, target.id, true).await.map_err(e)?,
278
        "enable" => accounts::set_disabled(&app.db, target.id, false).await.map_err(e)?,
19bb31ff Andy McCall ↶ 279
        "promote" => accounts::set_admin(&app.db, target.id, true).await.map_err(e)?,
280
        "demote" => accounts::set_admin(&app.db, target.id, false).await.map_err(e)?,
281
        _ => return Err(Error::bad(shell, "unknown action")),
282
    }
283
    accounts::audit(&app.db, Some(&me), &format!("admin.account.{}", f.action), &target.username, "").await.ok();
284
    admin_page(&app, shell, Some(format!("{}: {}.", target.username, f.action))).await
285
}
8fb35df7 Andy McCall ↶ 286
287
// ------------------------------------------------------------------ storage
288
289
/// One repository's footprint on disk.
290
pub struct StorageRow {
291
    pub slug: String,
292
    pub bytes: u64,
293
    /// Objects not yet in a pack.
294
    pub loose: usize,
295
    pub packs: usize,
296
}
297
298
#[derive(Template)]
299
#[template(path = "admin_storage.html")]
300
pub struct StoragePage {
301
    shell: Shell,
302
    rows: Vec<StorageRow>,
303
    total: u64,
304
    notice: Option<String>,
305
    error: Option<String>,
306
}
307
308
/// Size, loose objects and packs under a repository directory.
309
fn footprint(dir: &std::path::Path) -> (u64, usize, usize) {
310
    let (mut bytes, mut loose, mut packs) = (0u64, 0usize, 0usize);
311
    let mut stack = vec![dir.to_path_buf()];
312
    while let Some(d) = stack.pop() {
313
        let Ok(rd) = std::fs::read_dir(&d) else { continue };
314
        for e in rd.flatten() {
315
            let Ok(ft) = e.file_type() else { continue };
316
            if ft.is_dir() {
317
                stack.push(e.path());
318
            } else if ft.is_file() {
319
                bytes += e.metadata().map(|m| m.len()).unwrap_or(0);
320
                let p = e.path();
321
                if p.components().any(|c| c.as_os_str() == "loose") {
322
                    loose += 1;
323
                } else if p.extension().is_some_and(|x| x == "pack") {
324
                    packs += 1;
325
                }
326
            }
327
        }
328
    }
329
    (bytes, loose, packs)
330
}
331
332
async fn storage_page(app: &Shared, shell: Shell, notice: Option<String>, error: Option<String>) -> Result<Page<StoragePage>, Error> {
333
    let repos = crate::db::repos::list(&app.db).await.map_err(|e| Error::from_db(shell.clone(), e))?;
334
    let dirs: Vec<(String, std::path::PathBuf)> =
335
        repos.iter().filter_map(|r| crate::repos::RepoName::new(&r.owner, &r.name).map(|n| (n.to_string(), app.repos.dir(&n)))).collect();
336
    let mut rows = tokio::task::spawn_blocking(move || {
337
        dirs.into_iter()
338
            .map(|(slug, dir)| {
339
                let (bytes, loose, packs) = footprint(&dir);
340
                StorageRow { slug, bytes, loose, packs }
341
            })
342
            .collect::<Vec<_>>()
343
    })
344
    .await
345
    .unwrap_or_default();
346
    rows.sort_by_key(|r| std::cmp::Reverse(r.bytes));
347
    let total = rows.iter().map(|r| r.bytes).sum();
348
    Ok(Page(StoragePage { shell, rows, total, notice, error }))
349
}
350
351
pub async fn storage(State(app): State<Shared>, viewer: Viewer) -> Result<Page<StoragePage>, Error> {
352
    let shell = Shell::new(&app, "/admin/storage", &viewer);
353
    require_admin(&viewer, &shell)?;
354
    storage_page(&app, shell, None, None).await
355
}
356
357
#[derive(Deserialize)]
358
pub struct MaintainForm {
359
    #[serde(rename = "_csrf")]
360
    csrf_token: String,
361
    /// `owner/name`, or `*` for every repository.
362
    repo: String,
363
}
364
365
/// `POST /admin/storage`: `oxy gc` on one repository or all of them, under
366
/// each repository's write lock, with the grace period kept.
367
pub async fn maintain(State(app): State<Shared>, viewer: Viewer, Form(f): Form<MaintainForm>) -> Result<Page<StoragePage>, Error> {
368
    let shell = Shell::new(&app, "/admin/storage", &viewer);
369
    let me = require_admin(&viewer, &shell)?;
370
    csrf(&viewer, &f.csrf_token, &shell)?;
371
    let names: Vec<crate::repos::RepoName> = if f.repo == "*" {
372
        crate::db::repos::list(&app.db)
373
            .await
374
            .map_err(|e| Error::from_db(shell.clone(), e))?
375
            .iter()
376
            .filter_map(|r| crate::repos::RepoName::new(&r.owner, &r.name))
377
            .collect()
378
    } else {
379
        match crate::repos::RepoName::parse(&f.repo) {
380
            Some(n) if app.repos.exists(&n) => vec![n],
381
            _ => return storage_page(&app, shell, None, Some(format!("No repository {}.", f.repo))).await,
382
        }
383
    };
384
    let (mut packed, mut pruned, mut freed, mut failed) = (0usize, 0usize, 0u64, Vec::new());
385
    for name in &names {
386
        match app.repos.write(name, |r, _| r.gc(false).map_err(crate::repos::RepoError::Oxy)).await {
387
            Ok(rep) => {
388
                packed += rep.packed.objects;
389
                pruned += rep.pruned.objects;
390
                freed += rep.pruned.bytes + rep.packed.raw_bytes.saturating_sub(rep.packed.packed_bytes);
391
            }
392
            Err(e) => failed.push(format!("{name}: {e}")),
393
        }
394
    }
395
    let summary = format!(
396
        "Maintained {} repositor{}: {packed} loose objects packed, {pruned} unreachable objects pruned, about {} saved.",
397
        names.len(),
398
        if names.len() == 1 { "y" } else { "ies" },
399
        crate::render::bytes(freed)
400
    );
401
    accounts::audit(&app.db, Some(&me), "admin.gc", &f.repo, &summary).await.ok();
402
    let error = (!failed.is_empty()).then(|| failed.join("; "));
403
    storage_page(&app, shell, Some(summary), error).await
404
}
e71846aa Andy McCall ↶ 405
2a83f530 Andy McCall ↶ 406
fn site_assistants() -> crate::levels::At {
407
    crate::levels::At::site()
e71846aa Andy McCall ↶ 408
}
409
410
/// `POST /admin/assistants`: the site's assistants and prompt (#97).
411
pub async fn assistants(
412
    State(app): State<Shared>,
413
    viewer: Viewer,
414
    Form(f): Form<super::assistants::AssistantForm>,
415
) -> Result<Page<AdminPage>, Error> {
416
    let shell = Shell::new(&app, "/admin", &viewer);
417
    require_admin(&viewer, &shell)?;
418
    csrf(&viewer, &f.csrf_token, &shell)?;
419
    let outcome = super::assistants::apply(&app, &viewer, &site_assistants(), f).await.map_err(|e| Error::from_db(shell.clone(), e))?;
420
    admin_page(&app, shell, Some(outcome.unwrap_or_else(|e| e))).await
421
}
2a83f530 Andy McCall ↶ 422
423
/// `POST /admin/variables`: the site's Flow variables (#102).
424
pub async fn variables(
425
    State(app): State<Shared>,
426
    viewer: Viewer,
427
    Form(f): Form<super::variables::VariableForm>,
428
) -> Result<Page<AdminPage>, Error> {
429
    let shell = Shell::new(&app, "/admin", &viewer);
430
    require_admin(&viewer, &shell)?;
431
    csrf(&viewer, &f.csrf_token, &shell)?;
432
    let outcome = super::variables::apply(&app, &viewer, &site_assistants(), f).await.map_err(|e| Error::from_db(shell.clone(), e))?;
433
    admin_page(&app, shell, Some(outcome.unwrap_or_else(|e| e))).await
434
}
4ac01a73 Andy McCall ↶ 435
436
/// `POST /admin/secrets`: the site's Flow secrets (#107).
437
pub async fn secrets(
438
    State(app): State<Shared>,
439
    viewer: Viewer,
440
    Form(f): Form<super::secrets::SecretForm>,
441
) -> Result<Page<AdminPage>, Error> {
442
    let shell = Shell::new(&app, "/admin", &viewer);
443
    require_admin(&viewer, &shell)?;
444
    csrf(&viewer, &f.csrf_token, &shell)?;
445
    let outcome = super::secrets::apply(&app, &viewer, &site_assistants(), f).await.map_err(|e| Error::from_db(shell.clone(), e))?;
446
    admin_page(&app, shell, Some(outcome.unwrap_or_else(|e| e))).await
447
}
83940d53 Andy McCall ↶ 448
449
/// `POST /admin/signin`: a sign-in provider's client id, secret and switch (#106).
450
pub async fn signin(
451
    State(app): State<Shared>,
452
    viewer: Viewer,
453
    Form(f): Form<super::signin::ProviderForm>,
454
) -> Result<Page<AdminPage>, Error> {
455
    let shell = Shell::new(&app, "/admin", &viewer);
456
    require_admin(&viewer, &shell)?;
457
    csrf(&viewer, &f.csrf_token, &shell)?;
458
    let outcome = super::signin::apply(&app, &viewer, f).await.map_err(|e| Error::from_db(shell.clone(), e))?;
459
    admin_page(&app, shell, Some(outcome.unwrap_or_else(|e| e))).await
460
}
155cab14 Andy McCall ↶ 461
462
/// `POST /admin/assistants/models`: what a provider offers, as JSON (#109).
463
pub async fn assistant_models(
464
    State(app): State<Shared>,
465
    viewer: Viewer,
466
    Form(f): Form<super::assistants::ModelsForm>,
467
) -> Result<axum::Json<serde_json::Value>, Error> {
468
    let shell = Shell::new(&app, "/admin", &viewer);
469
    require_admin(&viewer, &shell)?;
470
    csrf(&viewer, &f.csrf_token, &shell)?;
471
    Ok(axum::Json(super::assistants::models(&app, &site_assistants(), f).await.map_err(|e| Error::from_db(shell.clone(), e))?))
472
}