g1t/crates/contracts/src/identity.rs

1,416 lines48,374 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
320/// `create_workspace`. Returns `Outcome<Workspace>`.
321#[derive(Debug, Serialize, Deserialize)]
322pub struct CreateWorkspaceArgs {
323 pub user: User,
324 pub slug: String,
325 #[serde(default)]
326 pub name: String,
327}
328
329/// `get_workspace`: public details, or null. Returns `Option<Workspace>`.
330#[derive(Debug, Serialize, Deserialize)]
331pub struct SlugArgs {
332 pub slug: String,
333}
334
335/// `list_members`: members only. Returns `Outcome<Vec<Member>>`.
336#[derive(Debug, Serialize, Deserialize)]
337pub struct ListMembersArgs {
338 pub slug: String,
339 pub viewer: crate::Viewer,
340}
341
342/// `add_member` and `remove_member`: owners only.
343/// Each returns `Outcome<bool>`.
344#[derive(Debug, Serialize, Deserialize)]
345pub struct MemberArgs {
346 pub actor: User,
347 pub slug: String,
348 pub username: String,
349}
OAuth 2.1 sign-in for MCP clients and other applications350
Agents as a team: lifecycle, merge queue, billing and a new shell351/// `update_workspace`: owners only. An empty name falls back to the slug;
352/// an empty description clears it. Returns `Outcome<Workspace>`.
353#[derive(Debug, Serialize, Deserialize)]
354pub struct UpdateWorkspaceArgs {
355 pub actor: User,
356 pub slug: String,
357 pub name: String,
358 pub description: String,
359}
360
Agents and memory, checks and conflicts, profiles, slug renames, custom domains361/// `rename_workspace`: owners only. Changes the workspace's slug, the first
362/// segment of its URLs, to `new_slug`; the display name is untouched. The
363/// old slug redirects to the new one, and is held for this workspace, for
364/// [`SLUG_HOLD_DAYS`]. Publishes `workspace.renamed`. Returns
365/// `Outcome<Workspace>`.
366///
367/// `check_workspace_rename` takes the same arguments and answers whether
368/// the rename would be allowed, changing nothing. Returns `Outcome<bool>`.
369#[derive(Debug, Serialize, Deserialize)]
370#[serde(rename_all = "camelCase")]
371pub struct RenameWorkspaceArgs {
372 pub actor: User,
373 pub slug: String,
374 pub new_slug: String,
375}
376
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look377/// `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 member378/// the workspace's slug, typed out. Refused for a protected workspace
379/// ([`protected_names`]), whoever asks, and while billing cannot settle it
380/// (`close_workspace`). Everything in it goes with it at once: nobody can
381/// reach it, its tokens stop working, its pages are not found, and its
382/// repositories, projects and apps are deleted with it. It is kept for
383/// [`WORKSPACE_RESTORE_DAYS`] so g1t's staff can restore it, then purged:
384/// its memberships, access tokens and old-slug redirects go, and billing's
385/// ledger and the audit log keep its history. The slug is never given to
386/// another workspace; the person whose username it is may make a workspace
387/// of that name again once it is purged. Publishes `workspace.deleting`,
388/// and `workspace.deleted` at the purge. Returns `Outcome<bool>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look389///
390/// `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 member391/// ignored) and says what would go and whether anything stands in the way,
392/// changing nothing. Returns `Outcome<WorkspaceDeletion>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look393#[derive(Debug, Serialize, Deserialize)]
394pub struct DeleteWorkspaceArgs {
395 pub actor: User,
396 pub slug: String,
397 #[serde(default)]
398 pub confirm: String,
399 /// Where the request came in, for the audit log; g1t.sh when absent.
400 #[serde(default)]
401 pub surface: Option<crate::audit::Surface>,
402}
403
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member404/// What deleting a workspace takes with it, and what stands in the way.
405/// 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 look406#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
407pub struct WorkspaceDeletion {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member408 /// Its live repositories, which are deleted with it.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look409 pub repositories: u32,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member410 /// Its projects, hidden with it.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look411 pub projects: u32,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member412 #[serde(default)]
413 pub members: u32,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look414 /// Why billing cannot close the workspace yet, in words for its owner.
415 pub billing: Option<String>,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member416 /// It can never be deleted, by anyone ([`protected_names`]).
417 #[serde(default)]
418 pub protected: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look419}
420
421impl WorkspaceDeletion {
422 pub fn blocked(&self) -> bool {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member423 self.protected || self.billing.is_some()
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look424 }
425
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member426 /// 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 look427 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 member428 if self.protected {
429 return Some(protected_refusal(slug));
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look430 }
431 self.billing.clone()
432 }
433}
434
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member435/// How long a deleted workspace is kept, for staff to restore, before it is
436/// purged.
437pub const WORKSPACE_RESTORE_DAYS: u64 = 30;
438
439/// Workspaces nobody can delete, whatever identity's `PROTECTED_WORKSPACES`
440/// says: Flagon's, which runs g1t.
441pub const ALWAYS_PROTECTED: &[&str] = &["flagon-io"];
442
443/// The protected workspaces: `configured` (comma-separated slugs or
444/// workspace ids, as identity's `PROTECTED_WORKSPACES` holds them), and
445/// [`ALWAYS_PROTECTED`] whatever it says, so an empty or missing variable
446/// still protects them. Lowercased, without duplicates.
447pub fn protected_names(configured: Option<&str>) -> Vec<String> {
448 let mut names: Vec<String> = Vec::new();
449 let given = configured.unwrap_or_default().split(',');
450 for name in ALWAYS_PROTECTED.iter().copied().chain(given) {
451 let name = name.trim().to_lowercase();
452 if !name.is_empty() && !names.contains(&name) {
453 names.push(name);
454 }
455 }
456 names
457}
458
459/// Why a protected workspace is not deleted, purged or acted on.
460pub fn protected_refusal(slug: &str) -> String {
461 format!("{slug} is protected and can never be deleted.")
462}
463
464/// `admin_deleted_workspaces` takes no arguments (`{}`) and returns
465/// `Vec<DeletedWorkspace>`, newest first. Staff only.
466///
467/// A workspace an owner deleted, kept until `purge_after` for staff to
468/// restore.
469#[derive(Clone, Debug, Serialize, Deserialize)]
470#[serde(rename_all = "camelCase")]
471pub struct DeletedWorkspace {
472 pub workspace_id: String,
473 pub slug: String,
474 pub name: String,
475 /// RFC 3339.
476 pub deleted_at: String,
477 /// The username of the owner who deleted it.
478 pub deleted_by: String,
479 /// RFC 3339: when it is purged unless restored first.
480 pub purge_after: String,
481 /// What went with it, counted when it was deleted.
482 pub went: WorkspaceDeletion,
483 /// Whether staff can still restore it.
484 pub restorable: bool,
485}
486
487/// `admin_restore_workspace` and `admin_purge_workspace`: staff restore a
488/// deleted workspace within [`WORKSPACE_RESTORE_DAYS`], or purge it now.
489/// `staff` is who, for the audit logs. Purging needs `confirm`, the slug
490/// typed out, and is refused for a protected workspace. Restoring publishes
491/// `workspace.restored`; purging, `workspace.deleted`. Both return
492/// `Outcome<bool>`.
493#[derive(Debug, Serialize, Deserialize)]
494#[serde(rename_all = "camelCase")]
495pub struct AdminDeletedWorkspaceArgs {
496 pub workspace_id: String,
497 pub staff: String,
498 #[serde(default)]
499 pub confirm: String,
500}
501
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look502/// `transfer_repo_scopes`: a repository moved from `from` to `to`; the
503/// tokens of agents at work on it are kept pointing at it. For repos'
504/// `transfer`. Returns `bool`.
505#[derive(Debug, Serialize, Deserialize)]
506pub struct TransferRepoScopesArgs {
507 pub from: crate::repos::RepoPath,
508 pub to: crate::repos::RepoPath,
509}
510
Agents and memory, checks and conflicts, profiles, slug renames, custom domains511/// How long a workspace's old slug keeps redirecting to it, and stays
512/// reserved for it, after a rename.
513pub const SLUG_HOLD_DAYS: u64 = 90;
514
515/// How long a workspace must wait between renames.
516pub const RENAME_COOLDOWN_HOURS: u64 = 24;
517
518// `resolve_slug` takes `SlugArgs` and returns `Option<String>`: the
519// workspace's current slug when `slug` is one it was renamed from within
520// the last `SLUG_HOLD_DAYS`, and null otherwise (including for a slug that
521// is in use).
522
Workspace names and icons, and a component kit for every control523/// `set_workspace_avatar`: owners only. `image` is the file's bytes in
524/// base64: PNG, JPEG, WebP or GIF, at most `MAX_AVATAR_BYTES`. Null removes
525/// the icon. Returns `Outcome<Workspace>`.
526#[derive(Debug, Serialize, Deserialize)]
527pub struct SetWorkspaceAvatarArgs {
528 pub actor: User,
529 pub slug: String,
530 pub image: Option<String>,
531}
532
533/// `set_user_avatar`: a person's own avatar, as `SetWorkspaceAvatarArgs`.
534/// Returns `Outcome<Option<String>>`: the new avatar, or null once removed.
535#[derive(Debug, Serialize, Deserialize)]
536pub struct SetUserAvatarArgs {
537 pub user: User,
538 pub image: Option<String>,
539}
540
541/// The largest avatar that can be uploaded, in bytes.
542pub const MAX_AVATAR_BYTES: usize = 1024 * 1024;
543
Agents as a team: lifecycle, merge queue, billing and a new shell544/// `list_workspace_tokens`: members only. Returns
545/// `Outcome<Vec<AccessToken>>`.
546#[derive(Debug, Serialize, Deserialize)]
547pub struct WorkspaceTokensArgs {
548 pub slug: String,
549 pub viewer: crate::Viewer,
550}
551
552/// `create_workspace_token`: owners only. The token belongs to the
553/// workspace, acts as it, and keeps working when the member who made it
554/// leaves. Returns `Outcome<CreatedAccessToken>`.
555#[derive(Debug, Serialize, Deserialize)]
556pub struct CreateWorkspaceTokenArgs {
557 pub actor: User,
558 pub slug: String,
559 pub name: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step560 /// Its scopes; null for full access.
561 #[serde(default)]
562 pub scopes: Option<Vec<String>>,
563 /// When set, the token stops working after this many seconds. It is
564 /// listed with the workspace's tokens either way. Null: no expiry.
565 #[serde(default)]
566 pub ttl_seconds: Option<u64>,
Agents as a team: lifecycle, merge queue, billing and a new shell567}
568
569/// `remove_workspace_token`: owners only. Returns `Outcome<bool>`.
570#[derive(Debug, Serialize, Deserialize)]
571pub struct RemoveWorkspaceTokenArgs {
572 pub actor: User,
573 pub slug: String,
574 pub id: String,
575}
576
OAuth 2.1 sign-in for MCP clients and other applications577/// `oauth_authorize`: the signed-in person approved an application. The
578/// caller has checked the client and that it may be redirected to
579/// `redirect_uri`. Returns `OAuthCode`.
580#[derive(Debug, Serialize, Deserialize)]
581#[serde(rename_all = "camelCase")]
582pub struct OAuthAuthorizeArgs {
583 pub user: User,
584 pub client_id: String,
585 /// Shown wherever the application's access is listed.
586 pub client_name: String,
587 pub redirect_uri: String,
588 /// PKCE challenge, method S256.
589 pub code_challenge: String,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step590 /// What the person granted, as `resource:level`. Null: full access.
591 #[serde(default)]
592 pub scopes: Option<Vec<String>>,
OAuth 2.1 sign-in for MCP clients and other applications593}
594
595#[derive(Debug, Serialize, Deserialize)]
596pub struct OAuthCode {
597 pub code: String,
598}
599
600/// `oauth_exchange`: redeems an authorization code.
601/// Returns `Outcome<OAuthTokens>`.
602#[derive(Debug, Serialize, Deserialize)]
603#[serde(rename_all = "camelCase")]
604pub struct OAuthExchangeArgs {
605 pub code: String,
606 pub code_verifier: String,
607 pub client_id: String,
608 pub redirect_uri: String,
609}
610
611/// `oauth_refresh`: trades a refresh token for new tokens.
612/// Returns `Outcome<OAuthTokens>`.
613#[derive(Debug, Serialize, Deserialize)]
614#[serde(rename_all = "camelCase")]
615pub struct OAuthRefreshArgs {
616 pub refresh_token: String,
617 pub client_id: String,
618}
619
620#[derive(Debug, Serialize, Deserialize)]
621#[serde(rename_all = "camelCase")]
622pub struct OAuthTokens {
623 pub access_token: String,
624 /// Works once; using it returns the next one.
625 pub refresh_token: String,
626 /// Seconds until the access token stops working.
627 pub expires_in: u64,
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step628 /// The scopes granted, space-separated, or `*` for full access.
629 #[serde(default)]
630 pub scope: Option<String>,
OAuth 2.1 sign-in for MCP clients and other applications631}
632
633/// An application a person has signed in to. Listed by `list_oauth_grants`
634/// and ended by `revoke_oauth_grant`.
635#[derive(Debug, Serialize, Deserialize)]
636#[serde(rename_all = "camelCase")]
637pub struct OAuthGrant {
638 pub id: String,
639 pub client_name: String,
640 /// RFC 3339.
641 pub created_at: String,
642 /// RFC 3339.
643 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 step644 /// What the person granted. Null: full access.
645 #[serde(default)]
646 pub scopes: Option<Vec<String>>,
647 /// Signed in before applications were given scopes: full access until
648 /// someone narrows it.
649 #[serde(default)]
650 pub legacy: bool,
651}
652
653/// `update_oauth_grant`: changes what an application the person signed in
654/// to may do, at once and when it refreshes. Returns `Outcome<OAuthGrant>`.
655#[derive(Debug, Serialize, Deserialize)]
656pub struct UpdateOAuthGrantArgs {
657 pub user: User,
658 pub id: String,
659 #[serde(default)]
660 pub scopes: Option<Vec<String>>,
OAuth 2.1 sign-in for MCP clients and other applications661}
Agents as a team: lifecycle, merge queue, billing and a new shell662
663
664/// 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 API665#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Agents as a team: lifecycle, merge queue, billing and a new shell666pub struct AgentScope {
667 pub repo: crate::repos::RepoPath,
668 /// API and MCP operation names, such as `create_issue`.
669 pub operations: Vec<String>,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API670 /// Set on a run credential: the run it belongs to, and what it may do
671 /// with git. See [`crate::credentials`].
672 #[serde(default, skip_serializing_if = "Option::is_none")]
673 pub run: Option<crate::credentials::RunBinding>,
Agents as a team: lifecycle, merge queue, billing and a new shell674}
675
676/// `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-agent677/// behalf. It acts as `g1t`, a member of the repository's workspace,
Agents as a team: lifecycle, merge queue, billing and a new shell678/// and only for the operations in `scope`. Returns `CreatedAccessToken`.
679#[derive(Debug, Serialize, Deserialize)]
680#[serde(rename_all = "camelCase")]
681pub struct CreateAgentTokenArgs {
682 /// The person the agent works for; the token is recorded as theirs.
683 pub on_behalf_of: User,
684 pub scope: AgentScope,
685 pub ttl_seconds: u64,
686}
687
688// `agent_scope` takes `TokenArgs` and returns `Option<AgentScope>`: what an
689// agent's token may do, or null for any other token.
690
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent691/// The id g1t's agent acts under. Only ever stored, never shown: it keeps
692/// the agent's work apart from g1t's own ([`crate::system::ID`]) where
693/// that matters, such as whether its approval counts.
Agents as a team: lifecycle, merge queue, billing and a new shell694pub 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-agent695/// The name g1t's agent is shown by: g1t's own, [`crate::system::USERNAME`].
696/// Everything it does, people see g1t do.
697pub const AGENT_NAME: &str = crate::system::USERNAME;
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace698
699// --- Staff ---------------------------------------------------------------
700//
701// Staff-only methods, for sudo.g1t.sh. They take no viewer and check no
702// membership: only sudo calls them, over its service binding, after it has
703// verified a Cloudflare Access sign-in and its staff list. Nothing a
704// customer can reach should ever forward to them.
705
706/// `notify_owners`: emails a short notice, with one link, to each owner of
707/// a workspace with a confirmed address. Called by other services (billing
708/// warns owners near their usage limit), never on a person's behalf.
709/// Returns how many were sent.
710#[derive(Clone, Debug, Serialize, Deserialize)]
711pub struct NotifyOwnersArgs {
712 pub workspace: String,
713 pub subject: String,
714 /// One or two sentences: what happened and what it means.
715 pub intro: String,
716 /// The button's words, such as `Open billing`.
717 pub action: String,
718 /// Where the button goes; must be on g1t.sh.
719 pub link: String,
720 /// Small print: why they got it.
721 pub footer: String,
722}
723
724/// `admin_workspaces`: every workspace, newest first, at most
725/// [`ADMIN_WORKSPACES_LIMIT`], optionally only those whose slug, name or
726/// an owner's username or email contains `query`. Returns
727/// `Vec<AdminWorkspace>`. Staff only.
728#[derive(Debug, Default, Serialize, Deserialize)]
729pub struct AdminWorkspacesArgs {
730 #[serde(default)]
731 pub query: Option<String>,
732}
733
734/// The most workspaces one `admin_workspaces` call returns.
735pub const ADMIN_WORKSPACES_LIMIT: usize = 500;
736
737/// An owner of a workspace, as staff see them.
738#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
739pub struct AdminOwner {
740 pub username: String,
741 pub email: Option<String>,
742}
743
744/// A workspace as staff see it: who owns it and how many belong to it.
745#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
746#[serde(rename_all = "camelCase")]
747pub struct AdminWorkspace {
748 pub slug: String,
749 pub name: String,
750 /// RFC 3339.
751 pub created_at: String,
752 pub owners: Vec<AdminOwner>,
753 pub member_count: u32,
754}
755
756/// `admin_workspace`: one workspace with every member, or null. Takes
757/// `SlugArgs`; returns `Option<AdminWorkspaceDetail>`. Staff only.
758#[derive(Clone, Debug, Serialize, Deserialize)]
759#[serde(rename_all = "camelCase")]
760pub struct AdminWorkspaceDetail {
761 pub slug: String,
762 pub name: String,
763 pub description: Option<String>,
764 /// RFC 3339.
765 pub created_at: String,
766 /// Owners first, then by username.
767 pub members: Vec<AdminMember>,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member768 /// It can never be deleted ([`protected_names`]).
769 #[serde(default)]
770 pub protected: bool,
Billing on Stripe's pages, month-end charges, warnings; sudo by workspace771}
772
773/// A member of a workspace, as staff see them.
774#[derive(Clone, Debug, Serialize, Deserialize)]
775pub struct AdminMember {
776 pub username: String,
777 pub email: Option<String>,
778 pub role: crate::Role,
779 /// When they joined the workspace. RFC 3339.
780 pub joined: String,
781}
Agents and memory, checks and conflicts, profiles, slug renames, custom domains782
783// --- Profiles ------------------------------------------------------------
784//
785// A person's public page at `g1t.sh/u/<username>`. Everything in a
786// `Profile` is shown to anyone, signed in or not; an email address never is.
787
788/// The most characters each profile field takes.
789pub const MAX_PROFILE_NAME: usize = 80;
790pub const MAX_PROFILE_BIO: usize = 160;
791pub const MAX_PROFILE_LOCATION: usize = 80;
792pub const MAX_PROFILE_WEBSITE: usize = 200;
793pub const MAX_PROFILE_PRONOUNS: usize = 40;
794
795/// What anyone may see about a person.
796#[derive(Clone, Debug, Default, Serialize, Deserialize)]
797#[serde(rename_all = "camelCase")]
798pub struct Profile {
799 pub username: String,
800 /// The name they go by, if they gave one.
801 pub name: Option<String>,
802 /// One or two lines about them, at most [`MAX_PROFILE_BIO`] characters.
803 pub bio: Option<String>,
804 pub location: Option<String>,
805 /// An `https://` address.
806 pub website: Option<String>,
807 pub pronouns: Option<String>,
808 /// The uploaded avatar's hash, served at `/avatars/<avatar>`.
809 pub avatar: Option<String>,
810 /// When the account was made. RFC 3339.
811 pub created_at: String,
812}
813
814// `profile` takes `UsernameArgs` and returns `Option<Profile>`: null for
815// an account that does not exist.
816
817/// `update_profile`: a person changes their own profile. Every field is
818/// replaced; an empty one is cleared. Returns `Outcome<Profile>`.
819#[derive(Debug, Default, Serialize, Deserialize)]
820#[serde(rename_all = "camelCase")]
821pub struct UpdateProfileArgs {
822 pub actor: User,
823 #[serde(default)]
824 pub name: String,
825 #[serde(default)]
826 pub bio: String,
827 #[serde(default)]
828 pub location: String,
829 #[serde(default)]
830 pub website: String,
831 #[serde(default)]
832 pub pronouns: String,
833}
834
835/// `profile_workspaces`: the workspaces shown on a person's profile, as
836/// `viewer` may see them. A membership is shown only when it is no secret
837/// from the viewer: a workspace the viewer belongs to as well, or one of
838/// `public`, the workspaces the caller found the person has made a public
839/// project in (whose page shows that already). Returns
840/// `Vec<ProfileWorkspace>`; empty for an account that does not exist.
841#[derive(Debug, Serialize, Deserialize)]
842pub struct ProfileWorkspacesArgs {
843 pub username: String,
844 pub viewer: crate::Viewer,
845 #[serde(default)]
846 pub public: Vec<String>,
847}
848
849/// A workspace on a person's profile.
850#[derive(Clone, Debug, Serialize, Deserialize)]
851pub struct ProfileWorkspace {
852 pub slug: String,
853 pub name: String,
854 pub avatar: Option<String>,
855}
Search across all of g1t, Explore, and a command palette856
857/// `directory`: every account or every workspace, as their public pages
858/// show them, a page at a time in name order. For services that index
859/// them, such as search; nothing private is in it. Returns
860/// `DirectoryPage`.
861#[derive(Debug, Default, Serialize, Deserialize)]
862pub struct DirectoryArgs {
863 /// `user` or `workspace`.
864 pub kind: String,
865 /// Names after this one.
866 #[serde(default)]
867 pub after: Option<String>,
868 pub limit: u32,
869}
870
871/// One account or workspace in the directory.
872#[derive(Clone, Debug, Serialize, Deserialize)]
873#[serde(rename_all = "camelCase")]
874pub struct DirectoryEntry {
875 /// The account's or workspace's id.
876 pub id: String,
877 /// A username or a workspace's slug.
878 pub slug: String,
879 /// A person's display name or a workspace's name.
880 pub name: Option<String>,
881 /// A person's bio or a workspace's description.
882 pub bio: Option<String>,
883 pub avatar: Option<String>,
884 /// RFC 3339.
885 pub created_at: String,
886}
887
888#[derive(Clone, Debug, Default, Serialize, Deserialize)]
889pub struct DirectoryPage {
890 pub entries: Vec<DirectoryEntry>,
891 /// Where the next page starts; null on the last.
892 pub next: Option<String>,
893}
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look894
895// --- Invites ---------------------------------------------------------------
896//
897// While registration is invite-only, every new account (with a password or
898// through GitHub) needs an invite code. Each person may have
899// `INVITES_PER_USER` invites out at a time; staff grant more to a person or
900// to a workspace, whose owners share them. Inviting an email with no
901// account into a workspace makes an invite bound to that address, which
902// registers and joins in one step. See services/identity/src/invites.rs.
903
904/// Whether anyone may make an account, or only someone with an invite. Set
905/// by identity's `REGISTRATION_MODE` var; anything but `open`, including
906/// leaving it unset, is `invite`, so a missing setting never opens sign-up.
907#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
908#[serde(rename_all = "snake_case")]
909pub enum RegistrationMode {
910 #[default]
911 Invite,
912 Open,
913}
914
915impl RegistrationMode {
916 pub fn parse(text: Option<&str>) -> RegistrationMode {
917 match text.map(|text| text.trim().to_ascii_lowercase()).as_deref() {
918 Some("open") => RegistrationMode::Open,
919 _ => RegistrationMode::Invite,
920 }
921 }
922}
923
924/// How many invites a person may have out at once, unless identity's
925/// `INVITES_PER_USER` var says otherwise.
926pub const INVITES_PER_USER: u32 = 5;
927
928/// How long an invite works, unless identity's `INVITE_TTL_DAYS` var says
929/// otherwise.
930pub const INVITE_TTL_DAYS: u64 = 30;
931
932/// Where an invite stands. Only a pending invite can be used or revoked.
933/// An expired or revoked invite that was never used gives its inviter the
934/// invite back.
935#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
936#[serde(rename_all = "snake_case")]
937pub enum InviteStatus {
938 Pending,
939 Redeemed,
940 Expired,
941 Revoked,
942}
943
944/// What using an invite does.
945#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
946#[serde(rename_all = "snake_case")]
947pub enum InviteKind {
948 /// Makes a new account, and joins `workspace` when one is set.
949 Account,
950 /// An existing account joins `workspace`. Never makes an account.
951 Workspace,
952}
953
954/// Whose allowance an invite uses.
955#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
956#[serde(rename_all = "snake_case")]
957pub enum InviteCharge {
958 /// Its inviter's own.
959 User,
960 /// The workspace's, granted by staff and shared by its owners.
961 Workspace,
962 /// Nobody's: staff minted it, or it invites an existing account.
963 None,
964}
965
966/// One invite, as the person who made it sees it.
967#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
968#[serde(rename_all = "camelCase")]
969pub struct Invite {
970 pub id: String,
971 /// The code, such as `g1t-k7m2-q9xd-…`: returned once when the invite
972 /// is made, and afterwards to whoever made it while it is pending.
973 /// Null otherwise.
974 pub code: Option<String>,
975 /// The code's first group, such as `g1t-k7m2`, to recognise it by.
976 pub hint: String,
977 /// Only an account with this address can use it. Null: anyone with
978 /// the code.
979 pub email: Option<String>,
980 pub kind: InviteKind,
981 /// The workspace it joins, by slug.
982 pub workspace: Option<String>,
983 pub status: InviteStatus,
984 pub charged_to: InviteCharge,
985 /// Who made it, by username. Null when g1t staff did.
986 pub invited_by: Option<String>,
987 /// The account that used it, by username.
988 pub redeemed_by: Option<String>,
989 /// RFC 3339.
990 pub created_at: String,
991 /// RFC 3339.
992 pub expires_at: String,
993 /// RFC 3339.
994 pub redeemed_at: Option<String>,
995 /// RFC 3339.
996 pub revoked_at: Option<String>,
997 /// The staff member who minted it. Only in staff views.
998 #[serde(default, skip_serializing_if = "Option::is_none")]
999 pub staff: Option<String>,
1000}
1001
1002/// How many invites someone may have out, and how many they have.
1003#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1004pub struct Allowance {
1005 /// Null: no limit.
1006 pub limit: Option<u32>,
1007 /// Pending and used invites; revoked and expired ones are not counted.
1008 pub used: u32,
1009 /// Null: no limit.
1010 pub remaining: Option<u32>,
1011}
1012
1013impl Allowance {
1014 pub fn new(limit: Option<u32>, used: u32) -> Allowance {
1015 Allowance {
1016 limit,
1017 used,
1018 remaining: limit.map(|limit| limit.saturating_sub(used)),
1019 }
1020 }
1021
1022 pub fn exhausted(&self) -> bool {
1023 self.remaining == Some(0)
1024 }
1025}
1026
1027/// A workspace's shared invites, for one of its owners.
1028#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1029pub struct WorkspaceAllowance {
1030 pub slug: String,
1031 pub allowance: Allowance,
1032}
1033
1034/// `list_invites` (takes `UserArgs`): a person's invites, newest first,
1035/// and what they have left. Returns `InvitesOverview`.
1036#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1037pub struct InvitesOverview {
1038 pub mode: RegistrationMode,
1039 pub allowance: Allowance,
1040 /// Workspaces the person owns that staff granted invites to.
1041 pub workspaces: Vec<WorkspaceAllowance>,
1042 pub invites: Vec<Invite>,
1043}
1044
1045/// `create_invite`: a person makes an invite, optionally for one email
1046/// address. People only; never an agent or a workspace's token, and not
1047/// before their email is confirmed. Uses one of the person's invites, or,
1048/// with `workspace`, one of the invites staff granted that workspace (its
1049/// owners only). Emails the address when one is given. Returns
1050/// `Outcome<Invite>`, with the code.
1051///
1052/// `revoke_invite` (takes `RemoveArgs`): its maker revokes a pending
1053/// invite; a workspace's owners may revoke one made for the workspace.
1054/// The invite comes back to whoever it was charged to. Returns
1055/// `Outcome<Invite>`.
1056#[derive(Debug, Serialize, Deserialize)]
1057pub struct CreateInviteArgs {
1058 pub user: User,
1059 #[serde(default)]
1060 pub email: Option<String>,
1061 /// Use this workspace's granted invites, by slug.
1062 #[serde(default)]
1063 pub workspace: Option<String>,
1064 /// Where the request came in, for the audit log; g1t.sh when absent.
1065 #[serde(default)]
1066 pub surface: Option<crate::audit::Surface>,
1067}
1068
1069/// `check_invite`: what an invite code is for, before using it. Returns
1070/// `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 quotas1071/// expired gets the same answer, so codes cannot be probed. With
1072/// `any_status`, a real code that can no longer be used is described
1073/// instead (its `status` says why), so the page can say whom to ask for a
1074/// 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 look1075#[derive(Debug, Serialize, Deserialize)]
1076pub struct InviteCodeArgs {
1077 pub code: String,
1078 /// Who is asking, such as the visitor's IP address, for rate limits.
1079 #[serde(default)]
1080 pub client: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1081 /// Who is looking, if signed in: sets `InvitePreview::for_viewer`.
1082 #[serde(default)]
1083 pub viewer: Option<User>,
1084 #[serde(default)]
1085 pub any_status: bool,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1086}
1087
1088/// Someone shown on an invite.
1089#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1090pub struct InviteFrom {
1091 pub username: String,
1092 pub name: Option<String>,
1093 pub avatar: Option<String>,
1094}
1095
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1096/// A repository an invite code was sent with: using the code accepts the
1097/// invitation to collaborate on it.
1098#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1099pub struct InviteRepository {
1100 /// `workspace/repo`.
1101 pub name: String,
1102 /// The role it gives, such as `write`.
1103 pub role: String,
1104}
1105
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1106/// What a valid invite code is for.
1107#[derive(Clone, Debug, Serialize, Deserialize)]
1108#[serde(rename_all = "camelCase")]
1109pub struct InvitePreview {
1110 pub kind: InviteKind,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1111 /// Pending, unless `any_status` asked about a code that is spent.
1112 pub status: InviteStatus,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1113 /// Null when g1t staff sent it.
1114 pub invited_by: Option<InviteFrom>,
1115 pub workspace: Option<ProfileWorkspace>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1116 /// The repository it accepts an invitation to, if it was sent with one.
1117 pub repository: Option<InviteRepository>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1118 /// The address it is for, partly hidden, such as `a•••@example.com`.
1119 pub email: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1120 /// The address in full, while it is pending: whoever holds the code
1121 /// was sent it there. Fills in and locks the sign-up form.
1122 pub address: Option<String>,
1123 /// Whether the address it is for has a g1t account already, so the
1124 /// page asks them to sign in rather than sign up.
1125 pub has_account: bool,
1126 /// With a viewer: whether the invite is theirs (it is for one of their
1127 /// confirmed addresses, or they used it). Null without a viewer or,
1128 /// for a pending invite, when it is for anyone with the code.
1129 pub for_viewer: Option<bool>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1130 /// RFC 3339.
1131 pub expires_at: String,
1132}
1133
1134/// `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 quotas1135/// their confirmed address, and joins the workspace, or an invite sent with
1136/// a repository invitation, and accepts it. Returns `Outcome<String>`: the
1137/// workspace's slug, or `workspace/repo`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1138#[derive(Debug, Serialize, Deserialize)]
1139pub struct AcceptInviteArgs {
1140 pub user: User,
1141 pub code: String,
1142}
1143
1144/// `invite_member`: an owner invites an email address into a workspace.
1145/// It always makes an invite bound to that address and emails it, so the
1146/// answer never says whether the address has an account. Without one, the
1147/// invite registers and joins in one step, and uses one of the workspace's
1148/// granted invites or else one of the owner's own. With one, it costs
1149/// nothing. Returns `Outcome<Invite>`, with the code.
1150#[derive(Debug, Serialize, Deserialize)]
1151pub struct InviteMemberArgs {
1152 pub actor: User,
1153 pub slug: String,
1154 pub email: String,
1155 /// Where the request came in, for the audit log; g1t.sh when absent.
1156 #[serde(default)]
1157 pub surface: Option<crate::audit::Surface>,
1158}
1159
1160/// `workspace_invites` (takes `ListMembersArgs`): a workspace's invites,
1161/// newest first. Owners only. Returns `Outcome<Vec<Invite>>`.
1162///
1163/// `revoke_workspace_invite`: owners only. Returns `Outcome<Invite>`.
1164#[derive(Debug, Serialize, Deserialize)]
1165pub struct WorkspaceInviteArgs {
1166 pub actor: User,
1167 pub slug: String,
1168 pub id: String,
1169}
1170
1171/// `request_access`: someone without an invite asks for one. Kept on the
1172/// waitlist, one entry per address. Answers the same way whether or not
1173/// the address is already on it. Returns `Outcome<bool>`.
1174#[derive(Debug, Default, Serialize, Deserialize)]
1175pub struct RequestAccessArgs {
1176 pub email: String,
1177 /// What they will build, if they said.
1178 #[serde(default)]
1179 pub about: String,
1180 /// Who is asking, such as the visitor's IP address, for rate limits.
1181 #[serde(default)]
1182 pub client: Option<String>,
1183}
1184
1185/// The most characters `RequestAccessArgs::about` keeps.
1186pub const MAX_WAITLIST_ABOUT: usize = 1000;
1187
1188// `registration` takes `{}` and returns `RegistrationMode`.
1189
1190// --- Invites, staff only ---
1191
1192#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1193#[serde(rename_all = "snake_case")]
1194pub enum WaitlistStatus {
1195 Waiting,
1196 Invited,
1197 Dismissed,
1198}
1199
1200impl WaitlistStatus {
1201 pub fn as_str(self) -> &'static str {
1202 match self {
1203 WaitlistStatus::Waiting => "waiting",
1204 WaitlistStatus::Invited => "invited",
1205 WaitlistStatus::Dismissed => "dismissed",
1206 }
1207 }
1208}
1209
1210/// Someone who asked for access.
1211#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1212#[serde(rename_all = "camelCase")]
1213pub struct WaitlistEntry {
1214 pub id: String,
1215 pub email: String,
1216 pub about: Option<String>,
1217 pub status: WaitlistStatus,
1218 pub invite_id: Option<String>,
1219 pub decided_by: Option<String>,
1220 /// RFC 3339.
1221 pub decided_at: Option<String>,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1222 /// What staff wrote when approving; it went in the invite email.
1223 #[serde(default)]
1224 pub note: Option<String>,
1225 /// The account made with the invite, once it was used.
1226 #[serde(default)]
1227 pub joined_as: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1228 /// When they first asked. RFC 3339.
1229 pub created_at: String,
1230 /// When they last asked. RFC 3339.
1231 pub updated_at: String,
1232}
1233
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1234/// `admin_waitlist`: the waitlist, newest first, at most
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1235/// [`ADMIN_INVITES_LIMIT`]. Returns `Vec<WaitlistEntry>`.
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1236///
1237/// `admin_waitlist_pending` takes `{}` and returns the number of requests
1238/// still waiting, for sudo's navigation.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1239#[derive(Debug, Default, Serialize, Deserialize)]
1240pub struct AdminWaitlistArgs {
1241 /// Part of an email address or of what they said.
1242 #[serde(default)]
1243 pub query: Option<String>,
1244 /// Null: every status.
1245 #[serde(default)]
1246 pub status: Option<WaitlistStatus>,
1247}
1248
1249/// The most rows one staff listing of invites or the waitlist returns.
1250pub const ADMIN_INVITES_LIMIT: usize = 500;
1251
1252/// `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 quotas1253/// address, charged to nobody, and emails it, with `note` if given;
1254/// dismissing only marks the entry. Returns `Outcome<WaitlistEntry>`.
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1255#[derive(Debug, Serialize, Deserialize)]
1256pub struct AdminDecideWaitlistArgs {
1257 pub id: String,
1258 pub approve: bool,
1259 /// The staff member, by email.
1260 pub staff: String,
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1261 /// A line for the invite email, up to [`MAX_WAITLIST_NOTE`] characters.
1262 #[serde(default)]
1263 pub note: Option<String>,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1264}
1265
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas1266/// The most characters an approval's note keeps.
1267pub const MAX_WAITLIST_NOTE: usize = 500;
1268
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1269/// `admin_invites`: every invite, newest first, at most
1270/// [`ADMIN_INVITES_LIMIT`], optionally only those whose code starts with
1271/// `query`, or whose email, inviter or redeemer contains it. Returns
1272/// `Vec<Invite>`.
1273#[derive(Debug, Default, Serialize, Deserialize)]
1274pub struct AdminInvitesArgs {
1275 #[serde(default)]
1276 pub query: Option<String>,
1277}
1278
1279/// `admin_revoke_invite`: revokes any pending invite. Returns
1280/// `Outcome<Invite>`.
1281#[derive(Debug, Serialize, Deserialize)]
1282pub struct AdminRevokeInviteArgs {
1283 pub id: String,
1284 pub staff: String,
1285}
1286
1287/// `admin_mint_invite`: staff make an invite that uses nobody's
1288/// allowance, optionally bound to (and emailed to) an address. Returns
1289/// `Outcome<Invite>`, with the code.
1290#[derive(Debug, Serialize, Deserialize)]
1291pub struct AdminMintInviteArgs {
1292 #[serde(default)]
1293 pub email: Option<String>,
1294 pub staff: String,
1295}
1296
1297/// Who staff grant invites to.
1298#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1299#[serde(rename_all = "snake_case")]
1300pub enum GrantTarget {
1301 User,
1302 Workspace,
1303}
1304
1305impl GrantTarget {
1306 pub fn as_str(self) -> &'static str {
1307 match self {
1308 GrantTarget::User => "user",
1309 GrantTarget::Workspace => "workspace",
1310 }
1311 }
1312}
1313
1314/// `admin_grant_invites`: gives a person (by username) or a workspace (by
1315/// slug) `amount` more invites; a negative amount takes some back. Returns
1316/// `Outcome<Allowance>`: theirs afterwards.
1317#[derive(Debug, Serialize, Deserialize)]
1318pub struct AdminGrantInvitesArgs {
1319 pub target: GrantTarget,
1320 pub name: String,
1321 pub amount: i32,
1322 #[serde(default)]
1323 pub note: String,
1324 pub staff: String,
1325}
1326
1327/// The most invites one grant gives or takes back.
1328pub const MAX_INVITE_GRANT: i32 = 1000;
1329
1330/// Invites staff granted.
1331#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1332#[serde(rename_all = "camelCase")]
1333pub struct InviteGrant {
1334 pub amount: i32,
1335 pub note: Option<String>,
1336 pub granted_by: String,
1337 /// RFC 3339.
1338 pub created_at: String,
1339}
1340
1341/// Someone a person invited, and whom they invited in turn.
1342#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1343#[serde(rename_all = "camelCase")]
1344pub struct InviteTreeNode {
1345 pub username: String,
1346 /// When they used the invite. RFC 3339.
1347 pub joined_at: String,
1348 pub invited: Vec<InviteTreeNode>,
1349}
1350
1351/// `admin_invite_tree` (takes `UsernameArgs`): where a person came from
1352/// and whom they brought, for tracing abuse. Returns `Option<InviteTree>`.
1353///
1354/// `admin_workspace_invites` (takes `SlugArgs`): a workspace's granted
1355/// invites, grants and invites. Returns `Option<InviteTree>` with
1356/// `username` the slug and no `invited_by`.
1357#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1358#[serde(rename_all = "camelCase")]
1359pub struct InviteTree {
1360 pub username: String,
1361 /// Who invited them, then who invited that person, and so on. Empty
1362 /// for an account made without an invite.
1363 pub invited_by: Vec<String>,
1364 /// The staff member who minted their invite, when staff did.
1365 pub staff: Option<String>,
1366 pub allowance: Allowance,
1367 pub grants: Vec<InviteGrant>,
1368 /// Their invites, newest first.
1369 pub invites: Vec<Invite>,
1370 /// Whom they invited, three levels down.
1371 pub invited: Vec<InviteTreeNode>,
1372}
1373
1374#[cfg(test)]
1375mod deletion_tests {
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1376 use super::{WorkspaceDeletion, protected_names};
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1377
1378 #[test]
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1379 fn only_billing_or_protection_stands_in_the_way() {
1380 let clear = WorkspaceDeletion {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1381 repositories: 2,
1382 projects: 1,
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1383 members: 3,
1384 ..WorkspaceDeletion::default()
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1385 };
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1386 assert!(!clear.blocked());
1387 assert_eq!(clear.reason("acme"), None);
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1388 let owing = WorkspaceDeletion {
1389 billing: Some("Pay first.".into()),
1390 ..WorkspaceDeletion::default()
1391 };
Packages, with a container registry on g1t.sh; workspaces deleted whole and kept 30 days; Members for every member1392 assert!(owing.blocked());
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1393 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 member1394 let protected = WorkspaceDeletion {
1395 billing: Some("Pay first.".into()),
1396 protected: true,
1397 ..WorkspaceDeletion::default()
1398 };
1399 assert!(protected.blocked());
1400 assert_eq!(
1401 protected.reason("flagon-io").as_deref(),
1402 Some("flagon-io is protected and can never be deleted.")
1403 );
1404 }
1405
1406 #[test]
1407 fn flagon_is_protected_whatever_the_variable_says() {
1408 assert_eq!(protected_names(None), ["flagon-io"]);
1409 assert_eq!(protected_names(Some("")), ["flagon-io"]);
1410 assert_eq!(protected_names(Some(" , ")), ["flagon-io"]);
1411 assert_eq!(
1412 protected_names(Some("Flagon-IO, acme ,wsp_1")),
1413 ["flagon-io", "acme", "wsp_1"]
1414 );
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1415 }
1416}