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
+1
-1
@@ -216,7 +216,7 @@ pub async fn logout(
|
||||
Extension(user): Extension<User>,
|
||||
headers: HeaderMap,
|
||||
) -> Result<Response, AppError> {
|
||||
if user.local {
|
||||
if user.local || st.cfg.demo() {
|
||||
return Ok(Redirect::to(HOME).into_response());
|
||||
}
|
||||
if let Some(id) = session::cookie_value(&headers, SESSION_COOKIE) {
|
||||
|
||||
@@ -693,6 +693,10 @@ pub(crate) struct Checked {
|
||||
sha256: String,
|
||||
}
|
||||
|
||||
/// What an upload in the demo says: it takes no one's files.
|
||||
pub(crate) const DEMO_NO_UPLOADS: &str = "Uploads are off in the demo, so nobody's files land here. \
|
||||
The demo's own documents are on the Documents tabs, and they print in the packs.";
|
||||
|
||||
/// The files, checked: a type the app takes (by the file's first bytes),
|
||||
/// not empty, not too large, not uploaded before for this person or company.
|
||||
pub(crate) async fn check_files(
|
||||
@@ -702,6 +706,11 @@ pub(crate) async fn check_files(
|
||||
errors: &mut Errors,
|
||||
) -> anyhow::Result<Vec<Checked>> {
|
||||
let mut problems: Vec<String> = Vec::new();
|
||||
if st.cfg.demo() {
|
||||
// the demo keeps no one's files: only the ones it came with
|
||||
forms::err(errors, "file", DEMO_NO_UPLOADS);
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
if up.files.is_empty() && up.too_big.is_empty() && up.empty.is_empty() {
|
||||
problems.push("Choose a file to upload.".into());
|
||||
}
|
||||
|
||||
@@ -1036,6 +1036,13 @@ pub async fn add_version(
|
||||
"Say what this version is, such as: the label's changes of Nov 21.",
|
||||
);
|
||||
}
|
||||
if st.cfg.demo() && form.file.is_some() {
|
||||
err(
|
||||
&mut errors,
|
||||
"file",
|
||||
"Uploads are off in the demo. Paste the text instead; it is kept as the version.",
|
||||
);
|
||||
}
|
||||
if form.too_big {
|
||||
err(
|
||||
&mut errors,
|
||||
|
||||
+7
-2
@@ -43,7 +43,8 @@ pub struct AppState {
|
||||
templates: Environment<'static>,
|
||||
pub flows: Flows,
|
||||
provider: RwLock<Option<Arc<oidc::Provider>>>,
|
||||
/// The form token of local development, which has no sessions.
|
||||
/// The form token of local development and of the demo, which have no
|
||||
/// sessions.
|
||||
local_csrf: String,
|
||||
/// The documents' files; none in local development without a place
|
||||
/// and a key for them.
|
||||
@@ -58,8 +59,11 @@ impl AppState {
|
||||
.user_agent(concat!("visa/", env!("CARGO_PKG_VERSION")))
|
||||
.build()?;
|
||||
let files = cfg.files.as_ref().map(Store::open).transpose()?;
|
||||
let mut templates = templates()?;
|
||||
// the demo's note on every page, the back office's and the client's
|
||||
templates.add_global("demo", cfg.demo());
|
||||
Ok(Arc::new(AppState {
|
||||
templates: templates()?,
|
||||
templates,
|
||||
files,
|
||||
cfg,
|
||||
db,
|
||||
@@ -493,6 +497,7 @@ async fn gate(State(st): State<Arc<AppState>>, mut req: Request, next: Next) ->
|
||||
}
|
||||
let user = match &st.cfg.auth {
|
||||
Auth::Disabled => Some(User::local(&st.local_csrf)),
|
||||
Auth::Demo => Some(User::demo(&st.local_csrf)),
|
||||
Auth::Oidc(_) => match session::cookie_value(req.headers(), SESSION_COOKIE) {
|
||||
Some(id) => match session::get(&st.db, &id).await {
|
||||
Ok(u) => u,
|
||||
|
||||
Reference in new issue
Block a user