~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Approving an app is a page of its own, over the host's background

Merged chadtmiller.com asked to merge into feature/branding from chadtmiller.com/group-host:branding/authorize
.changeset/authorize-alone.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# Approving an app is a page of its own, over the host's background
The page an app's request is approved on is one card, without the console's header and footer: at its top, the host's name and logo and who is signed in, whose menu switches account, adds one or signs out. With one group to approve, Decline sits beside its button. "Technical details" and the operator's links are at the card's foot. `BACKGROUND_LIGHT_URL` and `BACKGROUND_DARK_URL` set the picture behind the card, served at `/img/background-light` and `/img/background-dark`, and `getBrand` names them as `backgrounds`.
crates/group-host/src/apps.rs+5−5
@@ -29,7 +29,7 @@ const KEEP_FOR: i64 = 10 * 60_000;
/// How many apps' logos are kept at once.
const KEEP_AT_MOST: usize = 100;
/// The most bytes a logo may be.
const LOGO_AT_MOST: usize = 256 * 1024;
pub(crate) const LOGO_AT_MOST: usize = 256 * 1024;
/// An app's logo: its type, as its bytes say, and its bytes.
#[derive(Debug, Clone, PartialEq)]
@@ -135,16 +135,16 @@ impl Host {
async fn read_logo(&self, id: &str, now: i64) -> Option<Logo> {
let view = self.client_view(id, now).await?;
self.read_image(view["logo"].as_str()?).await
self.read_image(view["logo"].as_str()?, LOGO_AT_MOST).await
}
/// The image at `url`, read as a logo is: from a public address, at
/// most [`LOGO_AT_MOST`] bytes, and only an image by its first bytes.
pub(crate) async fn read_image(&self, url: &str) -> Option<Logo> {
/// most `at_most` bytes, and only an image by its first bytes.
pub(crate) async fn read_image(&self, url: &str, at_most: usize) -> Option<Logo> {
let asked = self.guarded.get(url).ok()?;
let res = asked.send().await.ok()?;
let res = res.error_for_status().ok()?;
let bytes = capped(res, LOGO_AT_MOST).await?;
let bytes = capped(res, at_most).await?;
let kind = image_kind(&bytes)?;
Some(Logo {
kind,
crates/group-host/src/brand.rs+41−15
@@ -1,10 +1,12 @@
//! How the host shows itself, as its operator names it (`config::Brand`):
//! its name, logo and pages, for the console to draw (`getBrand`), and its
//! logo served from here, at `/img/host`, read as an app's logo is
//! (`apps`), so that a reader's browser asks no other server for it.
//! its name, logo, pages and backgrounds, for the console to draw
//! (`getBrand`), and its pictures served from here, read as an app's logo
//! is (`apps`), so that a reader's browser asks no other server for them:
//! its logo at `/img/host`, its backgrounds at `/img/background-light`
//! and `/img/background-dark`.
use crate::Host;
use crate::apps::{Logo, kept, served};
use crate::apps::{LOGO_AT_MOST, Logo, kept, served};
use crate::time::now_millis;
use axum::Json;
use axum::extract::State;
@@ -13,6 +15,9 @@ use axum::response::{IntoResponse, Response};
use serde_json::{Map, Value, json};
use std::sync::Arc;
/// The most bytes a background may be: a photograph, larger than a logo.
const BACKGROUND_AT_MOST: usize = 2 * 1024 * 1024;
/// The fields of `fields` that are set, as an object.
pub(crate) fn set<const N: usize>(fields: [(&str, &Option<String>); N]) -> Value {
let set = fields
@@ -21,8 +26,8 @@ pub(crate) fn set<const N: usize>(fields: [(&str, &Option<String>); N]) -> Value
Value::Object(set.collect::<Map<_, _>>())
}
/// How the host shows itself: its name and logo, and the links to its
/// operator's pages, each only when set.
/// How the host shows itself: its name and logo, the links to its
/// operator's pages, and its backgrounds, each only when set.
pub async fn get_brand(State(host): State<Arc<Host>>) -> Json<Value> {
let b = &host.config.brand;
let mut brand = set([("name", &b.name), ("logo", &b.logo)]);
@@ -32,22 +37,43 @@ pub async fn get_brand(State(host): State<Arc<Host>>) -> Json<Value> {
("termsOfService", &b.terms_of_service),
("support", &b.support),
]);
brand["backgrounds"] = set([("light", &b.background_light), ("dark", &b.background_dark)]);
Json(brand)
}
impl Host {
/// The host's logo, kept or read now: none when it names none, or
/// when what it names is no image.
pub async fn host_logo(&self, now: i64) -> Option<Logo> {
let url = self.config.brand.logo.as_deref()?;
kept(&self.host_logo, url, now, self.read_image(url)).await
/// The host's own picture `key` names, at `url`, kept or read now:
/// none when it names none, or when what it names is no image of at
/// most `at_most` bytes.
async fn own_image(&self, key: &str, url: Option<&str>, at_most: usize) -> Option<Logo> {
let url = url?;
let now = now_millis();
kept(&self.host_images, key, now, self.read_image(url, at_most)).await
}
}
/// The host's logo, for a page to draw: nothing when it has none.
pub async fn logo(State(host): State<Arc<Host>>) -> Response {
match host.host_logo(now_millis()).await {
Some(logo) => served(logo),
/// A picture for a page to draw, or nothing.
fn answer(image: Option<Logo>) -> Response {
match image {
Some(image) => served(image),
None => StatusCode::NOT_FOUND.into_response(),
}
}
/// The host's logo: nothing when it has none.
pub async fn logo(State(host): State<Arc<Host>>) -> Response {
let url = host.config.brand.logo.as_deref();
answer(host.own_image("logo", url, LOGO_AT_MOST).await)
}
/// The host's background in a light colour scheme: nothing when it has none.
pub async fn background_light(State(host): State<Arc<Host>>) -> Response {
let url = host.config.brand.background_light.as_deref();
answer(host.own_image("light", url, BACKGROUND_AT_MOST).await)
}
/// The host's background in a dark colour scheme: nothing when it has none.
pub async fn background_dark(State(host): State<Arc<Host>>) -> Response {
let url = host.config.brand.background_dark.as_deref();
answer(host.own_image("dark", url, BACKGROUND_AT_MOST).await)
}
crates/group-host/src/config.rs+8−0
@@ -106,6 +106,12 @@ pub struct Brand {
pub support: Option<String>,
/// Where its operator is written to, `CONTACT_EMAIL`.
pub contact_email: Option<String>,
/// The picture behind the card an app's request is approved on, in a
/// light colour scheme, `BACKGROUND_LIGHT_URL`, served at
/// `/img/background-light`.
pub background_light: Option<String>,
/// And in a dark one, `BACKGROUND_DARK_URL`, at `/img/background-dark`.
pub background_dark: Option<String>,
}
/// The most characters a host's name may be, as a page's header has room for.
@@ -144,6 +150,8 @@ impl Brand {
terms_of_service: page("TERMS_OF_SERVICE_URL")?,
support: page("SUPPORT_URL")?,
contact_email,
background_light: page("BACKGROUND_LIGHT_URL")?,
background_dark: page("BACKGROUND_DARK_URL")?,
})
}
}
crates/group-host/src/lib.rs+5−3
@@ -110,8 +110,8 @@ pub struct Host {
pub(crate) lexicons: permission_sets::Read,
/// Apps' logos, as read.
pub(crate) logos: apps::Logos,
/// Its own logo, as read.
pub(crate) host_logo: apps::Logos,
/// Its own pictures, its logo and backgrounds, as read.
pub(crate) host_images: apps::Logos,
/// The lines it logged, kept for its operators.
pub logs: Arc<logs::Logs>,
/// How it is used, counted for its operators.
@@ -159,7 +159,7 @@ impl Host {
handles: Default::default(),
lexicons: Default::default(),
logos: Default::default(),
host_logo: Default::default(),
host_images: Default::default(),
logs: Arc::new(logs),
stats,
limits,
@@ -486,6 +486,8 @@ pub(crate) fn routes(host: Arc<Host>) -> Router {
)
.route("/img/app", get(apps::logo))
.route("/img/host", get(brand::logo))
.route("/img/background-light", get(brand::background_light))
.route("/img/background-dark", get(brand::background_dark))
.route("/img/{did}/{cid}", get(blobs::image))
.route("/console/login", get(console_login::login))
.route("/console/move/login", get(account_move::login))
crates/group-host/tests/brand.rs+37−8
@@ -13,9 +13,9 @@ use std::sync::{Arc, Mutex};
const PNG: &[u8] = b"\x89PNG\r\n\x1a\n\0\0\0\rIHDR";
/// What `/img/host` answers: its status and bytes.
async fn host_logo(h: &Running) -> (u16, Vec<u8>) {
let res = h.http.get(format!("{}/img/host", h.url)).send().await;
/// What the host serves at `path`: its status and bytes.
async fn picture(h: &Running, path: &str) -> (u16, Vec<u8>) {
let res = h.http.get(format!("{}{path}", h.url)).send().await;
let res = res.unwrap();
(res.status().as_u16(), res.bytes().await.unwrap().to_vec())
}
@@ -25,12 +25,40 @@ async fn a_host_named_nothing_shows_the_consoles_own() {
let h = start(&[], false).await;
let (status, brand) = h.get("org.atgrp.internal.getBrand", "").await;
assert_eq!(status, 200, "{brand}");
assert_eq!(brand, json!({"links": {}}));
assert_eq!(brand, json!({"links": {}, "backgrounds": {}}));
let (status, described) = h.get("com.atproto.server.describeServer", "").await;
assert_eq!(status, 200, "{described}");
assert_eq!(described["links"], json!({}));
assert_eq!(described["contact"], json!({}));
assert_eq!(host_logo(&h).await.0, 404);
for path in ["/img/host", "/img/background-light", "/img/background-dark"] {
assert_eq!(picture(&h, path).await.0, 404, "{path}");
}
}
#[tokio::test]
async fn a_host_serves_its_backgrounds_larger_than_a_logo() {
// A photograph, past what a logo may be, and one past what any
// background may be.
let photo = [PNG, &[0; 300 * 1024]].concat();
let large = [PNG, &[0; 2 * 1024 * 1024]].concat();
let (light, dark) = (photo.clone(), large.clone());
let router = Router::new()
.route("/light.png", get(move || async move { light }))
.route("/dark.png", get(move || async move { dark }));
let site = serve(router).await;
let (light, dark) = (format!("{site}/light.png"), format!("{site}/dark.png"));
let h = start_reachable(&[
("BACKGROUND_LIGHT_URL", &light),
("BACKGROUND_DARK_URL", &dark),
("LOGO_URL", &light),
])
.await;
let (_, brand) = h.get("org.atgrp.internal.getBrand", "").await;
assert_eq!(brand["backgrounds"], json!({"light": light, "dark": dark}));
assert_eq!(picture(&h, "/img/background-light").await, (200, photo));
assert_eq!(picture(&h, "/img/background-dark").await.0, 404);
// The same picture, as a logo, is too large.
assert_eq!(picture(&h, "/img/host").await.0, 404);
}
#[tokio::test]
@@ -78,6 +106,7 @@ async fn a_host_shows_its_operators_name_logo_and_pages() {
"termsOfService": "https://riverside.example/terms",
"support": "https://riverside.example/help",
},
"backgrounds": {},
})
);
@@ -115,15 +144,15 @@ async fn a_host_shows_its_operators_name_logo_and_pages() {
// Kept as read: a logo changed on its server shows once the kept one
// is old, not before.
*logo.lock().unwrap() = b"no image".to_vec();
assert_eq!(host_logo(&h).await, (200, PNG.to_vec()));
assert_eq!(picture(&h, "/img/host").await, (200, PNG.to_vec()));
// A logo that is no image, or can't be read, is not served.
for path in ["logo.svg", "gone.png"] {
let url = format!("{site}/{path}");
let h = start_reachable(&[("LOGO_URL", &url)]).await;
assert_eq!(host_logo(&h).await.0, 404, "{path}");
assert_eq!(picture(&h, "/img/host").await.0, 404, "{path}");
}
// Nor is one at a private address, for a host on https.
let h = start(&[("LOGO_URL", &logo_url)], false).await;
assert_eq!(host_logo(&h).await.0, 404);
assert_eq!(picture(&h, "/img/host").await.0, 404);
}
crates/group-host/tests/config.rs+7−0
@@ -199,6 +199,11 @@ fn the_host_shows_itself_as_its_operator_names_it() {
("TERMS_OF_SERVICE_URL", "https://riverside.example/terms"),
("SUPPORT_URL", "http://help.riverside.test"),
("CONTACT_EMAIL", "hello@riverside.example"),
(
"BACKGROUND_LIGHT_URL",
"https://riverside.example/light.jpg",
),
("BACKGROUND_DARK_URL", "https://riverside.example/dark.jpg"),
])
.unwrap();
let some = |s: &str| Some(s.to_string());
@@ -212,6 +217,8 @@ fn the_host_shows_itself_as_its_operator_names_it() {
terms_of_service: some("https://riverside.example/terms"),
support: some("http://help.riverside.test"),
contact_email: some("hello@riverside.example"),
background_light: some("https://riverside.example/light.jpg"),
background_dark: some("https://riverside.example/dark.jpg"),
}
);
deploy/docker-compose.yml+2−0
@@ -52,6 +52,8 @@ services:
TERMS_OF_SERVICE_URL: ${GROUP_HOST_TERMS_OF_SERVICE_URL:-}
SUPPORT_URL: ${GROUP_HOST_SUPPORT_URL:-}
CONTACT_EMAIL: ${GROUP_HOST_CONTACT_EMAIL:-}
BACKGROUND_LIGHT_URL: ${GROUP_HOST_BACKGROUND_LIGHT_URL:-}
BACKGROUND_DARK_URL: ${GROUP_HOST_BACKGROUND_DARK_URL:-}
volumes:
# The database, blobs and keys: back it up (docs/deploying.md).
# Owned by uid 1000, the node user the image runs as.
docs/design/signing-in.md+14−4
@@ -223,10 +223,20 @@ it wouldn't, the way an account's PDS shows a request on its consent
page. It reads the scopes with the same parser (`@atproto/oauth-scopes`)
and lists them as that page's rows, in its order (Bluesky, chat, each
permission set, the repository, calling services, spaces). Each row's
details are a dialog away, and the scopes as asked sit behind "Technical
details". Each of the host's permission sets is named in its own words,
the `title` and `detail` of its lexicon, both those asked for and any
tier a group would give in place of one.
details are a dialog away. Each of the host's permission sets is named in
its own words, the `title` and `detail` of its lexicon, both those asked
for and any tier a group would give in place of one.
The page stands alone, one card without the console's header and footer,
so nothing on it leads away from answering. The card's top names the host
as its operator does (its logo and name) and who is signed in, whose menu
switches account, adds one or signs out, and nothing else. With one group
to approve, Decline sits beside its button; with more, it comes once after
them. The scopes as asked sit behind "Technical details" at the card's
foot, beside the links to the operator's pages. Behind the card is the
operator's background, `BACKGROUND_LIGHT_URL` or `BACKGROUND_DARK_URL` by
the reader's colour scheme (either standing in for the other), which the
host serves as it serves its logo, up to 2 MiB.
The client is named by its metadata: its `client_name`, its
`client_uri` and its `logo_uri`. The host gives the home page and the
docs/guides/shots/apps-activity-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-activity.png+0−0
A binary file, not shown.
docs/guides/shots/apps-approve-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-approve.png+0−0
A binary file, not shown.
docs/guides/shots/apps-approve.txt+3−5
@@ -1,12 +1,10 @@
- banner:
- main:
- link "Atmosphere Groups":
- group: "@bob.test"
- main:
- heading "Sign in an app" [level=1]
- paragraph:
- strong: Darkroom
- text: wants to sign in as one of your groups.
- button "Technical details"
- link "Night shift":
- text: "@nightshift.groups.test"
- list:
@@ -14,6 +12,6 @@
- listitem:
- text: Repository Publish changes
- button "Details"
- button "Sign it in as Night shift"
- button "Decline"
- contentinfo: console.group-host.internal runs Atmosphere Groups
- button "Sign it in as Night shift"
- button "Technical details"
docs/guides/shots/apps-made-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-made.png+0−0
A binary file, not shown.
docs/guides/shots/apps-signed-in-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-signed-in.png+0−0
A binary file, not shown.
docs/guides/signing-in-as-a-group.md+7−5
docs/reference/api.md+2−2
docs/reference/config.md+2−1
docs/deploying.md+1−1
lexicons/org/atgrp/internal/getBrand.json+21−1
web/src/lib/molecules/AskedScopes.sveltenew+14−0
web/src/lib/molecules/SiteBrand.sveltenew+14−0
web/src/lib/molecules/SiteLinks.sveltenew+13−0
web/src/lib/molecules/UserMenu.svelte+16−10
web/src/lib/organisms/AuthorizeRequest.svelte+30−24
web/src/lib/organisms/SiteFooter.svelte+3−7
web/src/lib/organisms/SiteHeader.svelte+3−9
web/src/lib/templates/Alone.sveltenew+32−0
web/src/lib/brand.ts+2−2
web/src/routes/authorize/+page.server.ts+4−3
web/src/routes/authorize/+page.svelte+33−4
web/src/routes/+layout.svelte+14−9
web/src/app.css+49−3
web/src/app.d.ts+2−1