Skip to content

Commit deee4b1

Browse files
authored
Close sign-ups quietly: someone who signs in without an account goes on a waitlist table (forge account, login, name, email, how they arrived) and sees one line, 'VisualCI opens in about 48 hours. We'll email you at <email>.'; no account, organization, session or email; an MCP client's newcomer stops at the forge callback, so never reaches consent or gets a token; existing users unchanged; on in production (settings.waitlist), VISUALCI_WAITLIST=1 for tests (#49)
1 parent 12bbc71 commit deee4b1

10 files changed

Lines changed: 293 additions & 0 deletions

File tree

‎server/config/production.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ settings:
136136
# Baked into both images from docker/renderer.version, so the server and the renderers always agree.
137137
renderer_version: "<%= get_env(name="RENDERER_VERSION") %>"
138138
dev_login: false
139+
# Sign-ups are closed until the rebuild opens: someone new goes on the waitlist (models::waitlist)
140+
waitlist: true
139141
<% if get_env(name="VISUALCI_GITLAB_CLIENT_ID", default="") != "" %>
140142
# GitLab sign-in (VisualCI's OAuth application) and the VisualCI bot user's token (statuses, MR notes, access).
141143
gitlab:

‎server/migration/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mod m20261202_000039_repository_id;
4646
mod m20261202_000040_closed_builds;
4747
mod m20261202_000041_build_creator;
4848
mod m20261202_000042_build_groups;
49+
mod m20261203_000046_waitlist;
4950

5051
pub struct Migrator;
5152

@@ -98,6 +99,7 @@ impl MigratorTrait for Migrator {
9899
Box::new(m20261202_000040_closed_builds::Migration),
99100
Box::new(m20261202_000041_build_creator::Migration),
100101
Box::new(m20261202_000042_build_groups::Migration),
102+
Box::new(m20261203_000046_waitlist::Migration),
101103
// inject-above (do not remove this comment)
102104
]
103105
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! The waitlist (closed sign-ups, 3 Dec 2026): someone who signs in without an account gets no account or organization,
2+
//! only a row here, and Nathan writes to them when VisualCI opens.
3+
use sea_orm_migration::prelude::*;
4+
5+
pub struct Migration;
6+
7+
impl MigrationName for Migration {
8+
fn name(&self) -> &str {
9+
"m20261203_000046_waitlist"
10+
}
11+
}
12+
13+
#[async_trait::async_trait]
14+
impl MigrationTrait for Migration {
15+
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
16+
m.get_connection()
17+
.execute_unprepared(
18+
"CREATE TABLE waitlist (
19+
id BIGSERIAL PRIMARY KEY,
20+
forge TEXT NOT NULL,
21+
site TEXT NOT NULL DEFAULT '',
22+
forge_user_id TEXT NOT NULL,
23+
login TEXT NOT NULL,
24+
name TEXT,
25+
email TEXT,
26+
source TEXT NOT NULL,
27+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
28+
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
29+
UNIQUE (forge, site, forge_user_id)
30+
);",
31+
)
32+
.await?;
33+
Ok(())
34+
}
35+
36+
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
37+
m.get_connection().execute_unprepared("DROP TABLE waitlist;").await?;
38+
Ok(())
39+
}
40+
}

‎server/src/access.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ pub async fn identity_owner(db: &DatabaseConnection, id: &crate::forge::Identity
133133
.map(|i| i.user_id))
134134
}
135135

136+
/// Whether a forge sign-in would make a new account: its identity isn't anyone's, it isn't being linked to the
137+
/// signed-in user, and none of its trusted emails is an account's. With sign-ups closed, such a person goes on the
138+
/// waitlist instead (`models::waitlist`).
139+
///
140+
/// # Errors
141+
/// On a database error.
142+
pub async fn is_new_person(db: &DatabaseConnection, sign_in: &SignIn, link_to: Option<&users::Model>) -> Result<bool> {
143+
if link_to.is_some() || identity_owner(db, &sign_in.identity).await?.is_some() {
144+
return Ok(false);
145+
}
146+
for address in sign_in.identity.trusted_emails() {
147+
let found = users::Entity::find()
148+
.filter(sea_orm::sea_query::Expr::cust_with_values("lower(email) = $1", [address.clone()]))
149+
.one(db)
150+
.await?;
151+
if found.is_some() {
152+
return Ok(false);
153+
}
154+
}
155+
Ok(true)
156+
}
157+
136158
/// The user a forge sign-in belongs to, and whether it was created just now:
137159
/// 1. the user with this forge identity;
138160
/// 2. else the signed-in user, who asked to link it (the caller decides: see `session::may_finish`);

‎server/src/controllers/session.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ async fn forge_callback(
277277
let owner = access::identity_owner(&ctx.db, &sign_in.identity).await?;
278278
let acts_for_current = may_finish(current.as_ref().map(|u| (u.id, u.pid)), link_for, owner)?;
279279
let link_to = current.as_ref().filter(|_| acts_for_current);
280+
// Sign-ups closed: someone new goes on the waitlist, with no account, organization, session or email
281+
if settings.waitlist() && access::is_new_person(&ctx.db, &sign_in, link_to).await? {
282+
let return_to = jar.get(RETURN_COOKIE).and_then(|c| safe_return(c.value()));
283+
let source = crate::models::waitlist::source(&ctx.db, return_to.as_deref()).await?;
284+
crate::models::waitlist::record(&ctx.db, &sign_in.identity, &source).await?;
285+
let jar = jar.remove(Cookie::from(STATE_COOKIE)).remove(Cookie::from(RETURN_COOKIE));
286+
return Ok((jar, crate::models::waitlist::page(&sign_in.identity)).into_response());
287+
}
280288
let (user, created) = access::user_for_sign_in(&ctx.db, &sign_in, link_to).await?;
281289
access::after_sign_in(&ctx.db, &settings, &user, &sign_in).await?;
282290
let return_to = jar.get(RETURN_COOKIE).and_then(|c| safe_return(c.value()));
@@ -393,6 +401,11 @@ async fn dev_login(
393401
if let Some(forge) = params.forge {
394402
let sign_in = forge.sign_in(&params.email);
395403
let current = user_from_jar(&ctx, &jar).await.ok();
404+
if settings.waitlist() && access::is_new_person(&ctx.db, &sign_in, current.as_ref()).await? {
405+
let source = crate::models::waitlist::source(&ctx.db, params.return_to.as_deref()).await?;
406+
crate::models::waitlist::record(&ctx.db, &sign_in.identity, &source).await?;
407+
return Ok(crate::models::waitlist::page(&sign_in.identity));
408+
}
396409
let (user, created) = access::user_for_sign_in(&ctx.db, &sign_in, current.as_ref()).await?;
397410
access::after_sign_in(&ctx.db, &settings, &user, &sign_in).await?;
398411
let return_to = params.return_to.as_deref().and_then(safe_return);

‎server/src/models/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ pub mod snapshots;
3131
pub mod user_tokens;
3232
pub mod users;
3333
pub mod variants;
34+
pub mod waitlist;

‎server/src/models/waitlist.rs‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//! The waitlist (closed sign-ups): someone who signs in without an account is written here instead of getting one.
2+
//! Nathan reads it and writes to them himself when VisualCI opens; nothing is emailed from here.
3+
4+
use loco_rs::prelude::*;
5+
use sea_orm::{DbBackend, Statement};
6+
7+
use crate::forge::Identity;
8+
9+
/// Record a sign-in on the waitlist: once per forge account, with its newest name, email and how they arrived.
10+
///
11+
/// # Errors
12+
/// On a database error.
13+
pub async fn record(db: &DatabaseConnection, identity: &Identity, source: &str) -> ModelResult<()> {
14+
let email = identity.trusted_emails().first().cloned();
15+
db.execute_raw(Statement::from_sql_and_values(
16+
DbBackend::Postgres,
17+
"INSERT INTO waitlist (forge, site, forge_user_id, login, name, email, source) \
18+
VALUES ($1, $2, $3, $4, $5, $6, $7) \
19+
ON CONFLICT (forge, site, forge_user_id) DO UPDATE SET login = EXCLUDED.login, \
20+
name = COALESCE(EXCLUDED.name, waitlist.name), email = COALESCE(EXCLUDED.email, waitlist.email), \
21+
last_seen_at = now()",
22+
[
23+
identity.forge.as_str().into(),
24+
identity.site.clone().into(),
25+
identity.id.clone().into(),
26+
identity.login.clone().into(),
27+
identity.name.clone().into(),
28+
email.into(),
29+
source.into(),
30+
],
31+
))
32+
.await?;
33+
Ok(())
34+
}
35+
36+
/// How they arrived: `web`, or `mcp: <client's name>` when the sign-in came from an MCP client's authorization.
37+
///
38+
/// # Errors
39+
/// On a database error.
40+
pub async fn source(db: &DatabaseConnection, return_to: Option<&str>) -> ModelResult<String> {
41+
let Some(client_id) = return_to.and_then(crate::oauth::connecting_client) else { return Ok("web".to_string()) };
42+
let name = db
43+
.query_one_raw(Statement::from_sql_and_values(
44+
DbBackend::Postgres,
45+
"SELECT name FROM oauth_clients WHERE client_id = $1",
46+
[client_id.clone().into()],
47+
))
48+
.await?
49+
.and_then(|r| r.try_get::<Option<String>>("", "name").ok().flatten());
50+
Ok(format!("mcp: {}", name.unwrap_or(client_id)))
51+
}
52+
53+
/// The one page someone on the waitlist sees.
54+
#[must_use]
55+
pub fn page(identity: &Identity) -> Response {
56+
let line = match identity.trusted_emails().first() {
57+
Some(email) => format!("VisualCI opens in about 48 hours. We'll email you at {}.", escape(email)),
58+
None => "VisualCI opens in about 48 hours.".to_string(),
59+
};
60+
let html = format!(
61+
"<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" \
62+
content=\"width=device-width, initial-scale=1\"><title>VisualCI</title><style>body{{font:16px/1.5 \
63+
system-ui,sans-serif;margin:0;min-height:100vh;display:grid;place-items:center;padding:16px;color:#1a1a1a;\
64+
background:#fff}}@media (prefers-color-scheme:dark){{body{{color:#eee;background:#111}}}}p{{max-width:32rem;\
65+
margin:0}}</style></head><body><p>{line}</p></body></html>"
66+
);
67+
(
68+
[
69+
(axum::http::header::CONTENT_TYPE, "text/html; charset=utf-8"),
70+
(axum::http::header::CACHE_CONTROL, "no-store"),
71+
],
72+
html,
73+
)
74+
.into_response()
75+
}
76+
77+
fn escape(s: &str) -> String {
78+
s.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;").replace('"', "&quot;")
79+
}

‎server/src/settings.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ pub struct Settings {
3838
/// Lets `/auth/dev-login` sign anyone in. Development and tests only.
3939
#[serde(default)]
4040
pub dev_login: bool,
41+
/// Sign-ups are closed: someone signing in without an account goes on the waitlist (`models::waitlist`) instead
42+
/// of getting one. `VISUALCI_WAITLIST=1` turns it on too (tests).
43+
#[serde(default)]
44+
pub waitlist: bool,
45+
}
46+
47+
impl Settings {
48+
/// Whether sign-ups are closed: the setting, or `VISUALCI_WAITLIST=1`, read each time so a test can turn it on.
49+
#[must_use]
50+
pub fn waitlist(&self) -> bool {
51+
self.waitlist || std::env::var("VISUALCI_WAITLIST").is_ok_and(|v| v == "1")
52+
}
4153
}
4254

4355
#[derive(Clone, Debug, Deserialize)]

‎server/tests/requests/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ mod open_source;
2121
mod public_projects;
2222
mod render_metrics;
2323
mod staff;
24+
mod waitlist;

‎server/tests/requests/waitlist.rs‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//! Closed sign-ups: an existing user signs in as before; someone new goes on the waitlist with no account,
2+
//! organization, session or email, and so never reaches an MCP client's consent step or gets a token.
3+
4+
use loco_rs::testing::prelude::*;
5+
use serial_test::serial;
6+
use visualci_server::{app::App, models::users};
7+
8+
/// Turns sign-ups off for one test, and back on when it ends (even when it fails).
9+
struct Closed;
10+
11+
impl Closed {
12+
fn new() -> Self {
13+
// SAFETY: the tests here run one at a time (#[serial]), and nothing else reads the environment meanwhile.
14+
unsafe { std::env::set_var("VISUALCI_WAITLIST", "1") };
15+
Self
16+
}
17+
}
18+
19+
impl Drop for Closed {
20+
fn drop(&mut self) {
21+
// SAFETY: as above.
22+
unsafe { std::env::remove_var("VISUALCI_WAITLIST") };
23+
}
24+
}
25+
26+
fn sign_in(email: &str, id: &str, login: &str, return_to: Option<&str>) -> serde_json::Value {
27+
serde_json::json!({ "email": email, "forge": { "id": id, "login": login }, "return_to": return_to })
28+
}
29+
30+
async fn waitlist_rows(ctx: &loco_rs::prelude::AppContext, login: &str) -> Vec<(String, Option<String>)> {
31+
use sea_orm::{ConnectionTrait, DbBackend, Statement};
32+
ctx.db
33+
.query_all_raw(Statement::from_sql_and_values(
34+
DbBackend::Postgres,
35+
"SELECT source, email FROM waitlist WHERE login = $1",
36+
[login.into()],
37+
))
38+
.await
39+
.unwrap()
40+
.into_iter()
41+
.map(|r| (r.try_get("", "source").unwrap(), r.try_get("", "email").unwrap()))
42+
.collect()
43+
}
44+
45+
#[tokio::test]
46+
#[serial]
47+
async fn an_existing_user_signs_in_and_someone_new_goes_on_the_waitlist() {
48+
request::<App, _, _>(|request, ctx| async move {
49+
let suffix = &uuid::Uuid::new_v4().to_string()[..8];
50+
let (old_email, old_login) = (format!("old-{suffix}@example.com"), format!("old-{suffix}"));
51+
// An account made while sign-ups were open
52+
let r =
53+
request.post("/auth/dev-login").json(&sign_in(&old_email, &format!("1{suffix}"), &old_login, None)).await;
54+
assert_eq!(r.status_code(), 200, "{}", r.text());
55+
56+
let _closed = Closed::new();
57+
// They still sign in, and nothing goes on the waitlist for them
58+
let r =
59+
request.post("/auth/dev-login").json(&sign_in(&old_email, &format!("1{suffix}"), &old_login, None)).await;
60+
assert_eq!(r.status_code(), 200, "{}", r.text());
61+
assert!(r.text().contains("\"ok\""), "signed in: {}", r.text());
62+
assert!(waitlist_rows(&ctx, &old_login).await.is_empty());
63+
64+
// Someone new: the page, a row, and no account or session
65+
let (new_email, new_login) = (format!("new-{suffix}@example.com"), format!("new-{suffix}"));
66+
let r =
67+
request.post("/auth/dev-login").json(&sign_in(&new_email, &format!("2{suffix}"), &new_login, None)).await;
68+
assert_eq!(r.status_code(), 200, "{}", r.text());
69+
assert!(
70+
r.text().contains(&format!("VisualCI opens in about 48 hours. We'll email you at {new_email}.")),
71+
"{}",
72+
r.text()
73+
);
74+
assert!(r.headers().get("set-cookie").is_none(), "no session");
75+
assert!(users::Model::find_by_email(&ctx.db, &new_email).await.is_err(), "no account");
76+
assert_eq!(waitlist_rows(&ctx, &new_login).await, vec![("web".to_string(), Some(new_email.clone()))]);
77+
78+
// Again, from an MCP client's sign-in: still no account, and the row says where they came from
79+
let r = request
80+
.post("/auth/dev-login")
81+
.json(&sign_in(
82+
&new_email,
83+
&format!("2{suffix}"),
84+
&new_login,
85+
Some("/oauth/authorize?client_id=claude-test&response_type=code"),
86+
))
87+
.await;
88+
assert!(r.text().contains("VisualCI opens in about 48 hours"), "{}", r.text());
89+
assert!(users::Model::find_by_email(&ctx.db, &new_email).await.is_err(), "still no account");
90+
assert_eq!(waitlist_rows(&ctx, &new_login).await.len(), 1, "one row per person");
91+
})
92+
.await;
93+
}
94+
95+
#[tokio::test]
96+
#[serial]
97+
async fn someone_on_the_waitlist_gets_no_mcp_token() {
98+
request::<App, _, _>(|request, ctx| async move {
99+
let _closed = Closed::new();
100+
let suffix = &uuid::Uuid::new_v4().to_string()[..8];
101+
let email = format!("mcp-{suffix}@example.com");
102+
let r = request
103+
.post("/auth/dev-login")
104+
.json(&sign_in(
105+
&email,
106+
&format!("3{suffix}"),
107+
&format!("mcp-{suffix}"),
108+
Some("/oauth/authorize?client_id=x"),
109+
))
110+
.await;
111+
assert!(r.text().contains("VisualCI opens in about 48 hours"), "{}", r.text());
112+
// With no session, the authorization page asks them to sign in: there's no consent step to approve, so no
113+
// code and no token
114+
assert!(r.headers().get("set-cookie").is_none(), "no session");
115+
let page: serde_json::Value =
116+
request.get("/api/ui/oauth/authorize?client_id=x&response_type=code").await.json();
117+
assert_ne!(page["status"], "consent", "{page}");
118+
assert!(users::Model::find_by_email(&ctx.db, &email).await.is_err());
119+
})
120+
.await;
121+
}

0 commit comments

Comments
 (0)