g1t/crates/contracts/src/identity.rs
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 redesign | 1 | //! 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 | ||
| 6 | use serde::{Deserialize, Serialize}; | |
| 7 | ||
| 8 | use crate::User; | |
| 9 | ||
| 10 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 11 | #[serde(rename_all = "camelCase")] | |
| 12 | pub struct SshKey { | |
| 13 | pub id: String, | |
| 14 | pub title: String, | |
| 15 | pub fingerprint: String, | |
| RFC 3339 timestamps in identity and repos | 16 | /// RFC 3339. |
| 17 | pub created_at: String, | |
| API and MCP server, Rust identity service, registration, site redesign | 18 | } |
| 19 | ||
| 20 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 21 | #[serde(rename_all = "camelCase")] | |
| 22 | pub struct AccessToken { | |
| 23 | pub id: String, | |
| 24 | pub name: String, | |
| RFC 3339 timestamps in identity and repos | 25 | /// RFC 3339. |
| 26 | pub created_at: String, | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 27 | /// 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 step | 32 | /// 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 redesign | 41 | } |
| 42 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 43 | /// `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 redesign | 47 | /// Returns `Outcome<SignedIn>`. |
| 48 | #[derive(Debug, Serialize, Deserialize)] | |
| 49 | pub 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 look | 52 | /// 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 redesign | 55 | } |
| 56 | ||
| 57 | #[derive(Debug, Serialize, Deserialize)] | |
| 58 | #[serde(rename_all = "camelCase")] | |
| 59 | pub 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")] | |
| 67 | pub 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)] | |
| 73 | pub struct GitCredentialsArgs { | |
| 74 | pub username: String, | |
| 75 | pub secret: String, | |
| 76 | } | |
| 77 | ||
| 78 | /// `user_for_access_token`. | |
| 79 | #[derive(Debug, Serialize, Deserialize)] | |
| 80 | pub struct TokenArgs { | |
| 81 | pub token: String, | |
| 82 | } | |
| 83 | ||
| 84 | /// `user_for_ssh_key`. | |
| 85 | #[derive(Debug, Serialize, Deserialize)] | |
| 86 | pub struct FingerprintArgs { | |
| 87 | pub fingerprint: String, | |
| 88 | } | |
| 89 | ||
| 90 | /// `user_by_username`. | |
| 91 | #[derive(Debug, Serialize, Deserialize)] | |
| 92 | pub struct UsernameArgs { | |
| 93 | pub username: String, | |
| 94 | } | |
| 95 | ||
| What happened across an outcome, as a feed beside its graph | 96 | /// `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)] | |
| 100 | pub struct UsernamesArgs { | |
| 101 | pub ids: Vec<String>, | |
| 102 | } | |
| 103 | ||
| API and MCP server, Rust identity service, registration, site redesign | 104 | /// `list_ssh_keys` and `list_access_tokens`. |
| 105 | #[derive(Debug, Serialize, Deserialize)] | |
| 106 | pub 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")] | |
| 114 | pub 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)] | |
| 122 | pub struct RemoveArgs { | |
| 123 | pub user: User, | |
| 124 | pub id: String, | |
| 125 | } | |
| 126 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 127 | /// `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 redesign | 130 | #[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 redesign | 132 | pub 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 step | 136 | /// 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 step | 140 | /// 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)] | |
| 153 | pub 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 redesign | 159 | } |
| 160 | ||
| 161 | /// The plaintext token is returned once and never stored. | |
| 162 | #[derive(Debug, Serialize, Deserialize)] | |
| 163 | pub 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 look | 170 | /// |
| 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 redesign | 174 | #[derive(Debug, Serialize, Deserialize)] |
| 175 | pub 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 look | 179 | /// 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 redesign | 186 | } |
| Email verification, password reset, and Git for AI scale positioning | 187 | |
| 188 | /// `verify_email`: the token from the emailed link. Returns `Outcome<User>`. | |
| 189 | #[derive(Debug, Serialize, Deserialize)] | |
| 190 | pub 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 look | 195 | /// 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 positioning | 199 | #[derive(Debug, Serialize, Deserialize)] |
| 200 | pub struct EmailArgs { | |
| 201 | pub email: String, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 202 | /// 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 positioning | 205 | } |
| 206 | ||
| 207 | /// `reset_password`: sets a new password and ends every session. | |
| 208 | /// Returns `Outcome<User>`. | |
| 209 | #[derive(Debug, Serialize, Deserialize)] | |
| 210 | pub struct ResetPasswordArgs { | |
| 211 | pub token: String, | |
| 212 | pub password: String, | |
| 213 | } | |
| Device sign-in replaces registering and minting tokens over the API | 214 | |
| 215 | /// `device_start`: begins a device sign-in. Returns `DeviceStart`. | |
| 216 | #[derive(Debug, Serialize, Deserialize)] | |
| 217 | #[serde(rename_all = "camelCase")] | |
| 218 | pub 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")] | |
| 225 | pub 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")] | |
| 240 | pub struct DeviceLookupArgs { | |
| 241 | pub user_code: String, | |
| 242 | } | |
| 243 | ||
| 244 | #[derive(Debug, Serialize, Deserialize)] | |
| 245 | #[serde(rename_all = "camelCase")] | |
| 246 | pub 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")] | |
| 255 | pub 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")] | |
| 264 | pub 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")] | |
| 271 | pub 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 repositories | 283 | |
| 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")] | |
| 288 | pub 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 shell | 292 | /// One line saying what the workspace is for. |
| 293 | pub description: Option<String>, | |
| Workspaces own repositories | 294 | /// RFC 3339. |
| 295 | pub created_at: String, | |
| 296 | pub member_count: u32, | |
| Workspace names and icons, and a component kit for every control | 297 | /// 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 look | 301 | /// 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 repositories | 305 | } |
| 306 | ||
| 307 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 308 | pub 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 look | 311 | /// 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 repositories | 318 | } |
| 319 | ||
| 320 | /// `create_workspace`. Returns `Outcome<Workspace>`. | |
| 321 | #[derive(Debug, Serialize, Deserialize)] | |
| 322 | pub 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)] | |
| 331 | pub struct SlugArgs { | |
| 332 | pub slug: String, | |
| 333 | } | |
| 334 | ||
| 335 | /// `list_members`: members only. Returns `Outcome<Vec<Member>>`. | |
| 336 | #[derive(Debug, Serialize, Deserialize)] | |
| 337 | pub 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)] | |
| 345 | pub 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 applications | 350 | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 351 | /// `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)] | |
| 354 | pub 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 domains | 361 | /// `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")] | |
| 371 | pub 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 look | 377 | /// `delete_workspace`: owners only, and only a person. `confirm` must be |
| 378 | /// the workspace's slug, typed out. Refused while the workspace still | |
| 379 | /// holds repositories or projects, or while billing cannot settle it | |
| 380 | /// (`close_workspace`). Removes its memberships, its access tokens and its | |
| 381 | /// old-slug redirects; billing's ledger and the audit log keep its | |
| 382 | /// history. The slug is never given to another workspace; the person | |
| 383 | /// whose username it is may make a workspace of that name again. | |
| 384 | /// Publishes `workspace.deleted`. Returns `Outcome<bool>`. | |
| 385 | /// | |
| 386 | /// `check_workspace_deletion` takes the same arguments (with `confirm` | |
| 387 | /// ignored) and says what stands in the way, changing nothing. Returns | |
| 388 | /// `Outcome<WorkspaceDeletion>`. | |
| 389 | #[derive(Debug, Serialize, Deserialize)] | |
| 390 | pub struct DeleteWorkspaceArgs { | |
| 391 | pub actor: User, | |
| 392 | pub slug: String, | |
| 393 | #[serde(default)] | |
| 394 | pub confirm: String, | |
| 395 | /// Where the request came in, for the audit log; g1t.sh when absent. | |
| 396 | #[serde(default)] | |
| 397 | pub surface: Option<crate::audit::Surface>, | |
| 398 | } | |
| 399 | ||
| 400 | /// What stands between a workspace and its deletion. Nothing does when | |
| 401 | /// both counts are zero and `billing` is null. | |
| 402 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | |
| 403 | pub struct WorkspaceDeletion { | |
| 404 | pub repositories: u32, | |
| 405 | pub projects: u32, | |
| 406 | /// Why billing cannot close the workspace yet, in words for its owner. | |
| 407 | pub billing: Option<String>, | |
| 408 | } | |
| 409 | ||
| 410 | impl WorkspaceDeletion { | |
| 411 | pub fn blocked(&self) -> bool { | |
| 412 | self.repositories > 0 || self.projects > 0 || self.billing.is_some() | |
| 413 | } | |
| 414 | ||
| 415 | /// Why the workspace cannot be deleted yet, as one sentence, or `None`. | |
| 416 | pub fn reason(&self, slug: &str) -> Option<String> { | |
| 417 | let plural = |n: u32, one: &str, many: &str| { | |
| 418 | format!("{n} {}", if n == 1 { one } else { many }) | |
| 419 | }; | |
| 420 | let mut held = Vec::new(); | |
| 421 | if self.repositories > 0 { | |
| 422 | held.push(plural(self.repositories, "repository", "repositories")); | |
| 423 | } | |
| 424 | if self.projects > 0 { | |
| 425 | held.push(plural(self.projects, "project", "projects")); | |
| 426 | } | |
| 427 | if !held.is_empty() { | |
| 428 | return Some(format!( | |
| 429 | "{slug} still holds {}. Transfer them to another workspace first.", | |
| 430 | held.join(" and ") | |
| 431 | )); | |
| 432 | } | |
| 433 | self.billing.clone() | |
| 434 | } | |
| 435 | } | |
| 436 | ||
| 437 | /// `transfer_repo_scopes`: a repository moved from `from` to `to`; the | |
| 438 | /// tokens of agents at work on it are kept pointing at it. For repos' | |
| 439 | /// `transfer`. Returns `bool`. | |
| 440 | #[derive(Debug, Serialize, Deserialize)] | |
| 441 | pub struct TransferRepoScopesArgs { | |
| 442 | pub from: crate::repos::RepoPath, | |
| 443 | pub to: crate::repos::RepoPath, | |
| 444 | } | |
| 445 | ||
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 446 | /// How long a workspace's old slug keeps redirecting to it, and stays |
| 447 | /// reserved for it, after a rename. | |
| 448 | pub const SLUG_HOLD_DAYS: u64 = 90; | |
| 449 | ||
| 450 | /// How long a workspace must wait between renames. | |
| 451 | pub const RENAME_COOLDOWN_HOURS: u64 = 24; | |
| 452 | ||
| 453 | // `resolve_slug` takes `SlugArgs` and returns `Option<String>`: the | |
| 454 | // workspace's current slug when `slug` is one it was renamed from within | |
| 455 | // the last `SLUG_HOLD_DAYS`, and null otherwise (including for a slug that | |
| 456 | // is in use). | |
| 457 | ||
| Workspace names and icons, and a component kit for every control | 458 | /// `set_workspace_avatar`: owners only. `image` is the file's bytes in |
| 459 | /// base64: PNG, JPEG, WebP or GIF, at most `MAX_AVATAR_BYTES`. Null removes | |
| 460 | /// the icon. Returns `Outcome<Workspace>`. | |
| 461 | #[derive(Debug, Serialize, Deserialize)] | |
| 462 | pub struct SetWorkspaceAvatarArgs { | |
| 463 | pub actor: User, | |
| 464 | pub slug: String, | |
| 465 | pub image: Option<String>, | |
| 466 | } | |
| 467 | ||
| 468 | /// `set_user_avatar`: a person's own avatar, as `SetWorkspaceAvatarArgs`. | |
| 469 | /// Returns `Outcome<Option<String>>`: the new avatar, or null once removed. | |
| 470 | #[derive(Debug, Serialize, Deserialize)] | |
| 471 | pub struct SetUserAvatarArgs { | |
| 472 | pub user: User, | |
| 473 | pub image: Option<String>, | |
| 474 | } | |
| 475 | ||
| 476 | /// The largest avatar that can be uploaded, in bytes. | |
| 477 | pub const MAX_AVATAR_BYTES: usize = 1024 * 1024; | |
| 478 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 479 | /// `list_workspace_tokens`: members only. Returns |
| 480 | /// `Outcome<Vec<AccessToken>>`. | |
| 481 | #[derive(Debug, Serialize, Deserialize)] | |
| 482 | pub struct WorkspaceTokensArgs { | |
| 483 | pub slug: String, | |
| 484 | pub viewer: crate::Viewer, | |
| 485 | } | |
| 486 | ||
| 487 | /// `create_workspace_token`: owners only. The token belongs to the | |
| 488 | /// workspace, acts as it, and keeps working when the member who made it | |
| 489 | /// leaves. Returns `Outcome<CreatedAccessToken>`. | |
| 490 | #[derive(Debug, Serialize, Deserialize)] | |
| 491 | pub struct CreateWorkspaceTokenArgs { | |
| 492 | pub actor: User, | |
| 493 | pub slug: String, | |
| 494 | pub name: String, | |
| Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step | 495 | /// Its scopes; null for full access. |
| 496 | #[serde(default)] | |
| 497 | pub scopes: Option<Vec<String>>, | |
| 498 | /// When set, the token stops working after this many seconds. It is | |
| 499 | /// listed with the workspace's tokens either way. Null: no expiry. | |
| 500 | #[serde(default)] | |
| 501 | pub ttl_seconds: Option<u64>, | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 502 | } |
| 503 | ||
| 504 | /// `remove_workspace_token`: owners only. Returns `Outcome<bool>`. | |
| 505 | #[derive(Debug, Serialize, Deserialize)] | |
| 506 | pub struct RemoveWorkspaceTokenArgs { | |
| 507 | pub actor: User, | |
| 508 | pub slug: String, | |
| 509 | pub id: String, | |
| 510 | } | |
| 511 | ||
| OAuth 2.1 sign-in for MCP clients and other applications | 512 | /// `oauth_authorize`: the signed-in person approved an application. The |
| 513 | /// caller has checked the client and that it may be redirected to | |
| 514 | /// `redirect_uri`. Returns `OAuthCode`. | |
| 515 | #[derive(Debug, Serialize, Deserialize)] | |
| 516 | #[serde(rename_all = "camelCase")] | |
| 517 | pub struct OAuthAuthorizeArgs { | |
| 518 | pub user: User, | |
| 519 | pub client_id: String, | |
| 520 | /// Shown wherever the application's access is listed. | |
| 521 | pub client_name: String, | |
| 522 | pub redirect_uri: String, | |
| 523 | /// PKCE challenge, method S256. | |
| 524 | pub code_challenge: String, | |
| Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step | 525 | /// What the person granted, as `resource:level`. Null: full access. |
| 526 | #[serde(default)] | |
| 527 | pub scopes: Option<Vec<String>>, | |
| OAuth 2.1 sign-in for MCP clients and other applications | 528 | } |
| 529 | ||
| 530 | #[derive(Debug, Serialize, Deserialize)] | |
| 531 | pub struct OAuthCode { | |
| 532 | pub code: String, | |
| 533 | } | |
| 534 | ||
| 535 | /// `oauth_exchange`: redeems an authorization code. | |
| 536 | /// Returns `Outcome<OAuthTokens>`. | |
| 537 | #[derive(Debug, Serialize, Deserialize)] | |
| 538 | #[serde(rename_all = "camelCase")] | |
| 539 | pub struct OAuthExchangeArgs { | |
| 540 | pub code: String, | |
| 541 | pub code_verifier: String, | |
| 542 | pub client_id: String, | |
| 543 | pub redirect_uri: String, | |
| 544 | } | |
| 545 | ||
| 546 | /// `oauth_refresh`: trades a refresh token for new tokens. | |
| 547 | /// Returns `Outcome<OAuthTokens>`. | |
| 548 | #[derive(Debug, Serialize, Deserialize)] | |
| 549 | #[serde(rename_all = "camelCase")] | |
| 550 | pub struct OAuthRefreshArgs { | |
| 551 | pub refresh_token: String, | |
| 552 | pub client_id: String, | |
| 553 | } | |
| 554 | ||
| 555 | #[derive(Debug, Serialize, Deserialize)] | |
| 556 | #[serde(rename_all = "camelCase")] | |
| 557 | pub struct OAuthTokens { | |
| 558 | pub access_token: String, | |
| 559 | /// Works once; using it returns the next one. | |
| 560 | pub refresh_token: String, | |
| 561 | /// Seconds until the access token stops working. | |
| 562 | pub expires_in: u64, | |
| Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step | 563 | /// The scopes granted, space-separated, or `*` for full access. |
| 564 | #[serde(default)] | |
| 565 | pub scope: Option<String>, | |
| OAuth 2.1 sign-in for MCP clients and other applications | 566 | } |
| 567 | ||
| 568 | /// An application a person has signed in to. Listed by `list_oauth_grants` | |
| 569 | /// and ended by `revoke_oauth_grant`. | |
| 570 | #[derive(Debug, Serialize, Deserialize)] | |
| 571 | #[serde(rename_all = "camelCase")] | |
| 572 | pub struct OAuthGrant { | |
| 573 | pub id: String, | |
| 574 | pub client_name: String, | |
| 575 | /// RFC 3339. | |
| 576 | pub created_at: String, | |
| 577 | /// RFC 3339. | |
| 578 | 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 step | 579 | /// What the person granted. Null: full access. |
| 580 | #[serde(default)] | |
| 581 | pub scopes: Option<Vec<String>>, | |
| 582 | /// Signed in before applications were given scopes: full access until | |
| 583 | /// someone narrows it. | |
| 584 | #[serde(default)] | |
| 585 | pub legacy: bool, | |
| 586 | } | |
| 587 | ||
| 588 | /// `update_oauth_grant`: changes what an application the person signed in | |
| 589 | /// to may do, at once and when it refreshes. Returns `Outcome<OAuthGrant>`. | |
| 590 | #[derive(Debug, Serialize, Deserialize)] | |
| 591 | pub struct UpdateOAuthGrantArgs { | |
| 592 | pub user: User, | |
| 593 | pub id: String, | |
| 594 | #[serde(default)] | |
| 595 | pub scopes: Option<Vec<String>>, | |
| OAuth 2.1 sign-in for MCP clients and other applications | 596 | } |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 597 | |
| 598 | ||
| 599 | /// 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 API | 600 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 601 | pub struct AgentScope { |
| 602 | pub repo: crate::repos::RepoPath, | |
| 603 | /// API and MCP operation names, such as `create_issue`. | |
| 604 | pub operations: Vec<String>, | |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 605 | /// Set on a run credential: the run it belongs to, and what it may do |
| 606 | /// with git. See [`crate::credentials`]. | |
| 607 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 608 | pub run: Option<crate::credentials::RunBinding>, | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 609 | } |
| 610 | ||
| 611 | /// `create_agent_token`: a token for a g1t agent working on someone's | |
| 612 | /// behalf. It acts as `g1t-agent`, a member of the repository's workspace, | |
| 613 | /// and only for the operations in `scope`. Returns `CreatedAccessToken`. | |
| 614 | #[derive(Debug, Serialize, Deserialize)] | |
| 615 | #[serde(rename_all = "camelCase")] | |
| 616 | pub struct CreateAgentTokenArgs { | |
| 617 | /// The person the agent works for; the token is recorded as theirs. | |
| 618 | pub on_behalf_of: User, | |
| 619 | pub scope: AgentScope, | |
| 620 | pub ttl_seconds: u64, | |
| 621 | } | |
| 622 | ||
| 623 | // `agent_scope` takes `TokenArgs` and returns `Option<AgentScope>`: what an | |
| 624 | // agent's token may do, or null for any other token. | |
| 625 | ||
| 626 | /// The id and name g1t's agents act under. | |
| 627 | pub const AGENT_ID: &str = "usr_g1t_agent"; | |
| 628 | pub const AGENT_NAME: &str = "g1t-agent"; | |
| Billing on Stripe's pages, month-end charges, warnings; sudo by workspace | 629 | |
| 630 | // --- Staff --------------------------------------------------------------- | |
| 631 | // | |
| 632 | // Staff-only methods, for sudo.g1t.sh. They take no viewer and check no | |
| 633 | // membership: only sudo calls them, over its service binding, after it has | |
| 634 | // verified a Cloudflare Access sign-in and its staff list. Nothing a | |
| 635 | // customer can reach should ever forward to them. | |
| 636 | ||
| 637 | /// `notify_owners`: emails a short notice, with one link, to each owner of | |
| 638 | /// a workspace with a confirmed address. Called by other services (billing | |
| 639 | /// warns owners near their usage limit), never on a person's behalf. | |
| 640 | /// Returns how many were sent. | |
| 641 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 642 | pub struct NotifyOwnersArgs { | |
| 643 | pub workspace: String, | |
| 644 | pub subject: String, | |
| 645 | /// One or two sentences: what happened and what it means. | |
| 646 | pub intro: String, | |
| 647 | /// The button's words, such as `Open billing`. | |
| 648 | pub action: String, | |
| 649 | /// Where the button goes; must be on g1t.sh. | |
| 650 | pub link: String, | |
| 651 | /// Small print: why they got it. | |
| 652 | pub footer: String, | |
| 653 | } | |
| 654 | ||
| 655 | /// `admin_workspaces`: every workspace, newest first, at most | |
| 656 | /// [`ADMIN_WORKSPACES_LIMIT`], optionally only those whose slug, name or | |
| 657 | /// an owner's username or email contains `query`. Returns | |
| 658 | /// `Vec<AdminWorkspace>`. Staff only. | |
| 659 | #[derive(Debug, Default, Serialize, Deserialize)] | |
| 660 | pub struct AdminWorkspacesArgs { | |
| 661 | #[serde(default)] | |
| 662 | pub query: Option<String>, | |
| 663 | } | |
| 664 | ||
| 665 | /// The most workspaces one `admin_workspaces` call returns. | |
| 666 | pub const ADMIN_WORKSPACES_LIMIT: usize = 500; | |
| 667 | ||
| 668 | /// An owner of a workspace, as staff see them. | |
| 669 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 670 | pub struct AdminOwner { | |
| 671 | pub username: String, | |
| 672 | pub email: Option<String>, | |
| 673 | } | |
| 674 | ||
| 675 | /// A workspace as staff see it: who owns it and how many belong to it. | |
| 676 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 677 | #[serde(rename_all = "camelCase")] | |
| 678 | pub struct AdminWorkspace { | |
| 679 | pub slug: String, | |
| 680 | pub name: String, | |
| 681 | /// RFC 3339. | |
| 682 | pub created_at: String, | |
| 683 | pub owners: Vec<AdminOwner>, | |
| 684 | pub member_count: u32, | |
| 685 | } | |
| 686 | ||
| 687 | /// `admin_workspace`: one workspace with every member, or null. Takes | |
| 688 | /// `SlugArgs`; returns `Option<AdminWorkspaceDetail>`. Staff only. | |
| 689 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 690 | #[serde(rename_all = "camelCase")] | |
| 691 | pub struct AdminWorkspaceDetail { | |
| 692 | pub slug: String, | |
| 693 | pub name: String, | |
| 694 | pub description: Option<String>, | |
| 695 | /// RFC 3339. | |
| 696 | pub created_at: String, | |
| 697 | /// Owners first, then by username. | |
| 698 | pub members: Vec<AdminMember>, | |
| 699 | } | |
| 700 | ||
| 701 | /// A member of a workspace, as staff see them. | |
| 702 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 703 | pub struct AdminMember { | |
| 704 | pub username: String, | |
| 705 | pub email: Option<String>, | |
| 706 | pub role: crate::Role, | |
| 707 | /// When they joined the workspace. RFC 3339. | |
| 708 | pub joined: String, | |
| 709 | } | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 710 | |
| 711 | // --- Profiles ------------------------------------------------------------ | |
| 712 | // | |
| 713 | // A person's public page at `g1t.sh/u/<username>`. Everything in a | |
| 714 | // `Profile` is shown to anyone, signed in or not; an email address never is. | |
| 715 | ||
| 716 | /// The most characters each profile field takes. | |
| 717 | pub const MAX_PROFILE_NAME: usize = 80; | |
| 718 | pub const MAX_PROFILE_BIO: usize = 160; | |
| 719 | pub const MAX_PROFILE_LOCATION: usize = 80; | |
| 720 | pub const MAX_PROFILE_WEBSITE: usize = 200; | |
| 721 | pub const MAX_PROFILE_PRONOUNS: usize = 40; | |
| 722 | ||
| 723 | /// What anyone may see about a person. | |
| 724 | #[derive(Clone, Debug, Default, Serialize, Deserialize)] | |
| 725 | #[serde(rename_all = "camelCase")] | |
| 726 | pub struct Profile { | |
| 727 | pub username: String, | |
| 728 | /// The name they go by, if they gave one. | |
| 729 | pub name: Option<String>, | |
| 730 | /// One or two lines about them, at most [`MAX_PROFILE_BIO`] characters. | |
| 731 | pub bio: Option<String>, | |
| 732 | pub location: Option<String>, | |
| 733 | /// An `https://` address. | |
| 734 | pub website: Option<String>, | |
| 735 | pub pronouns: Option<String>, | |
| 736 | /// The uploaded avatar's hash, served at `/avatars/<avatar>`. | |
| 737 | pub avatar: Option<String>, | |
| 738 | /// When the account was made. RFC 3339. | |
| 739 | pub created_at: String, | |
| 740 | } | |
| 741 | ||
| 742 | // `profile` takes `UsernameArgs` and returns `Option<Profile>`: null for | |
| 743 | // an account that does not exist. | |
| 744 | ||
| 745 | /// `update_profile`: a person changes their own profile. Every field is | |
| 746 | /// replaced; an empty one is cleared. Returns `Outcome<Profile>`. | |
| 747 | #[derive(Debug, Default, Serialize, Deserialize)] | |
| 748 | #[serde(rename_all = "camelCase")] | |
| 749 | pub struct UpdateProfileArgs { | |
| 750 | pub actor: User, | |
| 751 | #[serde(default)] | |
| 752 | pub name: String, | |
| 753 | #[serde(default)] | |
| 754 | pub bio: String, | |
| 755 | #[serde(default)] | |
| 756 | pub location: String, | |
| 757 | #[serde(default)] | |
| 758 | pub website: String, | |
| 759 | #[serde(default)] | |
| 760 | pub pronouns: String, | |
| 761 | } | |
| 762 | ||
| 763 | /// `profile_workspaces`: the workspaces shown on a person's profile, as | |
| 764 | /// `viewer` may see them. A membership is shown only when it is no secret | |
| 765 | /// from the viewer: a workspace the viewer belongs to as well, or one of | |
| 766 | /// `public`, the workspaces the caller found the person has made a public | |
| 767 | /// project in (whose page shows that already). Returns | |
| 768 | /// `Vec<ProfileWorkspace>`; empty for an account that does not exist. | |
| 769 | #[derive(Debug, Serialize, Deserialize)] | |
| 770 | pub struct ProfileWorkspacesArgs { | |
| 771 | pub username: String, | |
| 772 | pub viewer: crate::Viewer, | |
| 773 | #[serde(default)] | |
| 774 | pub public: Vec<String>, | |
| 775 | } | |
| 776 | ||
| 777 | /// A workspace on a person's profile. | |
| 778 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 779 | pub struct ProfileWorkspace { | |
| 780 | pub slug: String, | |
| 781 | pub name: String, | |
| 782 | pub avatar: Option<String>, | |
| 783 | } | |
| Search across all of g1t, Explore, and a command palette | 784 | |
| 785 | /// `directory`: every account or every workspace, as their public pages | |
| 786 | /// show them, a page at a time in name order. For services that index | |
| 787 | /// them, such as search; nothing private is in it. Returns | |
| 788 | /// `DirectoryPage`. | |
| 789 | #[derive(Debug, Default, Serialize, Deserialize)] | |
| 790 | pub struct DirectoryArgs { | |
| 791 | /// `user` or `workspace`. | |
| 792 | pub kind: String, | |
| 793 | /// Names after this one. | |
| 794 | #[serde(default)] | |
| 795 | pub after: Option<String>, | |
| 796 | pub limit: u32, | |
| 797 | } | |
| 798 | ||
| 799 | /// One account or workspace in the directory. | |
| 800 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 801 | #[serde(rename_all = "camelCase")] | |
| 802 | pub struct DirectoryEntry { | |
| 803 | /// The account's or workspace's id. | |
| 804 | pub id: String, | |
| 805 | /// A username or a workspace's slug. | |
| 806 | pub slug: String, | |
| 807 | /// A person's display name or a workspace's name. | |
| 808 | pub name: Option<String>, | |
| 809 | /// A person's bio or a workspace's description. | |
| 810 | pub bio: Option<String>, | |
| 811 | pub avatar: Option<String>, | |
| 812 | /// RFC 3339. | |
| 813 | pub created_at: String, | |
| 814 | } | |
| 815 | ||
| 816 | #[derive(Clone, Debug, Default, Serialize, Deserialize)] | |
| 817 | pub struct DirectoryPage { | |
| 818 | pub entries: Vec<DirectoryEntry>, | |
| 819 | /// Where the next page starts; null on the last. | |
| 820 | pub next: Option<String>, | |
| 821 | } | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 822 | |
| 823 | // --- Invites --------------------------------------------------------------- | |
| 824 | // | |
| 825 | // While registration is invite-only, every new account (with a password or | |
| 826 | // through GitHub) needs an invite code. Each person may have | |
| 827 | // `INVITES_PER_USER` invites out at a time; staff grant more to a person or | |
| 828 | // to a workspace, whose owners share them. Inviting an email with no | |
| 829 | // account into a workspace makes an invite bound to that address, which | |
| 830 | // registers and joins in one step. See services/identity/src/invites.rs. | |
| 831 | ||
| 832 | /// Whether anyone may make an account, or only someone with an invite. Set | |
| 833 | /// by identity's `REGISTRATION_MODE` var; anything but `open`, including | |
| 834 | /// leaving it unset, is `invite`, so a missing setting never opens sign-up. | |
| 835 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | |
| 836 | #[serde(rename_all = "snake_case")] | |
| 837 | pub enum RegistrationMode { | |
| 838 | #[default] | |
| 839 | Invite, | |
| 840 | Open, | |
| 841 | } | |
| 842 | ||
| 843 | impl RegistrationMode { | |
| 844 | pub fn parse(text: Option<&str>) -> RegistrationMode { | |
| 845 | match text.map(|text| text.trim().to_ascii_lowercase()).as_deref() { | |
| 846 | Some("open") => RegistrationMode::Open, | |
| 847 | _ => RegistrationMode::Invite, | |
| 848 | } | |
| 849 | } | |
| 850 | } | |
| 851 | ||
| 852 | /// How many invites a person may have out at once, unless identity's | |
| 853 | /// `INVITES_PER_USER` var says otherwise. | |
| 854 | pub const INVITES_PER_USER: u32 = 5; | |
| 855 | ||
| 856 | /// How long an invite works, unless identity's `INVITE_TTL_DAYS` var says | |
| 857 | /// otherwise. | |
| 858 | pub const INVITE_TTL_DAYS: u64 = 30; | |
| 859 | ||
| 860 | /// Where an invite stands. Only a pending invite can be used or revoked. | |
| 861 | /// An expired or revoked invite that was never used gives its inviter the | |
| 862 | /// invite back. | |
| 863 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 864 | #[serde(rename_all = "snake_case")] | |
| 865 | pub enum InviteStatus { | |
| 866 | Pending, | |
| 867 | Redeemed, | |
| 868 | Expired, | |
| 869 | Revoked, | |
| 870 | } | |
| 871 | ||
| 872 | /// What using an invite does. | |
| 873 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 874 | #[serde(rename_all = "snake_case")] | |
| 875 | pub enum InviteKind { | |
| 876 | /// Makes a new account, and joins `workspace` when one is set. | |
| 877 | Account, | |
| 878 | /// An existing account joins `workspace`. Never makes an account. | |
| 879 | Workspace, | |
| 880 | } | |
| 881 | ||
| 882 | /// Whose allowance an invite uses. | |
| 883 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 884 | #[serde(rename_all = "snake_case")] | |
| 885 | pub enum InviteCharge { | |
| 886 | /// Its inviter's own. | |
| 887 | User, | |
| 888 | /// The workspace's, granted by staff and shared by its owners. | |
| 889 | Workspace, | |
| 890 | /// Nobody's: staff minted it, or it invites an existing account. | |
| 891 | None, | |
| 892 | } | |
| 893 | ||
| 894 | /// One invite, as the person who made it sees it. | |
| 895 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 896 | #[serde(rename_all = "camelCase")] | |
| 897 | pub struct Invite { | |
| 898 | pub id: String, | |
| 899 | /// The code, such as `g1t-k7m2-q9xd-…`: returned once when the invite | |
| 900 | /// is made, and afterwards to whoever made it while it is pending. | |
| 901 | /// Null otherwise. | |
| 902 | pub code: Option<String>, | |
| 903 | /// The code's first group, such as `g1t-k7m2`, to recognise it by. | |
| 904 | pub hint: String, | |
| 905 | /// Only an account with this address can use it. Null: anyone with | |
| 906 | /// the code. | |
| 907 | pub email: Option<String>, | |
| 908 | pub kind: InviteKind, | |
| 909 | /// The workspace it joins, by slug. | |
| 910 | pub workspace: Option<String>, | |
| 911 | pub status: InviteStatus, | |
| 912 | pub charged_to: InviteCharge, | |
| 913 | /// Who made it, by username. Null when g1t staff did. | |
| 914 | pub invited_by: Option<String>, | |
| 915 | /// The account that used it, by username. | |
| 916 | pub redeemed_by: Option<String>, | |
| 917 | /// RFC 3339. | |
| 918 | pub created_at: String, | |
| 919 | /// RFC 3339. | |
| 920 | pub expires_at: String, | |
| 921 | /// RFC 3339. | |
| 922 | pub redeemed_at: Option<String>, | |
| 923 | /// RFC 3339. | |
| 924 | pub revoked_at: Option<String>, | |
| 925 | /// The staff member who minted it. Only in staff views. | |
| 926 | #[serde(default, skip_serializing_if = "Option::is_none")] | |
| 927 | pub staff: Option<String>, | |
| 928 | } | |
| 929 | ||
| 930 | /// How many invites someone may have out, and how many they have. | |
| 931 | #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] | |
| 932 | pub struct Allowance { | |
| 933 | /// Null: no limit. | |
| 934 | pub limit: Option<u32>, | |
| 935 | /// Pending and used invites; revoked and expired ones are not counted. | |
| 936 | pub used: u32, | |
| 937 | /// Null: no limit. | |
| 938 | pub remaining: Option<u32>, | |
| 939 | } | |
| 940 | ||
| 941 | impl Allowance { | |
| 942 | pub fn new(limit: Option<u32>, used: u32) -> Allowance { | |
| 943 | Allowance { | |
| 944 | limit, | |
| 945 | used, | |
| 946 | remaining: limit.map(|limit| limit.saturating_sub(used)), | |
| 947 | } | |
| 948 | } | |
| 949 | ||
| 950 | pub fn exhausted(&self) -> bool { | |
| 951 | self.remaining == Some(0) | |
| 952 | } | |
| 953 | } | |
| 954 | ||
| 955 | /// A workspace's shared invites, for one of its owners. | |
| 956 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 957 | pub struct WorkspaceAllowance { | |
| 958 | pub slug: String, | |
| 959 | pub allowance: Allowance, | |
| 960 | } | |
| 961 | ||
| 962 | /// `list_invites` (takes `UserArgs`): a person's invites, newest first, | |
| 963 | /// and what they have left. Returns `InvitesOverview`. | |
| 964 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 965 | pub struct InvitesOverview { | |
| 966 | pub mode: RegistrationMode, | |
| 967 | pub allowance: Allowance, | |
| 968 | /// Workspaces the person owns that staff granted invites to. | |
| 969 | pub workspaces: Vec<WorkspaceAllowance>, | |
| 970 | pub invites: Vec<Invite>, | |
| 971 | } | |
| 972 | ||
| 973 | /// `create_invite`: a person makes an invite, optionally for one email | |
| 974 | /// address. People only; never an agent or a workspace's token, and not | |
| 975 | /// before their email is confirmed. Uses one of the person's invites, or, | |
| 976 | /// with `workspace`, one of the invites staff granted that workspace (its | |
| 977 | /// owners only). Emails the address when one is given. Returns | |
| 978 | /// `Outcome<Invite>`, with the code. | |
| 979 | /// | |
| 980 | /// `revoke_invite` (takes `RemoveArgs`): its maker revokes a pending | |
| 981 | /// invite; a workspace's owners may revoke one made for the workspace. | |
| 982 | /// The invite comes back to whoever it was charged to. Returns | |
| 983 | /// `Outcome<Invite>`. | |
| 984 | #[derive(Debug, Serialize, Deserialize)] | |
| 985 | pub struct CreateInviteArgs { | |
| 986 | pub user: User, | |
| 987 | #[serde(default)] | |
| 988 | pub email: Option<String>, | |
| 989 | /// Use this workspace's granted invites, by slug. | |
| 990 | #[serde(default)] | |
| 991 | pub workspace: Option<String>, | |
| 992 | /// Where the request came in, for the audit log; g1t.sh when absent. | |
| 993 | #[serde(default)] | |
| 994 | pub surface: Option<crate::audit::Surface>, | |
| 995 | } | |
| 996 | ||
| 997 | /// `check_invite`: what an invite code is for, before using it. Returns | |
| 998 | /// `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 quotas | 999 | /// expired gets the same answer, so codes cannot be probed. With |
| 1000 | /// `any_status`, a real code that can no longer be used is described | |
| 1001 | /// instead (its `status` says why), so the page can say whom to ask for a | |
| 1002 | /// 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 look | 1003 | #[derive(Debug, Serialize, Deserialize)] |
| 1004 | pub struct InviteCodeArgs { | |
| 1005 | pub code: String, | |
| 1006 | /// Who is asking, such as the visitor's IP address, for rate limits. | |
| 1007 | #[serde(default)] | |
| 1008 | pub client: Option<String>, | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1009 | /// Who is looking, if signed in: sets `InvitePreview::for_viewer`. |
| 1010 | #[serde(default)] | |
| 1011 | pub viewer: Option<User>, | |
| 1012 | #[serde(default)] | |
| 1013 | pub any_status: bool, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1014 | } |
| 1015 | ||
| 1016 | /// Someone shown on an invite. | |
| 1017 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 1018 | pub struct InviteFrom { | |
| 1019 | pub username: String, | |
| 1020 | pub name: Option<String>, | |
| 1021 | pub avatar: Option<String>, | |
| 1022 | } | |
| 1023 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1024 | /// A repository an invite code was sent with: using the code accepts the |
| 1025 | /// invitation to collaborate on it. | |
| 1026 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 1027 | pub struct InviteRepository { | |
| 1028 | /// `workspace/repo`. | |
| 1029 | pub name: String, | |
| 1030 | /// The role it gives, such as `write`. | |
| 1031 | pub role: String, | |
| 1032 | } | |
| 1033 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1034 | /// What a valid invite code is for. |
| 1035 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 1036 | #[serde(rename_all = "camelCase")] | |
| 1037 | pub struct InvitePreview { | |
| 1038 | pub kind: InviteKind, | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1039 | /// Pending, unless `any_status` asked about a code that is spent. |
| 1040 | pub status: InviteStatus, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1041 | /// Null when g1t staff sent it. |
| 1042 | pub invited_by: Option<InviteFrom>, | |
| 1043 | pub workspace: Option<ProfileWorkspace>, | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1044 | /// The repository it accepts an invitation to, if it was sent with one. |
| 1045 | pub repository: Option<InviteRepository>, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1046 | /// The address it is for, partly hidden, such as `a•••@example.com`. |
| 1047 | pub email: Option<String>, | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1048 | /// The address in full, while it is pending: whoever holds the code |
| 1049 | /// was sent it there. Fills in and locks the sign-up form. | |
| 1050 | pub address: Option<String>, | |
| 1051 | /// Whether the address it is for has a g1t account already, so the | |
| 1052 | /// page asks them to sign in rather than sign up. | |
| 1053 | pub has_account: bool, | |
| 1054 | /// With a viewer: whether the invite is theirs (it is for one of their | |
| 1055 | /// confirmed addresses, or they used it). Null without a viewer or, | |
| 1056 | /// for a pending invite, when it is for anyone with the code. | |
| 1057 | pub for_viewer: Option<bool>, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1058 | /// RFC 3339. |
| 1059 | pub expires_at: String, | |
| 1060 | } | |
| 1061 | ||
| 1062 | /// `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 quotas | 1063 | /// their confirmed address, and joins the workspace, or an invite sent with |
| 1064 | /// a repository invitation, and accepts it. Returns `Outcome<String>`: the | |
| 1065 | /// workspace's slug, or `workspace/repo`. | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1066 | #[derive(Debug, Serialize, Deserialize)] |
| 1067 | pub struct AcceptInviteArgs { | |
| 1068 | pub user: User, | |
| 1069 | pub code: String, | |
| 1070 | } | |
| 1071 | ||
| 1072 | /// `invite_member`: an owner invites an email address into a workspace. | |
| 1073 | /// It always makes an invite bound to that address and emails it, so the | |
| 1074 | /// answer never says whether the address has an account. Without one, the | |
| 1075 | /// invite registers and joins in one step, and uses one of the workspace's | |
| 1076 | /// granted invites or else one of the owner's own. With one, it costs | |
| 1077 | /// nothing. Returns `Outcome<Invite>`, with the code. | |
| 1078 | #[derive(Debug, Serialize, Deserialize)] | |
| 1079 | pub struct InviteMemberArgs { | |
| 1080 | pub actor: User, | |
| 1081 | pub slug: String, | |
| 1082 | pub email: String, | |
| 1083 | /// Where the request came in, for the audit log; g1t.sh when absent. | |
| 1084 | #[serde(default)] | |
| 1085 | pub surface: Option<crate::audit::Surface>, | |
| 1086 | } | |
| 1087 | ||
| 1088 | /// `workspace_invites` (takes `ListMembersArgs`): a workspace's invites, | |
| 1089 | /// newest first. Owners only. Returns `Outcome<Vec<Invite>>`. | |
| 1090 | /// | |
| 1091 | /// `revoke_workspace_invite`: owners only. Returns `Outcome<Invite>`. | |
| 1092 | #[derive(Debug, Serialize, Deserialize)] | |
| 1093 | pub struct WorkspaceInviteArgs { | |
| 1094 | pub actor: User, | |
| 1095 | pub slug: String, | |
| 1096 | pub id: String, | |
| 1097 | } | |
| 1098 | ||
| 1099 | /// `request_access`: someone without an invite asks for one. Kept on the | |
| 1100 | /// waitlist, one entry per address. Answers the same way whether or not | |
| 1101 | /// the address is already on it. Returns `Outcome<bool>`. | |
| 1102 | #[derive(Debug, Default, Serialize, Deserialize)] | |
| 1103 | pub struct RequestAccessArgs { | |
| 1104 | pub email: String, | |
| 1105 | /// What they will build, if they said. | |
| 1106 | #[serde(default)] | |
| 1107 | pub about: String, | |
| 1108 | /// Who is asking, such as the visitor's IP address, for rate limits. | |
| 1109 | #[serde(default)] | |
| 1110 | pub client: Option<String>, | |
| 1111 | } | |
| 1112 | ||
| 1113 | /// The most characters `RequestAccessArgs::about` keeps. | |
| 1114 | pub const MAX_WAITLIST_ABOUT: usize = 1000; | |
| 1115 | ||
| 1116 | // `registration` takes `{}` and returns `RegistrationMode`. | |
| 1117 | ||
| 1118 | // --- Invites, staff only --- | |
| 1119 | ||
| 1120 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 1121 | #[serde(rename_all = "snake_case")] | |
| 1122 | pub enum WaitlistStatus { | |
| 1123 | Waiting, | |
| 1124 | Invited, | |
| 1125 | Dismissed, | |
| 1126 | } | |
| 1127 | ||
| 1128 | impl WaitlistStatus { | |
| 1129 | pub fn as_str(self) -> &'static str { | |
| 1130 | match self { | |
| 1131 | WaitlistStatus::Waiting => "waiting", | |
| 1132 | WaitlistStatus::Invited => "invited", | |
| 1133 | WaitlistStatus::Dismissed => "dismissed", | |
| 1134 | } | |
| 1135 | } | |
| 1136 | } | |
| 1137 | ||
| 1138 | /// Someone who asked for access. | |
| 1139 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 1140 | #[serde(rename_all = "camelCase")] | |
| 1141 | pub struct WaitlistEntry { | |
| 1142 | pub id: String, | |
| 1143 | pub email: String, | |
| 1144 | pub about: Option<String>, | |
| 1145 | pub status: WaitlistStatus, | |
| 1146 | pub invite_id: Option<String>, | |
| 1147 | pub decided_by: Option<String>, | |
| 1148 | /// RFC 3339. | |
| 1149 | pub decided_at: Option<String>, | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1150 | /// What staff wrote when approving; it went in the invite email. |
| 1151 | #[serde(default)] | |
| 1152 | pub note: Option<String>, | |
| 1153 | /// The account made with the invite, once it was used. | |
| 1154 | #[serde(default)] | |
| 1155 | pub joined_as: Option<String>, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1156 | /// When they first asked. RFC 3339. |
| 1157 | pub created_at: String, | |
| 1158 | /// When they last asked. RFC 3339. | |
| 1159 | pub updated_at: String, | |
| 1160 | } | |
| 1161 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1162 | /// `admin_waitlist`: the waitlist, newest first, at most |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1163 | /// [`ADMIN_INVITES_LIMIT`]. Returns `Vec<WaitlistEntry>`. |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1164 | /// |
| 1165 | /// `admin_waitlist_pending` takes `{}` and returns the number of requests | |
| 1166 | /// still waiting, for sudo's navigation. | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1167 | #[derive(Debug, Default, Serialize, Deserialize)] |
| 1168 | pub struct AdminWaitlistArgs { | |
| 1169 | /// Part of an email address or of what they said. | |
| 1170 | #[serde(default)] | |
| 1171 | pub query: Option<String>, | |
| 1172 | /// Null: every status. | |
| 1173 | #[serde(default)] | |
| 1174 | pub status: Option<WaitlistStatus>, | |
| 1175 | } | |
| 1176 | ||
| 1177 | /// The most rows one staff listing of invites or the waitlist returns. | |
| 1178 | pub const ADMIN_INVITES_LIMIT: usize = 500; | |
| 1179 | ||
| 1180 | /// `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 quotas | 1181 | /// address, charged to nobody, and emails it, with `note` if given; |
| 1182 | /// dismissing only marks the entry. Returns `Outcome<WaitlistEntry>`. | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1183 | #[derive(Debug, Serialize, Deserialize)] |
| 1184 | pub struct AdminDecideWaitlistArgs { | |
| 1185 | pub id: String, | |
| 1186 | pub approve: bool, | |
| 1187 | /// The staff member, by email. | |
| 1188 | pub staff: String, | |
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1189 | /// A line for the invite email, up to [`MAX_WAITLIST_NOTE`] characters. |
| 1190 | #[serde(default)] | |
| 1191 | pub note: Option<String>, | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1192 | } |
| 1193 | ||
| status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas | 1194 | /// The most characters an approval's note keeps. |
| 1195 | pub const MAX_WAITLIST_NOTE: usize = 500; | |
| 1196 | ||
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 1197 | /// `admin_invites`: every invite, newest first, at most |
| 1198 | /// [`ADMIN_INVITES_LIMIT`], optionally only those whose code starts with | |
| 1199 | /// `query`, or whose email, inviter or redeemer contains it. Returns | |
| 1200 | /// `Vec<Invite>`. | |
| 1201 | #[derive(Debug, Default, Serialize, Deserialize)] | |
| 1202 | pub struct AdminInvitesArgs { | |
| 1203 | #[serde(default)] | |
| 1204 | pub query: Option<String>, | |
| 1205 | } | |
| 1206 | ||
| 1207 | /// `admin_revoke_invite`: revokes any pending invite. Returns | |
| 1208 | /// `Outcome<Invite>`. | |
| 1209 | #[derive(Debug, Serialize, Deserialize)] | |
| 1210 | pub struct AdminRevokeInviteArgs { | |
| 1211 | pub id: String, | |
| 1212 | pub staff: String, | |
| 1213 | } | |
| 1214 | ||
| 1215 | /// `admin_mint_invite`: staff make an invite that uses nobody's | |
| 1216 | /// allowance, optionally bound to (and emailed to) an address. Returns | |
| 1217 | /// `Outcome<Invite>`, with the code. | |
| 1218 | #[derive(Debug, Serialize, Deserialize)] | |
| 1219 | pub struct AdminMintInviteArgs { | |
| 1220 | #[serde(default)] | |
| 1221 | pub email: Option<String>, | |
| 1222 | pub staff: String, | |
| 1223 | } | |
| 1224 | ||
| 1225 | /// Who staff grant invites to. | |
| 1226 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | |
| 1227 | #[serde(rename_all = "snake_case")] | |
| 1228 | pub enum GrantTarget { | |
| 1229 | User, | |
| 1230 | Workspace, | |
| 1231 | } | |
| 1232 | ||
| 1233 | impl GrantTarget { | |
| 1234 | pub fn as_str(self) -> &'static str { | |
| 1235 | match self { | |
| 1236 | GrantTarget::User => "user", | |
| 1237 | GrantTarget::Workspace => "workspace", | |
| 1238 | } | |
| 1239 | } | |
| 1240 | } | |
| 1241 | ||
| 1242 | /// `admin_grant_invites`: gives a person (by username) or a workspace (by | |
| 1243 | /// slug) `amount` more invites; a negative amount takes some back. Returns | |
| 1244 | /// `Outcome<Allowance>`: theirs afterwards. | |
| 1245 | #[derive(Debug, Serialize, Deserialize)] | |
| 1246 | pub struct AdminGrantInvitesArgs { | |
| 1247 | pub target: GrantTarget, | |
| 1248 | pub name: String, | |
| 1249 | pub amount: i32, | |
| 1250 | #[serde(default)] | |
| 1251 | pub note: String, | |
| 1252 | pub staff: String, | |
| 1253 | } | |
| 1254 | ||
| 1255 | /// The most invites one grant gives or takes back. | |
| 1256 | pub const MAX_INVITE_GRANT: i32 = 1000; | |
| 1257 | ||
| 1258 | /// Invites staff granted. | |
| 1259 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 1260 | #[serde(rename_all = "camelCase")] | |
| 1261 | pub struct InviteGrant { | |
| 1262 | pub amount: i32, | |
| 1263 | pub note: Option<String>, | |
| 1264 | pub granted_by: String, | |
| 1265 | /// RFC 3339. | |
| 1266 | pub created_at: String, | |
| 1267 | } | |
| 1268 | ||
| 1269 | /// Someone a person invited, and whom they invited in turn. | |
| 1270 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 1271 | #[serde(rename_all = "camelCase")] | |
| 1272 | pub struct InviteTreeNode { | |
| 1273 | pub username: String, | |
| 1274 | /// When they used the invite. RFC 3339. | |
| 1275 | pub joined_at: String, | |
| 1276 | pub invited: Vec<InviteTreeNode>, | |
| 1277 | } | |
| 1278 | ||
| 1279 | /// `admin_invite_tree` (takes `UsernameArgs`): where a person came from | |
| 1280 | /// and whom they brought, for tracing abuse. Returns `Option<InviteTree>`. | |
| 1281 | /// | |
| 1282 | /// `admin_workspace_invites` (takes `SlugArgs`): a workspace's granted | |
| 1283 | /// invites, grants and invites. Returns `Option<InviteTree>` with | |
| 1284 | /// `username` the slug and no `invited_by`. | |
| 1285 | #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | |
| 1286 | #[serde(rename_all = "camelCase")] | |
| 1287 | pub struct InviteTree { | |
| 1288 | pub username: String, | |
| 1289 | /// Who invited them, then who invited that person, and so on. Empty | |
| 1290 | /// for an account made without an invite. | |
| 1291 | pub invited_by: Vec<String>, | |
| 1292 | /// The staff member who minted their invite, when staff did. | |
| 1293 | pub staff: Option<String>, | |
| 1294 | pub allowance: Allowance, | |
| 1295 | pub grants: Vec<InviteGrant>, | |
| 1296 | /// Their invites, newest first. | |
| 1297 | pub invites: Vec<Invite>, | |
| 1298 | /// Whom they invited, three levels down. | |
| 1299 | pub invited: Vec<InviteTreeNode>, | |
| 1300 | } | |
| 1301 | ||
| 1302 | #[cfg(test)] | |
| 1303 | mod deletion_tests { | |
| 1304 | use super::WorkspaceDeletion; | |
| 1305 | ||
| 1306 | #[test] | |
| 1307 | fn says_what_is_left_to_move() { | |
| 1308 | let clear = WorkspaceDeletion::default(); | |
| 1309 | assert!(!clear.blocked()); | |
| 1310 | assert_eq!(clear.reason("acme"), None); | |
| 1311 | let held = WorkspaceDeletion { | |
| 1312 | repositories: 2, | |
| 1313 | projects: 1, | |
| 1314 | billing: Some("Pay first.".into()), | |
| 1315 | }; | |
| 1316 | assert!(held.blocked()); | |
| 1317 | assert_eq!( | |
| 1318 | held.reason("acme").as_deref(), | |
| 1319 | Some("acme still holds 2 repositories and 1 project. Transfer them to another workspace first.") | |
| 1320 | ); | |
| 1321 | let owing = WorkspaceDeletion { | |
| 1322 | billing: Some("Pay first.".into()), | |
| 1323 | ..WorkspaceDeletion::default() | |
| 1324 | }; | |
| 1325 | assert_eq!(owing.reason("acme").as_deref(), Some("Pay first.")); | |
| 1326 | } | |
| 1327 | } |