g1t/crates/contracts/src/identity.rs

1,455 lines49,627 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

API and MCP server, Rust identity service, registration, site redesign1//! The identity service: accounts, credentials and sessions.
2//!
3//! Each `*Args` struct is the argument of the method of the same name,
4//! served at `POST /rpc/<method>`.
5
6use serde::{Deserialize, Serialize};
7
8use crate::User;
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct SshKey {
13 pub id: String,
14 pub title: String,
15 pub fingerprint: String,
RFC 3339 timestamps in identity and repos16 /// RFC 3339.
17 pub created_at: String,
API and MCP server, Rust identity service, registration, site redesign18}
19
20#[derive(Clone, Debug, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct AccessToken {
23 pub id: String,
24 pub name: String,
RFC 3339 timestamps in identity and repos25 /// RFC 3339.
26 pub created_at: String,
Agents as a team: lifecycle, merge queue, billing and a new shell27 /// RFC 3339, to within a few minutes. Null until it is first used.
28 pub last_used_at: Option<String>,
29 /// For a workspace's token, the username of the member who made it.
30 /// Null once that account is gone, and on personal tokens.
31 pub created_by: Option<String>,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step32 /// Its scopes, as `resource:level`. Null: full access.
33 #[serde(default)]
34 pub scopes: Option<Vec<String>>,
35 /// Made before tokens had scopes: full access until someone narrows it.
36 #[serde(default)]
37 pub legacy: bool,
38 /// RFC 3339. Null: it does not expire.
39 #[serde(default)]
40 pub expires_at: Option<String>,
API and MCP server, Rust identity service, registration, site redesign41}
42
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look43/// `sign_in`: verifies a username, or any confirmed email address of the
44/// account, and its password, for website sign-in. Wrong passwords are
45/// counted against the account and `client`, and past a limit nothing is
46/// checked for a while (see identity's `throttle.rs`).
API and MCP server, Rust identity service, registration, site redesign47/// Returns `Outcome<SignedIn>`.
48#[derive(Debug, Serialize, Deserialize)]
49pub struct SignInArgs {
50 pub username: String,
51 pub password: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look52 /// Who is asking, such as the visitor's IP address, for rate limits.
53 #[serde(default)]
54 pub client: Option<String>,
API and MCP server, Rust identity service, registration, site redesign55}
56
57#[derive(Debug, Serialize, Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct SignedIn {
60 pub user: User,
61 pub session_token: String,
62}
63
64/// `sign_out` and `user_for_session`.
65#[derive(Debug, Serialize, Deserialize)]
66#[serde(rename_all = "camelCase")]
67pub struct SessionArgs {
68 pub session_token: String,
69}
70
71/// `user_for_git_credentials`: the account password or an access token.
72#[derive(Debug, Serialize, Deserialize)]
73pub struct GitCredentialsArgs {
74 pub username: String,
75 pub secret: String,
76}
77
78/// `user_for_access_token`.
79#[derive(Debug, Serialize, Deserialize)]
80pub struct TokenArgs {
81 pub token: String,
82}
83
84/// `user_for_ssh_key`.
85#[derive(Debug, Serialize, Deserialize)]
86pub struct FingerprintArgs {
87 pub fingerprint: String,
88}
89
90/// `user_by_username`.
91#[derive(Debug, Serialize, Deserialize)]
92pub struct UsernameArgs {
93 pub username: String,
94}
95
What happened across an outcome, as a feed beside its graph96/// `usernames`: the names behind account and workspace ids, as events and
97/// other records store them. Returns a map from id to name; ids it does
98/// not know are left out.
99#[derive(Debug, Serialize, Deserialize)]
100pub struct UsernamesArgs {
101 pub ids: Vec<String>,
102}
103
API and MCP server, Rust identity service, registration, site redesign104/// `list_ssh_keys` and `list_access_tokens`.
105#[derive(Debug, Serialize, Deserialize)]
106pub struct UserArgs {
107 pub user: User,
108}
109
110/// `add_ssh_key`: `public_key` is one line in OpenSSH format.
111/// Returns `Outcome<SshKey>`.
112#[derive(Debug, Serialize, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct AddSshKeyArgs {
115 pub user: User,
116 pub title: String,
117 pub public_key: String,
118}
119
120/// `remove_ssh_key` and `remove_access_token`.
121#[derive(Debug, Serialize, Deserialize)]
122pub struct RemoveArgs {
123 pub user: User,
124 pub id: String,
125}
126
Agents as a team: lifecycle, merge queue, billing and a new shell127/// `create_access_token`: a token that acts as `user`. For a workspace
128/// acting through a token of its own, the new token belongs to that
129/// workspace too.
API and MCP server, Rust identity service, registration, site redesign130#[derive(Debug, Serialize, Deserialize)]
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)131#[serde(rename_all = "camelCase")]
API and MCP server, Rust identity service, registration, site redesign132pub struct CreateAccessTokenArgs {
133 pub user: User,
134 pub name: String,
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)135 /// When set, the token stops working after this many seconds and is
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step136 /// left out of the user's token list, unless `listed`. Used for hosted
137 /// attempts.
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)138 #[serde(default)]
139 pub ttl_seconds: Option<u64>,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step140 /// Its scopes, as `resource:level`; unknown names are left out. Null:
141 /// full access.
142 #[serde(default)]
143 pub scopes: Option<Vec<String>>,
144 /// Listed with the person's tokens although it expires: one they made
145 /// themselves, with an expiry.
146 #[serde(default)]
147 pub listed: bool,
148}
149
150/// `update_access_token`: changes what one of a person's tokens may do.
151/// The token itself is unchanged. Returns `Outcome<AccessToken>`.
152#[derive(Debug, Serialize, Deserialize)]
153pub struct UpdateAccessTokenArgs {
154 pub user: User,
155 pub id: String,
156 /// Null: full access.
157 #[serde(default)]
158 pub scopes: Option<Vec<String>>,
API and MCP server, Rust identity service, registration, site redesign159}
160
161/// The plaintext token is returned once and never stored.
162#[derive(Debug, Serialize, Deserialize)]
163pub struct CreatedAccessToken {
164 pub token: String,
165 pub info: AccessToken,
166}
167
168/// `register`: creates an account and signs it in.
169/// Returns `Outcome<SignedIn>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look170///
171/// While registration is invite-only (`REGISTRATION_MODE=invite`), every
172/// new account needs `invite_code`: an unused, unexpired invite, and, when
173/// the invite names an email, that address. See [`CreateInviteArgs`].
API and MCP server, Rust identity service, registration, site redesign174#[derive(Debug, Serialize, Deserialize)]
175pub struct RegisterArgs {
176 pub username: String,
177 pub email: String,
178 pub password: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look179 /// An invite code such as `g1t-k7m2-q9xd-4hpw-…`. Ignored while
180 /// registration is open.
181 #[serde(default)]
182 pub invite_code: Option<String>,
183 /// Who is asking, such as the visitor's IP address, for rate limits.
184 #[serde(default)]
185 pub client: Option<String>,
API and MCP server, Rust identity service, registration, site redesign186}
Email verification, password reset, and Git for AI scale positioning187
188/// `verify_email`: the token from the emailed link. Returns `Outcome<User>`.
189#[derive(Debug, Serialize, Deserialize)]
190pub struct EmailTokenArgs {
191 pub token: String,
192}
193
194/// `request_password_reset`. Always succeeds, so it cannot be used to find
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look195/// out which addresses have accounts. Any confirmed address of an account
196/// works: the link goes to the address given, and the primary (and the
197/// backup) are told a reset was asked for. A few requests an hour per
198/// address and per `client`; past that, nothing is sent.
Email verification, password reset, and Git for AI scale positioning199#[derive(Debug, Serialize, Deserialize)]
200pub struct EmailArgs {
201 pub email: String,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look202 /// Who is asking, such as the visitor's IP address, for rate limits.
203 #[serde(default)]
204 pub client: Option<String>,
Email verification, password reset, and Git for AI scale positioning205}
206
207/// `reset_password`: sets a new password and ends every session.
208/// Returns `Outcome<User>`.
209#[derive(Debug, Serialize, Deserialize)]
210pub struct ResetPasswordArgs {
211 pub token: String,
212 pub password: String,
213}
Device sign-in replaces registering and minting tokens over the API214
215/// `device_start`: begins a device sign-in. Returns `DeviceStart`.
216#[derive(Debug, Serialize, Deserialize)]
217#[serde(rename_all = "camelCase")]
218pub struct DeviceStartArgs {
219 /// What is asking, shown to the person approving, e.g. "Claude Code".
220 pub client_name: String,
221}
222
223#[derive(Debug, Serialize, Deserialize)]
224#[serde(rename_all = "camelCase")]
225pub struct DeviceStart {
226 /// Secret held by the tool and exchanged for a token once approved.
227 pub device_code: String,
228 /// Short code shown to the person, e.g. `WDJB-MJHT`.
229 pub user_code: String,
230 /// Seconds until both codes stop working.
231 pub expires_in: u32,
232 /// Seconds the tool should wait between polls.
233 pub interval: u32,
234}
235
236/// `device_lookup`: what a user code is asking for, or null if it is not
237/// valid. Returns `Option<DeviceRequest>`.
238#[derive(Debug, Serialize, Deserialize)]
239#[serde(rename_all = "camelCase")]
240pub struct DeviceLookupArgs {
241 pub user_code: String,
242}
243
244#[derive(Debug, Serialize, Deserialize)]
245#[serde(rename_all = "camelCase")]
246pub struct DeviceRequest {
247 pub user_code: String,
248 pub client_name: String,
249}
250
251/// `device_resolve`: the signed-in person approves or denies a request.
252/// Returns `Outcome<bool>`.
253#[derive(Debug, Serialize, Deserialize)]
254#[serde(rename_all = "camelCase")]
255pub struct DeviceResolveArgs {
256 pub user_code: String,
257 pub user: User,
258 pub approve: bool,
259}
260
261/// `device_claim`: the tool asks whether its request was approved.
262#[derive(Debug, Serialize, Deserialize)]
263#[serde(rename_all = "camelCase")]
264pub struct DeviceClaimArgs {
265 pub device_code: String,
266}
267
268/// The answer to a `device_claim`.
269#[derive(Debug, Serialize, Deserialize)]
270#[serde(tag = "status", rename_all = "snake_case")]
271pub enum DeviceClaim {
272 /// Nobody has approved or denied it yet; ask again after the interval.
273 Pending,
274 Denied,
275 /// The code was never issued, has expired, or was already used.
276 Expired,
277 /// The access token, returned once.
278 Approved {
279 token: String,
280 user: User,
281 },
282}
Workspaces own repositories283
284/// A workspace: the owner of repositories, and the first segment of their
285/// URLs. A person's own space and a team's are the same thing.
286#[derive(Clone, Debug, Serialize, Deserialize)]
287#[serde(rename_all = "camelCase")]
288pub struct Workspace {
289 pub id: String,
290 pub slug: String,
291 pub name: String,
Agents as a team: lifecycle, merge queue, billing and a new shell292 /// One line saying what the workspace is for.
293 pub description: Option<String>,
Workspaces own repositories294 /// RFC 3339.
295 pub created_at: String,
296 pub member_count: u32,
Workspace names and icons, and a component kit for every control297 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
298 /// `/avatars/<avatar>`. Null means the generated letter avatar.
299 #[serde(default)]
300 pub avatar: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look301 /// What every member gets on each of its repositories; owners have
302 /// Admin. See [`crate::access`].
303 #[serde(default)]
304 pub base_permission: crate::access::BasePermission,
Workspaces own repositories305}
306
307#[derive(Clone, Debug, Serialize, Deserialize)]
308pub struct Member {
309 pub username: String,
310 pub role: crate::Role,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look311 /// Their display name, when they set one.
312 #[serde(default)]
313 pub name: Option<String>,
314 /// Their uploaded avatar: the SHA-256 of its bytes, served at
315 /// `/avatars/<avatar>`. None means the generated letter avatar.
316 #[serde(default)]
317 pub avatar: Option<String>,
Workspaces own repositories318}
319
Merge branch 'worktree-agent-a2013627e5ea4ab13'320/// Where a workspace keeps its repositories' git data: anywhere g1t
321/// stores it (the default), or in the EU only. It applies to repositories
322/// made after it is set; the repos service reads it when it places a new
323/// one (`storage_options` says whether the EU can be chosen).
324#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
325#[serde(rename_all = "lowercase")]
326pub enum DataResidency {
327 #[default]
328 Anywhere,
329 Eu,
330}
331
332impl DataResidency {
333 pub fn as_str(self) -> &'static str {
334 match self {
335 DataResidency::Anywhere => "anywhere",
336 DataResidency::Eu => "eu",
337 }
338 }
339
340 pub fn parse(text: &str) -> Option<Self> {
341 match text.trim().to_ascii_lowercase().as_str() {
342 "anywhere" => Some(DataResidency::Anywhere),
343 "eu" => Some(DataResidency::Eu),
344 _ => None,
345 }
346 }
347}
348
349/// `workspace_residency` takes [`SlugArgs`] and returns
350/// `Option<DataResidency>` (null when there is no such workspace).
351/// `set_workspace_residency`: owners only. Returns `Outcome<DataResidency>`.
352#[derive(Debug, Serialize, Deserialize)]
353pub struct SetResidencyArgs {
354 pub actor: User,
355 pub slug: String,
356 pub residency: DataResidency,
357}
358
Workspaces own repositories359/// `create_workspace`. Returns `Outcome<Workspace>`.
360#[derive(Debug, Serialize, Deserialize)]
361pub struct CreateWorkspaceArgs {
362 pub user: User,
363 pub slug: String,
364 #[serde(default)]
365 pub name: String,
366}
367
368/// `get_workspace`: public details, or null. Returns `Option<Workspace>`.
369#[derive(Debug, Serialize, Deserialize)]
370pub struct SlugArgs {
371 pub slug: String,
372}
373
374/// `list_members`: members only. Returns `Outcome<Vec<Member>>`.
375#[derive(Debug, Serialize, Deserialize)]
376pub struct ListMembersArgs {
377 pub slug: String,
378 pub viewer: crate::Viewer,
379}
380
381/// `add_member` and `remove_member`: owners only.
382/// Each returns `Outcome<bool>`.
383#[derive(Debug, Serialize, Deserialize)]
384pub struct MemberArgs {
385 pub actor: User,
386 pub slug: String,
387 pub username: String,
388}
OAuth 2.1 sign-in for MCP clients and other applications389
Agents as a team: lifecycle, merge queue, billing and a new shell390/// `update_workspace`: owners only. An empty name falls back to the slug;
391/// an empty description clears it. Returns `Outcome<Workspace>`.
392#[derive(Debug, Serialize, Deserialize)]
393pub struct UpdateWorkspaceArgs {
394 pub actor: User,
395 pub slug: String,
396 pub name: String,
397 pub description: String,
398}
399
Agents and memory, checks and conflicts, profiles, slug renames, custom domains400/// `rename_workspace`: owners only. Changes the workspace's slug, the first
401/// segment of its URLs, to `new_slug`; the display name is untouched. The
402/// old slug redirects to the new one, and is held for this workspace, for
403/// [`SLUG_HOLD_DAYS`]. Publishes `workspace.renamed`. Returns
404/// `Outcome<Workspace>`.
405///
406/// `check_workspace_rename` takes the same arguments and answers whether
407/// the rename would be allowed, changing nothing. Returns `Outcome<bool>`.
408#[derive(Debug, Serialize, Deserialize)]
409#[serde(rename_all = "camelCase")]
410pub struct RenameWorkspaceArgs {
411 pub actor: User,
412 pub slug: String,
413 pub new_slug: String,
414}
415
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look416/// `delete_workspace`: owners only, and only a person. `confirm` must be
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member417/// the workspace's slug, typed out. Refused for a protected workspace
418/// ([`protected_names`]), whoever asks, and while billing cannot settle it
419/// (`close_workspace`). Everything in it goes with it at once: nobody can
420/// reach it, its tokens stop working, its pages are not found, and its
421/// repositories, projects and apps are deleted with it. It is kept for
422/// [`WORKSPACE_RESTORE_DAYS`] so g1t's staff can restore it, then purged:
423/// its memberships, access tokens and old-slug redirects go, and billing's
424/// ledger and the audit log keep its history. The slug is never given to
425/// another workspace; the person whose username it is may make a workspace
426/// of that name again once it is purged. Publishes `workspace.deleting`,
427/// and `workspace.deleted` at the purge. Returns `Outcome<bool>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look428///
429/// `check_workspace_deletion` takes the same arguments (with `confirm`
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member430/// ignored) and says what would go and whether anything stands in the way,
431/// changing nothing. Returns `Outcome<WorkspaceDeletion>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look432#[derive(Debug, Serialize, Deserialize)]
433pub struct DeleteWorkspaceArgs {
434 pub actor: User,
435 pub slug: String,
436 #[serde(default)]
437 pub confirm: String,
438 /// Where the request came in, for the audit log; g1t.sh when absent.
439 #[serde(default)]
440 pub surface: Option<crate::audit::Surface>,
441}
442
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member443/// What deleting a workspace takes with it, and what stands in the way.
444/// Nothing does when `billing` is null and it is not `protected`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look445#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
446pub struct WorkspaceDeletion {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member447 /// Its live repositories, which are deleted with it.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look448 pub repositories: u32,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member449 /// Its projects, hidden with it.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look450 pub projects: u32,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member451 #[serde(default)]
452 pub members: u32,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look453 /// Why billing cannot close the workspace yet, in words for its owner.
454 pub billing: Option<String>,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member455 /// It can never be deleted, by anyone ([`protected_names`]).
456 #[serde(default)]
457 pub protected: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look458}
459
460impl WorkspaceDeletion {
461 pub fn blocked(&self) -> bool {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member462 self.protected || self.billing.is_some()
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look463 }
464
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member465 /// Why the workspace cannot be deleted, as one sentence, or `None`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look466 pub fn reason(&self, slug: &str) -> Option<String> {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member467 if self.protected {
468 return Some(protected_refusal(slug));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look469 }
470 self.billing.clone()
471 }
472}
473
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member474/// How long a deleted workspace is kept, for staff to restore, before it is
475/// purged.
476pub const WORKSPACE_RESTORE_DAYS: u64 = 30;
477
478/// Workspaces nobody can delete, whatever identity's `PROTECTED_WORKSPACES`
479/// says: Flagon's, which runs g1t.
480pub const ALWAYS_PROTECTED: &[&str] = &["flagon-io"];
481
482/// The protected workspaces: `configured` (comma-separated slugs or
483/// workspace ids, as identity's `PROTECTED_WORKSPACES` holds them), and
484/// [`ALWAYS_PROTECTED`] whatever it says, so an empty or missing variable
485/// still protects them. Lowercased, without duplicates.
486pub fn protected_names(configured: Option<&str>) -> Vec<String> {
487 let mut names: Vec<String> = Vec::new();
488 let given = configured.unwrap_or_default().split(',');
489 for name in ALWAYS_PROTECTED.iter().copied().chain(given) {
490 let name = name.trim().to_lowercase();
491 if !name.is_empty() && !names.contains(&name) {
492 names.push(name);
493 }
494 }
495 names
496}
497
498/// Why a protected workspace is not deleted, purged or acted on.
499pub fn protected_refusal(slug: &str) -> String {
500 format!("{slug} is protected and can never be deleted.")
501}
502
503/// `admin_deleted_workspaces` takes no arguments (`{}`) and returns
504/// `Vec<DeletedWorkspace>`, newest first. Staff only.
505///
506/// A workspace an owner deleted, kept until `purge_after` for staff to
507/// restore.
508#[derive(Clone, Debug, Serialize, Deserialize)]
509#[serde(rename_all = "camelCase")]
510pub struct DeletedWorkspace {
511 pub workspace_id: String,
512 pub slug: String,
513 pub name: String,
514 /// RFC 3339.
515 pub deleted_at: String,
516 /// The username of the owner who deleted it.
517 pub deleted_by: String,
518 /// RFC 3339: when it is purged unless restored first.
519 pub purge_after: String,
520 /// What went with it, counted when it was deleted.
521 pub went: WorkspaceDeletion,
522 /// Whether staff can still restore it.
523 pub restorable: bool,
524}
525
526/// `admin_restore_workspace` and `admin_purge_workspace`: staff restore a
527/// deleted workspace within [`WORKSPACE_RESTORE_DAYS`], or purge it now.
528/// `staff` is who, for the audit logs. Purging needs `confirm`, the slug
529/// typed out, and is refused for a protected workspace. Restoring publishes
530/// `workspace.restored`; purging, `workspace.deleted`. Both return
531/// `Outcome<bool>`.
532#[derive(Debug, Serialize, Deserialize)]
533#[serde(rename_all = "camelCase")]
534pub struct AdminDeletedWorkspaceArgs {
535 pub workspace_id: String,
536 pub staff: String,
537 #[serde(default)]
538 pub confirm: String,
539}
540
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look541/// `transfer_repo_scopes`: a repository moved from `from` to `to`; the
542/// tokens of agents at work on it are kept pointing at it. For repos'
543/// `transfer`. Returns `bool`.
544#[derive(Debug, Serialize, Deserialize)]
545pub struct TransferRepoScopesArgs {
546 pub from: crate::repos::RepoPath,
547 pub to: crate::repos::RepoPath,
548}
549
Agents and memory, checks and conflicts, profiles, slug renames, custom domains550/// How long a workspace's old slug keeps redirecting to it, and stays
551/// reserved for it, after a rename.
552pub const SLUG_HOLD_DAYS: u64 = 90;
553
554/// How long a workspace must wait between renames.
555pub const RENAME_COOLDOWN_HOURS: u64 = 24;
556
557// `resolve_slug` takes `SlugArgs` and returns `Option<String>`: the
558// workspace's current slug when `slug` is one it was renamed from within
559// the last `SLUG_HOLD_DAYS`, and null otherwise (including for a slug that
560// is in use).
561
Workspace names and icons, and a component kit for every control562/// `set_workspace_avatar`: owners only. `image` is the file's bytes in
563/// base64: PNG, JPEG, WebP or GIF, at most `MAX_AVATAR_BYTES`. Null removes
564/// the icon. Returns `Outcome<Workspace>`.
565#[derive(Debug, Serialize, Deserialize)]
566pub struct SetWorkspaceAvatarArgs {
567 pub actor: User,
568 pub slug: String,
569 pub image: Option<String>,
570}
571
572/// `set_user_avatar`: a person's own avatar, as `SetWorkspaceAvatarArgs`.
573/// Returns `Outcome<Option<String>>`: the new avatar, or null once removed.
574#[derive(Debug, Serialize, Deserialize)]
575pub struct SetUserAvatarArgs {
576 pub user: User,
577 pub image: Option<String>,
578}
579
580/// The largest avatar that can be uploaded, in bytes.
581pub const MAX_AVATAR_BYTES: usize = 1024 * 1024;
582
Agents as a team: lifecycle, merge queue, billing and a new shell583/// `list_workspace_tokens`: members only. Returns
584/// `Outcome<Vec<AccessToken>>`.
585#[derive(Debug, Serialize, Deserialize)]
586pub struct WorkspaceTokensArgs {
587 pub slug: String,
588 pub viewer: crate::Viewer,
589}
590
591/// `create_workspace_token`: owners only. The token belongs to the
592/// workspace, acts as it, and keeps working when the member who made it
593/// leaves. Returns `Outcome<CreatedAccessToken>`.
594#[derive(Debug, Serialize, Deserialize)]
595pub struct CreateWorkspaceTokenArgs {
596 pub actor: User,
597 pub slug: String,
598 pub name: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step599 /// Its scopes; null for full access.
600 #[serde(default)]
601 pub scopes: Option<Vec<String>>,
602 /// When set, the token stops working after this many seconds. It is
603 /// listed with the workspace's tokens either way. Null: no expiry.
604 #[serde(default)]
605 pub ttl_seconds: Option<u64>,
Agents as a team: lifecycle, merge queue, billing and a new shell606}
607
608/// `remove_workspace_token`: owners only. Returns `Outcome<bool>`.
609#[derive(Debug, Serialize, Deserialize)]
610pub struct RemoveWorkspaceTokenArgs {
611 pub actor: User,
612 pub slug: String,
613 pub id: String,
614}
615
OAuth 2.1 sign-in for MCP clients and other applications616/// `oauth_authorize`: the signed-in person approved an application. The
617/// caller has checked the client and that it may be redirected to
618/// `redirect_uri`. Returns `OAuthCode`.
619#[derive(Debug, Serialize, Deserialize)]
620#[serde(rename_all = "camelCase")]
621pub struct OAuthAuthorizeArgs {
622 pub user: User,
623 pub client_id: String,
624 /// Shown wherever the application's access is listed.
625 pub client_name: String,
626 pub redirect_uri: String,
627 /// PKCE challenge, method S256.
628 pub code_challenge: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step629 /// What the person granted, as `resource:level`. Null: full access.
630 #[serde(default)]
631 pub scopes: Option<Vec<String>>,
OAuth 2.1 sign-in for MCP clients and other applications632}
633
634#[derive(Debug, Serialize, Deserialize)]
635pub struct OAuthCode {
636 pub code: String,
637}
638
639/// `oauth_exchange`: redeems an authorization code.
640/// Returns `Outcome<OAuthTokens>`.
641#[derive(Debug, Serialize, Deserialize)]
642#[serde(rename_all = "camelCase")]
643pub struct OAuthExchangeArgs {
644 pub code: String,
645 pub code_verifier: String,
646 pub client_id: String,
647 pub redirect_uri: String,
648}
649
650/// `oauth_refresh`: trades a refresh token for new tokens.
651/// Returns `Outcome<OAuthTokens>`.
652#[derive(Debug, Serialize, Deserialize)]
653#[serde(rename_all = "camelCase")]
654pub struct OAuthRefreshArgs {
655 pub refresh_token: String,
656 pub client_id: String,
657}
658
659#[derive(Debug, Serialize, Deserialize)]
660#[serde(rename_all = "camelCase")]
661pub struct OAuthTokens {
662 pub access_token: String,
663 /// Works once; using it returns the next one.
664 pub refresh_token: String,
665 /// Seconds until the access token stops working.
666 pub expires_in: u64,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step667 /// The scopes granted, space-separated, or `*` for full access.
668 #[serde(default)]
669 pub scope: Option<String>,
OAuth 2.1 sign-in for MCP clients and other applications670}
671
672/// An application a person has signed in to. Listed by `list_oauth_grants`
673/// and ended by `revoke_oauth_grant`.
674#[derive(Debug, Serialize, Deserialize)]
675#[serde(rename_all = "camelCase")]
676pub struct OAuthGrant {
677 pub id: String,
678 pub client_name: String,
679 /// RFC 3339.
680 pub created_at: String,
681 /// RFC 3339.
682 pub last_used_at: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step683 /// What the person granted. Null: full access.
684 #[serde(default)]
685 pub scopes: Option<Vec<String>>,
686 /// Signed in before applications were given scopes: full access until
687 /// someone narrows it.
688 #[serde(default)]
689 pub legacy: bool,
690}
691
692/// `update_oauth_grant`: changes what an application the person signed in
693/// to may do, at once and when it refreshes. Returns `Outcome<OAuthGrant>`.
694#[derive(Debug, Serialize, Deserialize)]
695pub struct UpdateOAuthGrantArgs {
696 pub user: User,
697 pub id: String,
698 #[serde(default)]
699 pub scopes: Option<Vec<String>>,
OAuth 2.1 sign-in for MCP clients and other applications700}
Agents as a team: lifecycle, merge queue, billing and a new shell701
702
703/// What an agent's token may do: these operations, in this repository.
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API704#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Agents as a team: lifecycle, merge queue, billing and a new shell705pub struct AgentScope {
706 pub repo: crate::repos::RepoPath,
707 /// API and MCP operation names, such as `create_issue`.
708 pub operations: Vec<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API709 /// Set on a run credential: the run it belongs to, and what it may do
710 /// with git. See [`crate::credentials`].
711 #[serde(default, skip_serializing_if = "Option::is_none")]
712 pub run: Option<crate::credentials::RunBinding>,
Agents as a team: lifecycle, merge queue, billing and a new shell713}
714
715/// `create_agent_token`: a token for a g1t agent working on someone's
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent716/// behalf. It acts as `g1t`, a member of the repository's workspace,
Agents as a team: lifecycle, merge queue, billing and a new shell717/// and only for the operations in `scope`. Returns `CreatedAccessToken`.
718#[derive(Debug, Serialize, Deserialize)]
719#[serde(rename_all = "camelCase")]
720pub struct CreateAgentTokenArgs {
721 /// The person the agent works for; the token is recorded as theirs.
722 pub on_behalf_of: User,
723 pub scope: AgentScope,
724 pub ttl_seconds: u64,
725}
726
727// `agent_scope` takes `TokenArgs` and returns `Option<AgentScope>`: what an
728// agent's token may do, or null for any other token.
729
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent730/// The id g1t's agent acts under. Only ever stored, never shown: it keeps
731/// the agent's work apart from g1t's own ([`crate::system::ID`]) where
732/// that matters, such as whether its approval counts.
Agents as a team: lifecycle, merge queue, billing and a new shell733pub const AGENT_ID: &str = "usr_g1t_agent";
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent734/// The name g1t's agent is shown by: g1t's own, [`crate::system::USERNAME`].
735/// Everything it does, people see g1t do.
736pub const AGENT_NAME: &str = crate::system::USERNAME;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace737
738// --- Staff ---------------------------------------------------------------
739//
740// Staff-only methods, for sudo.g1t.sh. They take no viewer and check no
741// membership: only sudo calls them, over its service binding, after it has
742// verified a Cloudflare Access sign-in and its staff list. Nothing a
743// customer can reach should ever forward to them.
744
745/// `notify_owners`: emails a short notice, with one link, to each owner of
746/// a workspace with a confirmed address. Called by other services (billing
747/// warns owners near their usage limit), never on a person's behalf.
748/// Returns how many were sent.
749#[derive(Clone, Debug, Serialize, Deserialize)]
750pub struct NotifyOwnersArgs {
751 pub workspace: String,
752 pub subject: String,
753 /// One or two sentences: what happened and what it means.
754 pub intro: String,
755 /// The button's words, such as `Open billing`.
756 pub action: String,
757 /// Where the button goes; must be on g1t.sh.
758 pub link: String,
759 /// Small print: why they got it.
760 pub footer: String,
761}
762
763/// `admin_workspaces`: every workspace, newest first, at most
764/// [`ADMIN_WORKSPACES_LIMIT`], optionally only those whose slug, name or
765/// an owner's username or email contains `query`. Returns
766/// `Vec<AdminWorkspace>`. Staff only.
767#[derive(Debug, Default, Serialize, Deserialize)]
768pub struct AdminWorkspacesArgs {
769 #[serde(default)]
770 pub query: Option<String>,
771}
772
773/// The most workspaces one `admin_workspaces` call returns.
774pub const ADMIN_WORKSPACES_LIMIT: usize = 500;
775
776/// An owner of a workspace, as staff see them.
777#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
778pub struct AdminOwner {
779 pub username: String,
780 pub email: Option<String>,
781}
782
783/// A workspace as staff see it: who owns it and how many belong to it.
784#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
785#[serde(rename_all = "camelCase")]
786pub struct AdminWorkspace {
787 pub slug: String,
788 pub name: String,
789 /// RFC 3339.
790 pub created_at: String,
791 pub owners: Vec<AdminOwner>,
792 pub member_count: u32,
793}
794
795/// `admin_workspace`: one workspace with every member, or null. Takes
796/// `SlugArgs`; returns `Option<AdminWorkspaceDetail>`. Staff only.
797#[derive(Clone, Debug, Serialize, Deserialize)]
798#[serde(rename_all = "camelCase")]
799pub struct AdminWorkspaceDetail {
800 pub slug: String,
801 pub name: String,
802 pub description: Option<String>,
803 /// RFC 3339.
804 pub created_at: String,
805 /// Owners first, then by username.
806 pub members: Vec<AdminMember>,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member807 /// It can never be deleted ([`protected_names`]).
808 #[serde(default)]
809 pub protected: bool,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace810}
811
812/// A member of a workspace, as staff see them.
813#[derive(Clone, Debug, Serialize, Deserialize)]
814pub struct AdminMember {
815 pub username: String,
816 pub email: Option<String>,
817 pub role: crate::Role,
818 /// When they joined the workspace. RFC 3339.
819 pub joined: String,
820}
Agents and memory, checks and conflicts, profiles, slug renames, custom domains821
822// --- Profiles ------------------------------------------------------------
823//
824// A person's public page at `g1t.sh/u/<username>`. Everything in a
825// `Profile` is shown to anyone, signed in or not; an email address never is.
826
827/// The most characters each profile field takes.
828pub const MAX_PROFILE_NAME: usize = 80;
829pub const MAX_PROFILE_BIO: usize = 160;
830pub const MAX_PROFILE_LOCATION: usize = 80;
831pub const MAX_PROFILE_WEBSITE: usize = 200;
832pub const MAX_PROFILE_PRONOUNS: usize = 40;
833
834/// What anyone may see about a person.
835#[derive(Clone, Debug, Default, Serialize, Deserialize)]
836#[serde(rename_all = "camelCase")]
837pub struct Profile {
838 pub username: String,
839 /// The name they go by, if they gave one.
840 pub name: Option<String>,
841 /// One or two lines about them, at most [`MAX_PROFILE_BIO`] characters.
842 pub bio: Option<String>,
843 pub location: Option<String>,
844 /// An `https://` address.
845 pub website: Option<String>,
846 pub pronouns: Option<String>,
847 /// The uploaded avatar's hash, served at `/avatars/<avatar>`.
848 pub avatar: Option<String>,
849 /// When the account was made. RFC 3339.
850 pub created_at: String,
851}
852
853// `profile` takes `UsernameArgs` and returns `Option<Profile>`: null for
854// an account that does not exist.
855
856/// `update_profile`: a person changes their own profile. Every field is
857/// replaced; an empty one is cleared. Returns `Outcome<Profile>`.
858#[derive(Debug, Default, Serialize, Deserialize)]
859#[serde(rename_all = "camelCase")]
860pub struct UpdateProfileArgs {
861 pub actor: User,
862 #[serde(default)]
863 pub name: String,
864 #[serde(default)]
865 pub bio: String,
866 #[serde(default)]
867 pub location: String,
868 #[serde(default)]
869 pub website: String,
870 #[serde(default)]
871 pub pronouns: String,
872}
873
874/// `profile_workspaces`: the workspaces shown on a person's profile, as
875/// `viewer` may see them. A membership is shown only when it is no secret
876/// from the viewer: a workspace the viewer belongs to as well, or one of
877/// `public`, the workspaces the caller found the person has made a public
878/// project in (whose page shows that already). Returns
879/// `Vec<ProfileWorkspace>`; empty for an account that does not exist.
880#[derive(Debug, Serialize, Deserialize)]
881pub struct ProfileWorkspacesArgs {
882 pub username: String,
883 pub viewer: crate::Viewer,
884 #[serde(default)]
885 pub public: Vec<String>,
886}
887
888/// A workspace on a person's profile.
889#[derive(Clone, Debug, Serialize, Deserialize)]
890pub struct ProfileWorkspace {
891 pub slug: String,
892 pub name: String,
893 pub avatar: Option<String>,
894}
Search across all of g1t, Explore, and a command palette895
896/// `directory`: every account or every workspace, as their public pages
897/// show them, a page at a time in name order. For services that index
898/// them, such as search; nothing private is in it. Returns
899/// `DirectoryPage`.
900#[derive(Debug, Default, Serialize, Deserialize)]
901pub struct DirectoryArgs {
902 /// `user` or `workspace`.
903 pub kind: String,
904 /// Names after this one.
905 #[serde(default)]
906 pub after: Option<String>,
907 pub limit: u32,
908}
909
910/// One account or workspace in the directory.
911#[derive(Clone, Debug, Serialize, Deserialize)]
912#[serde(rename_all = "camelCase")]
913pub struct DirectoryEntry {
914 /// The account's or workspace's id.
915 pub id: String,
916 /// A username or a workspace's slug.
917 pub slug: String,
918 /// A person's display name or a workspace's name.
919 pub name: Option<String>,
920 /// A person's bio or a workspace's description.
921 pub bio: Option<String>,
922 pub avatar: Option<String>,
923 /// RFC 3339.
924 pub created_at: String,
925}
926
927#[derive(Clone, Debug, Default, Serialize, Deserialize)]
928pub struct DirectoryPage {
929 pub entries: Vec<DirectoryEntry>,
930 /// Where the next page starts; null on the last.
931 pub next: Option<String>,
932}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look933
934// --- Invites ---------------------------------------------------------------
935//
936// While registration is invite-only, every new account (with a password or
937// through GitHub) needs an invite code. Each person may have
938// `INVITES_PER_USER` invites out at a time; staff grant more to a person or
939// to a workspace, whose owners share them. Inviting an email with no
940// account into a workspace makes an invite bound to that address, which
941// registers and joins in one step. See services/identity/src/invites.rs.
942
943/// Whether anyone may make an account, or only someone with an invite. Set
944/// by identity's `REGISTRATION_MODE` var; anything but `open`, including
945/// leaving it unset, is `invite`, so a missing setting never opens sign-up.
946#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
947#[serde(rename_all = "snake_case")]
948pub enum RegistrationMode {
949 #[default]
950 Invite,
951 Open,
952}
953
954impl RegistrationMode {
955 pub fn parse(text: Option<&str>) -> RegistrationMode {
956 match text.map(|text| text.trim().to_ascii_lowercase()).as_deref() {
957 Some("open") => RegistrationMode::Open,
958 _ => RegistrationMode::Invite,
959 }
960 }
961}
962
963/// How many invites a person may have out at once, unless identity's
964/// `INVITES_PER_USER` var says otherwise.
965pub const INVITES_PER_USER: u32 = 5;
966
967/// How long an invite works, unless identity's `INVITE_TTL_DAYS` var says
968/// otherwise.
969pub const INVITE_TTL_DAYS: u64 = 30;
970
971/// Where an invite stands. Only a pending invite can be used or revoked.
972/// An expired or revoked invite that was never used gives its inviter the
973/// invite back.
974#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
975#[serde(rename_all = "snake_case")]
976pub enum InviteStatus {
977 Pending,
978 Redeemed,
979 Expired,
980 Revoked,
981}
982
983/// What using an invite does.
984#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
985#[serde(rename_all = "snake_case")]
986pub enum InviteKind {
987 /// Makes a new account, and joins `workspace` when one is set.
988 Account,
989 /// An existing account joins `workspace`. Never makes an account.
990 Workspace,
991}
992
993/// Whose allowance an invite uses.
994#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
995#[serde(rename_all = "snake_case")]
996pub enum InviteCharge {
997 /// Its inviter's own.
998 User,
999 /// The workspace's, granted by staff and shared by its owners.
1000 Workspace,
1001 /// Nobody's: staff minted it, or it invites an existing account.
1002 None,
1003}
1004
1005/// One invite, as the person who made it sees it.
1006#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1007#[serde(rename_all = "camelCase")]
1008pub struct Invite {
1009 pub id: String,
1010 /// The code, such as `g1t-k7m2-q9xd-…`: returned once when the invite
1011 /// is made, and afterwards to whoever made it while it is pending.
1012 /// Null otherwise.
1013 pub code: Option<String>,
1014 /// The code's first group, such as `g1t-k7m2`, to recognise it by.
1015 pub hint: String,
1016 /// Only an account with this address can use it. Null: anyone with
1017 /// the code.
1018 pub email: Option<String>,
1019 pub kind: InviteKind,
1020 /// The workspace it joins, by slug.
1021 pub workspace: Option<String>,
1022 pub status: InviteStatus,
1023 pub charged_to: InviteCharge,
1024 /// Who made it, by username. Null when g1t staff did.
1025 pub invited_by: Option<String>,
1026 /// The account that used it, by username.
1027 pub redeemed_by: Option<String>,
1028 /// RFC 3339.
1029 pub created_at: String,
1030 /// RFC 3339.
1031 pub expires_at: String,
1032 /// RFC 3339.
1033 pub redeemed_at: Option<String>,
1034 /// RFC 3339.
1035 pub revoked_at: Option<String>,
1036 /// The staff member who minted it. Only in staff views.
1037 #[serde(default, skip_serializing_if = "Option::is_none")]
1038 pub staff: Option<String>,
1039}
1040
1041/// How many invites someone may have out, and how many they have.
1042#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1043pub struct Allowance {
1044 /// Null: no limit.
1045 pub limit: Option<u32>,
1046 /// Pending and used invites; revoked and expired ones are not counted.
1047 pub used: u32,
1048 /// Null: no limit.
1049 pub remaining: Option<u32>,
1050}
1051
1052impl Allowance {
1053 pub fn new(limit: Option<u32>, used: u32) -> Allowance {
1054 Allowance {
1055 limit,
1056 used,
1057 remaining: limit.map(|limit| limit.saturating_sub(used)),
1058 }
1059 }
1060
1061 pub fn exhausted(&self) -> bool {
1062 self.remaining == Some(0)
1063 }
1064}
1065
1066/// A workspace's shared invites, for one of its owners.
1067#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1068pub struct WorkspaceAllowance {
1069 pub slug: String,
1070 pub allowance: Allowance,
1071}
1072
1073/// `list_invites` (takes `UserArgs`): a person's invites, newest first,
1074/// and what they have left. Returns `InvitesOverview`.
1075#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1076pub struct InvitesOverview {
1077 pub mode: RegistrationMode,
1078 pub allowance: Allowance,
1079 /// Workspaces the person owns that staff granted invites to.
1080 pub workspaces: Vec<WorkspaceAllowance>,
1081 pub invites: Vec<Invite>,
1082}
1083
1084/// `create_invite`: a person makes an invite, optionally for one email
1085/// address. People only; never an agent or a workspace's token, and not
1086/// before their email is confirmed. Uses one of the person's invites, or,
1087/// with `workspace`, one of the invites staff granted that workspace (its
1088/// owners only). Emails the address when one is given. Returns
1089/// `Outcome<Invite>`, with the code.
1090///
1091/// `revoke_invite` (takes `RemoveArgs`): its maker revokes a pending
1092/// invite; a workspace's owners may revoke one made for the workspace.
1093/// The invite comes back to whoever it was charged to. Returns
1094/// `Outcome<Invite>`.
1095#[derive(Debug, Serialize, Deserialize)]
1096pub struct CreateInviteArgs {
1097 pub user: User,
1098 #[serde(default)]
1099 pub email: Option<String>,
1100 /// Use this workspace's granted invites, by slug.
1101 #[serde(default)]
1102 pub workspace: Option<String>,
1103 /// Where the request came in, for the audit log; g1t.sh when absent.
1104 #[serde(default)]
1105 pub surface: Option<crate::audit::Surface>,
1106}
1107
1108/// `check_invite`: what an invite code is for, before using it. Returns
1109/// `Outcome<InvitePreview>`; a code that is unknown, used, revoked or
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1110/// expired gets the same answer, so codes cannot be probed. With
1111/// `any_status`, a real code that can no longer be used is described
1112/// instead (its `status` says why), so the page can say whom to ask for a
1113/// new one; an unknown code still gets the one answer.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1114#[derive(Debug, Serialize, Deserialize)]
1115pub struct InviteCodeArgs {
1116 pub code: String,
1117 /// Who is asking, such as the visitor's IP address, for rate limits.
1118 #[serde(default)]
1119 pub client: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1120 /// Who is looking, if signed in: sets `InvitePreview::for_viewer`.
1121 #[serde(default)]
1122 pub viewer: Option<User>,
1123 #[serde(default)]
1124 pub any_status: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1125}
1126
1127/// Someone shown on an invite.
1128#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1129pub struct InviteFrom {
1130 pub username: String,
1131 pub name: Option<String>,
1132 pub avatar: Option<String>,
1133}
1134
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1135/// A repository an invite code was sent with: using the code accepts the
1136/// invitation to collaborate on it.
1137#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1138pub struct InviteRepository {
1139 /// `workspace/repo`.
1140 pub name: String,
1141 /// The role it gives, such as `write`.
1142 pub role: String,
1143}
1144
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1145/// What a valid invite code is for.
1146#[derive(Clone, Debug, Serialize, Deserialize)]
1147#[serde(rename_all = "camelCase")]
1148pub struct InvitePreview {
1149 pub kind: InviteKind,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1150 /// Pending, unless `any_status` asked about a code that is spent.
1151 pub status: InviteStatus,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1152 /// Null when g1t staff sent it.
1153 pub invited_by: Option<InviteFrom>,
1154 pub workspace: Option<ProfileWorkspace>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1155 /// The repository it accepts an invitation to, if it was sent with one.
1156 pub repository: Option<InviteRepository>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1157 /// The address it is for, partly hidden, such as `a•••@example.com`.
1158 pub email: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1159 /// The address in full, while it is pending: whoever holds the code
1160 /// was sent it there. Fills in and locks the sign-up form.
1161 pub address: Option<String>,
1162 /// Whether the address it is for has a g1t account already, so the
1163 /// page asks them to sign in rather than sign up.
1164 pub has_account: bool,
1165 /// With a viewer: whether the invite is theirs (it is for one of their
1166 /// confirmed addresses, or they used it). Null without a viewer or,
1167 /// for a pending invite, when it is for anyone with the code.
1168 pub for_viewer: Option<bool>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1169 /// RFC 3339.
1170 pub expires_at: String,
1171}
1172
1173/// `accept_invite`: a signed-in person uses a workspace invite made for
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1174/// their confirmed address, and joins the workspace, or an invite sent with
1175/// a repository invitation, and accepts it. Returns `Outcome<String>`: the
1176/// workspace's slug, or `workspace/repo`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1177#[derive(Debug, Serialize, Deserialize)]
1178pub struct AcceptInviteArgs {
1179 pub user: User,
1180 pub code: String,
1181}
1182
1183/// `invite_member`: an owner invites an email address into a workspace.
1184/// It always makes an invite bound to that address and emails it, so the
1185/// answer never says whether the address has an account. Without one, the
1186/// invite registers and joins in one step, and uses one of the workspace's
1187/// granted invites or else one of the owner's own. With one, it costs
1188/// nothing. Returns `Outcome<Invite>`, with the code.
1189#[derive(Debug, Serialize, Deserialize)]
1190pub struct InviteMemberArgs {
1191 pub actor: User,
1192 pub slug: String,
1193 pub email: String,
1194 /// Where the request came in, for the audit log; g1t.sh when absent.
1195 #[serde(default)]
1196 pub surface: Option<crate::audit::Surface>,
1197}
1198
1199/// `workspace_invites` (takes `ListMembersArgs`): a workspace's invites,
1200/// newest first. Owners only. Returns `Outcome<Vec<Invite>>`.
1201///
1202/// `revoke_workspace_invite`: owners only. Returns `Outcome<Invite>`.
1203#[derive(Debug, Serialize, Deserialize)]
1204pub struct WorkspaceInviteArgs {
1205 pub actor: User,
1206 pub slug: String,
1207 pub id: String,
1208}
1209
1210/// `request_access`: someone without an invite asks for one. Kept on the
1211/// waitlist, one entry per address. Answers the same way whether or not
1212/// the address is already on it. Returns `Outcome<bool>`.
1213#[derive(Debug, Default, Serialize, Deserialize)]
1214pub struct RequestAccessArgs {
1215 pub email: String,
1216 /// What they will build, if they said.
1217 #[serde(default)]
1218 pub about: String,
1219 /// Who is asking, such as the visitor's IP address, for rate limits.
1220 #[serde(default)]
1221 pub client: Option<String>,
1222}
1223
1224/// The most characters `RequestAccessArgs::about` keeps.
1225pub const MAX_WAITLIST_ABOUT: usize = 1000;
1226
1227// `registration` takes `{}` and returns `RegistrationMode`.
1228
1229// --- Invites, staff only ---
1230
1231#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1232#[serde(rename_all = "snake_case")]
1233pub enum WaitlistStatus {
1234 Waiting,
1235 Invited,
1236 Dismissed,
1237}
1238
1239impl WaitlistStatus {
1240 pub fn as_str(self) -> &'static str {
1241 match self {
1242 WaitlistStatus::Waiting => "waiting",
1243 WaitlistStatus::Invited => "invited",
1244 WaitlistStatus::Dismissed => "dismissed",
1245 }
1246 }
1247}
1248
1249/// Someone who asked for access.
1250#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1251#[serde(rename_all = "camelCase")]
1252pub struct WaitlistEntry {
1253 pub id: String,
1254 pub email: String,
1255 pub about: Option<String>,
1256 pub status: WaitlistStatus,
1257 pub invite_id: Option<String>,
1258 pub decided_by: Option<String>,
1259 /// RFC 3339.
1260 pub decided_at: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1261 /// What staff wrote when approving; it went in the invite email.
1262 #[serde(default)]
1263 pub note: Option<String>,
1264 /// The account made with the invite, once it was used.
1265 #[serde(default)]
1266 pub joined_as: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1267 /// When they first asked. RFC 3339.
1268 pub created_at: String,
1269 /// When they last asked. RFC 3339.
1270 pub updated_at: String,
1271}
1272
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1273/// `admin_waitlist`: the waitlist, newest first, at most
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1274/// [`ADMIN_INVITES_LIMIT`]. Returns `Vec<WaitlistEntry>`.
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1275///
1276/// `admin_waitlist_pending` takes `{}` and returns the number of requests
1277/// still waiting, for sudo's navigation.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1278#[derive(Debug, Default, Serialize, Deserialize)]
1279pub struct AdminWaitlistArgs {
1280 /// Part of an email address or of what they said.
1281 #[serde(default)]
1282 pub query: Option<String>,
1283 /// Null: every status.
1284 #[serde(default)]
1285 pub status: Option<WaitlistStatus>,
1286}
1287
1288/// The most rows one staff listing of invites or the waitlist returns.
1289pub const ADMIN_INVITES_LIMIT: usize = 500;
1290
1291/// `admin_decide_waitlist`: approving mints an invite bound to the
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1292/// address, charged to nobody, and emails it, with `note` if given;
1293/// dismissing only marks the entry. Returns `Outcome<WaitlistEntry>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1294#[derive(Debug, Serialize, Deserialize)]
1295pub struct AdminDecideWaitlistArgs {
1296 pub id: String,
1297 pub approve: bool,
1298 /// The staff member, by email.
1299 pub staff: String,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1300 /// A line for the invite email, up to [`MAX_WAITLIST_NOTE`] characters.
1301 #[serde(default)]
1302 pub note: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1303}
1304
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1305/// The most characters an approval's note keeps.
1306pub const MAX_WAITLIST_NOTE: usize = 500;
1307
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1308/// `admin_invites`: every invite, newest first, at most
1309/// [`ADMIN_INVITES_LIMIT`], optionally only those whose code starts with
1310/// `query`, or whose email, inviter or redeemer contains it. Returns
1311/// `Vec<Invite>`.
1312#[derive(Debug, Default, Serialize, Deserialize)]
1313pub struct AdminInvitesArgs {
1314 #[serde(default)]
1315 pub query: Option<String>,
1316}
1317
1318/// `admin_revoke_invite`: revokes any pending invite. Returns
1319/// `Outcome<Invite>`.
1320#[derive(Debug, Serialize, Deserialize)]
1321pub struct AdminRevokeInviteArgs {
1322 pub id: String,
1323 pub staff: String,
1324}
1325
1326/// `admin_mint_invite`: staff make an invite that uses nobody's
1327/// allowance, optionally bound to (and emailed to) an address. Returns
1328/// `Outcome<Invite>`, with the code.
1329#[derive(Debug, Serialize, Deserialize)]
1330pub struct AdminMintInviteArgs {
1331 #[serde(default)]
1332 pub email: Option<String>,
1333 pub staff: String,
1334}
1335
1336/// Who staff grant invites to.
1337#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1338#[serde(rename_all = "snake_case")]
1339pub enum GrantTarget {
1340 User,
1341 Workspace,
1342}
1343
1344impl GrantTarget {
1345 pub fn as_str(self) -> &'static str {
1346 match self {
1347 GrantTarget::User => "user",
1348 GrantTarget::Workspace => "workspace",
1349 }
1350 }
1351}
1352
1353/// `admin_grant_invites`: gives a person (by username) or a workspace (by
1354/// slug) `amount` more invites; a negative amount takes some back. Returns
1355/// `Outcome<Allowance>`: theirs afterwards.
1356#[derive(Debug, Serialize, Deserialize)]
1357pub struct AdminGrantInvitesArgs {
1358 pub target: GrantTarget,
1359 pub name: String,
1360 pub amount: i32,
1361 #[serde(default)]
1362 pub note: String,
1363 pub staff: String,
1364}
1365
1366/// The most invites one grant gives or takes back.
1367pub const MAX_INVITE_GRANT: i32 = 1000;
1368
1369/// Invites staff granted.
1370#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1371#[serde(rename_all = "camelCase")]
1372pub struct InviteGrant {
1373 pub amount: i32,
1374 pub note: Option<String>,
1375 pub granted_by: String,
1376 /// RFC 3339.
1377 pub created_at: String,
1378}
1379
1380/// Someone a person invited, and whom they invited in turn.
1381#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1382#[serde(rename_all = "camelCase")]
1383pub struct InviteTreeNode {
1384 pub username: String,
1385 /// When they used the invite. RFC 3339.
1386 pub joined_at: String,
1387 pub invited: Vec<InviteTreeNode>,
1388}
1389
1390/// `admin_invite_tree` (takes `UsernameArgs`): where a person came from
1391/// and whom they brought, for tracing abuse. Returns `Option<InviteTree>`.
1392///
1393/// `admin_workspace_invites` (takes `SlugArgs`): a workspace's granted
1394/// invites, grants and invites. Returns `Option<InviteTree>` with
1395/// `username` the slug and no `invited_by`.
1396#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1397#[serde(rename_all = "camelCase")]
1398pub struct InviteTree {
1399 pub username: String,
1400 /// Who invited them, then who invited that person, and so on. Empty
1401 /// for an account made without an invite.
1402 pub invited_by: Vec<String>,
1403 /// The staff member who minted their invite, when staff did.
1404 pub staff: Option<String>,
1405 pub allowance: Allowance,
1406 pub grants: Vec<InviteGrant>,
1407 /// Their invites, newest first.
1408 pub invites: Vec<Invite>,
1409 /// Whom they invited, three levels down.
1410 pub invited: Vec<InviteTreeNode>,
1411}
1412
1413#[cfg(test)]
1414mod deletion_tests {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1415 use super::{WorkspaceDeletion, protected_names};
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1416
1417 #[test]
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1418 fn only_billing_or_protection_stands_in_the_way() {
1419 let clear = WorkspaceDeletion {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1420 repositories: 2,
1421 projects: 1,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1422 members: 3,
1423 ..WorkspaceDeletion::default()
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1424 };
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1425 assert!(!clear.blocked());
1426 assert_eq!(clear.reason("acme"), None);
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1427 let owing = WorkspaceDeletion {
1428 billing: Some("Pay first.".into()),
1429 ..WorkspaceDeletion::default()
1430 };
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1431 assert!(owing.blocked());
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1432 assert_eq!(owing.reason("acme").as_deref(), Some("Pay first."));
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1433 let protected = WorkspaceDeletion {
1434 billing: Some("Pay first.".into()),
1435 protected: true,
1436 ..WorkspaceDeletion::default()
1437 };
1438 assert!(protected.blocked());
1439 assert_eq!(
1440 protected.reason("flagon-io").as_deref(),
1441 Some("flagon-io is protected and can never be deleted.")
1442 );
1443 }
1444
1445 #[test]
1446 fn flagon_is_protected_whatever_the_variable_says() {
1447 assert_eq!(protected_names(None), ["flagon-io"]);
1448 assert_eq!(protected_names(Some("")), ["flagon-io"]);
1449 assert_eq!(protected_names(Some(" , ")), ["flagon-io"]);
1450 assert_eq!(
1451 protected_names(Some("Flagon-IO, acme ,wsp_1")),
1452 ["flagon-io", "acme", "wsp_1"]
1453 );
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1454 }
1455}

This file's history is long; its oldest lines are credited to the oldest commit read.