Demo mode (VISA_DEMO=1) for demoapp.lannadesk.com
For a public demo: no login on any address, everyone is "Demo visitor" (actor demo), a note at the top of every page, the back office's and the client's (#demo-note), and the invented demo data added at start when the database is empty (the server drops it every night). Every file upload is refused with a message (documents, the office photo, the client's uploads; a contract version keeps its text without the file), a mail server in its settings is refused, so nothing leaves it, and it needs a place for the files and their key (the demo's own files and the signed copies). seed-demo also runs in it. Sign out leads home. Checked: config test (address, files, no mail), tests/demo.rs (the note, an upload refused and nothing kept, a version with text only, the journal's actor), a local run on an empty database (seeds itself: 27 documents, the clients and contracts) and screenshots light and dark, desk and phone (PROBLEMS: 0).
This commit is contained in:
1 parent
422ee2ec2c
commit
329b181c4f
13 files changed
+265
-26
No files matched your search
+43
-22
@@ -19,7 +19,8 @@ Usage: visa [COMMAND]
|
||||
Commands:
|
||||
serve run the web server (default); applies pending migrations first
|
||||
migrate apply pending database migrations and exit
|
||||
seed-demo add invented demo people and documents (local development only)
|
||||
seed-demo add invented demo people and documents (local development and the
|
||||
demo; the demo also does it itself at start)
|
||||
files-check read every document's file back and compare it with its upload;
|
||||
list files without a document (exit status 1 on any problem)
|
||||
files-migrate --from DIR
|
||||
@@ -91,29 +92,13 @@ async fn run(cmd: &str) -> Result<()> {
|
||||
let cfg = Config::from_env()?;
|
||||
ensure!(
|
||||
!cfg.login_enabled(),
|
||||
"seed-demo writes invented people and runs only in local development \
|
||||
(VISA_INSECURE_NO_LOGIN=1, no VISA_OIDC_ISSUER)"
|
||||
"seed-demo writes invented people and runs only in local development or the \
|
||||
demo (VISA_INSECURE_NO_LOGIN=1 or VISA_DEMO=1, no VISA_OIDC_ISSUER)"
|
||||
);
|
||||
let pool = db::connect(&cfg).await?;
|
||||
db::migrate(&pool).await?;
|
||||
if seed::demo(&pool, dates::today()).await? {
|
||||
println!("demo people added");
|
||||
} else {
|
||||
println!("demo people are there already");
|
||||
}
|
||||
match &cfg.files {
|
||||
Some(_) => {
|
||||
let store = store(&cfg)?;
|
||||
let n = seed::demo_documents(&pool, &store, dates::today()).await?;
|
||||
println!("demo documents added: {n}");
|
||||
}
|
||||
None => println!("no demo documents: documents are off (no place for them)"),
|
||||
}
|
||||
let store = cfg.files.as_ref().map(|_| store(&cfg)).transpose()?;
|
||||
if seed::legal::demo(&pool, store.as_ref(), dates::today()).await? {
|
||||
println!("demo clients and contracts added");
|
||||
} else {
|
||||
println!("demo clients and contracts are there already");
|
||||
for line in seed_demo(&cfg, &pool).await? {
|
||||
println!("{line}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -189,8 +174,15 @@ async fn serve() -> Result<()> {
|
||||
let cfg = Config::from_env()?;
|
||||
let pool = db::connect(&cfg).await?;
|
||||
db::migrate(&pool).await?;
|
||||
if cfg.demo() {
|
||||
// an empty database (the server's nightly reset) gets the demo data
|
||||
for line in seed_demo(&cfg, &pool).await? {
|
||||
info!("demo: {line}");
|
||||
}
|
||||
}
|
||||
let listen = cfg.listen;
|
||||
let login = cfg.login_enabled();
|
||||
let demo = cfg.demo();
|
||||
let st = web::AppState::new(cfg, pool)?;
|
||||
match &st.files {
|
||||
Some(s) => {
|
||||
@@ -215,7 +207,9 @@ async fn serve() -> Result<()> {
|
||||
let listener = tokio::net::TcpListener::bind(listen)
|
||||
.await
|
||||
.with_context(|| format!("cannot listen on {listen}"))?;
|
||||
if !login {
|
||||
if demo {
|
||||
info!("the public demo: no login, invented data, no uploads, no mail (VISA_DEMO)");
|
||||
} else if !login {
|
||||
info!("no login: VISA_INSECURE_NO_LOGIN is set (loopback only)");
|
||||
}
|
||||
info!("listening on http://{listen}");
|
||||
@@ -226,6 +220,33 @@ async fn serve() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Adds the invented demo data where it is missing: people, their
|
||||
/// documents, clients and contracts. What it did, a line each.
|
||||
async fn seed_demo(cfg: &Config, pool: &sqlx::PgPool) -> Result<Vec<String>> {
|
||||
let mut out = Vec::new();
|
||||
out.push(if seed::demo(pool, dates::today()).await? {
|
||||
"demo people added".to_string()
|
||||
} else {
|
||||
"demo people are there already".to_string()
|
||||
});
|
||||
let store = cfg.files.as_ref().map(|_| store(cfg)).transpose()?;
|
||||
match &store {
|
||||
Some(s) => {
|
||||
let n = seed::demo_documents(pool, s, dates::today()).await?;
|
||||
out.push(format!("demo documents added: {n}"));
|
||||
}
|
||||
None => out.push("no demo documents: documents are off (no place for them)".into()),
|
||||
}
|
||||
out.push(
|
||||
if seed::legal::demo(pool, store.as_ref(), dates::today()).await? {
|
||||
"demo clients and contracts added".to_string()
|
||||
} else {
|
||||
"demo clients and contracts are there already".to_string()
|
||||
},
|
||||
);
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
async fn shutdown() {
|
||||
let ctrl_c = async {
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
|
||||
Reference in new issue
Block a user