Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
1,869 linesCodeBlameRaw
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
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,
16 /// RFC 3339.
17 pub created_at: String,
18 /// When it was last used to sign in over SSH, RFC 3339, to within 5
19 /// minutes; null when it never was.
20 #[serde(default)]
21 pub last_used_at: Option<String>,
22}
23
24#[derive(Clone, Debug, Default, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct AccessToken {
27 pub id: String,
28 pub name: String,
29 /// RFC 3339.
30 pub created_at: String,
31 /// RFC 3339, to within a few minutes. Null until it is first used.
32 pub last_used_at: Option<String>,
33 /// For a workspace's token, the username of the member who made it.
34 /// Null once that account is gone, and on personal tokens.
35 pub created_by: Option<String>,
36 /// Its scopes, as `resource:level`, the highest of each resource.
37 /// Null: full access (an application's or an agent's credential).
38 #[serde(default)]
39 pub scopes: Option<Vec<String>>,
40 /// Made before tokens had scopes: full access until someone narrows it.
41 #[serde(default)]
42 pub legacy: bool,
43 /// RFC 3339. Null: it does not expire.
44 #[serde(default)]
45 pub expires_at: Option<String>,
46 /// Its scopes as permissions: each resource it may use, by name, at
47 /// the highest level, such as `{"issues": "write"}`. Every resource at
48 /// its highest when `scopes` is null.
49 #[serde(default)]
50 pub permissions: std::collections::BTreeMap<String, String>,
51 /// What it is for, as its owner wrote it.
52 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub description: Option<String>,
54 /// A personal token's reach: the workspace it is made for, by slug;
55 /// null for every workspace its owner belongs to (or, with
56 /// `repository_selection` public, none). Null on a workspace's own
57 /// token, which reaches its workspace.
58 #[serde(default)]
59 pub workspace: Option<String>,
60 /// Which repositories of that workspace it reaches.
61 #[serde(default)]
62 pub repository_selection: crate::scopes::RepositorySelection,
63 /// With `selected`: the repositories, as `owner/name`, that the viewer
64 /// can see.
65 #[serde(default)]
66 pub repositories: Vec<String>,
67 /// Whether a token made for a workspace that approves tokens may be
68 /// used there yet.
69 #[serde(default)]
70 pub status: crate::tokens::TokenStatus,
71 /// Why an owner denied or revoked it.
72 #[serde(default, skip_serializing_if = "Option::is_none")]
73 pub review_reason: Option<String>,
74 /// Whether it is a workspace's own token, acting as the workspace.
75 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
76 pub workspace_owned: bool,
77 /// A workspace's own token with Repositories: admin, which acts as an
78 /// admin of the workspace's repositories rather than with Write.
79 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
80 pub admin: bool,
81 /// A person's token its owner let use the website (g1t.sh) as them,
82 /// with `Authorization: Bearer`. See [`crate::scopes::TokenAccess::website`].
83 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
84 pub website: bool,
85}
86
87/// `sign_in`: verifies a username, or any confirmed email address of the
88/// account, and its password, for website sign-in. Wrong passwords are
89/// counted against the account and `client`, and past a limit nothing is
90/// checked for a while (see identity's `throttle.rs`).
91/// Returns `Outcome<SignedIn>`.
92#[derive(Debug, Serialize, Deserialize)]
93pub struct SignInArgs {
94 pub username: String,
95 pub password: String,
96 /// Who is asking, such as the visitor's IP address, for rate limits.
97 #[serde(default)]
98 pub client: Option<String>,
99}
100
101#[derive(Debug, Serialize, Deserialize)]
102#[serde(rename_all = "camelCase")]
103pub struct SignedIn {
104 pub user: User,
105 /// Empty while `two_factor_challenge` is set: no session is made until
106 /// the code is given.
107 pub session_token: String,
108 /// Set when the account has two-factor authentication on: the token to
109 /// pass to `two_factor_sign_in` with a code. Valid for
110 /// `accounts::TWO_FACTOR_CHALLENGE_SECONDS`.
111 #[serde(default, skip_serializing_if = "Option::is_none")]
112 pub two_factor_challenge: Option<String>,
113}
114
115/// `sign_out` and `user_for_session`.
116#[derive(Debug, Serialize, Deserialize)]
117#[serde(rename_all = "camelCase")]
118pub struct SessionArgs {
119 pub session_token: String,
120}
121
122/// `user_for_git_credentials`: the account password or an access token.
123#[derive(Debug, Serialize, Deserialize)]
124pub struct GitCredentialsArgs {
125 pub username: String,
126 pub secret: String,
127}
128
129/// `user_for_access_token`.
130#[derive(Debug, Serialize, Deserialize)]
131pub struct TokenArgs {
132 pub token: String,
133}
134
135/// `user_for_ssh_key`, and `principal_for_ssh_key` (see [`crate::deploy_keys`]).
136#[derive(Debug, Serialize, Deserialize)]
137pub struct FingerprintArgs {
138 pub fingerprint: String,
139}
140
141/// `user_by_username`.
142#[derive(Debug, Serialize, Deserialize)]
143pub struct UsernameArgs {
144 pub username: String,
145}
146
147/// `user_by_id`: a person as they are now, with their workspaces and roles,
148/// for a service acting later on what they asked (auto-merge), which must
149/// hold them to what they may do then. For services only. Returns
150/// `Viewer`: none for a deleted or unknown account.
151#[derive(Debug, Serialize, Deserialize)]
152pub struct UserIdArgs {
153 pub id: String,
154}
155
156/// `usernames`: the names behind account and workspace ids, as events and
157/// other records store them. Returns a map from id to name; ids it does
158/// not know are left out. Also `accounts`: the accounts behind user ids,
159/// each with its username and avatar (`HashMap<String, accounts::EmailOwner>`).
160#[derive(Debug, Serialize, Deserialize)]
161pub struct UsernamesArgs {
162 pub ids: Vec<String>,
163}
164
165/// `display_usernames`: how each of these people (by lowercased username,
166/// at most 200) wrote their username, for showing it beside the key.
167/// Returns a map from the lowercased username to its chosen case; people
168/// who chose none, and names nobody has, are left out.
169#[derive(Debug, Default, Serialize, Deserialize)]
170pub struct DisplayUsernamesArgs {
171 pub usernames: Vec<String>,
172}
173
174/// `list_ssh_keys` and `list_access_tokens`.
175#[derive(Debug, Serialize, Deserialize)]
176pub struct UserArgs {
177 pub user: User,
178}
179
180/// `ssh_key_owners`: services only. The account (user id) that registered
181/// each key, by fingerprint (`SHA256:…`, as `ssh-keygen -lf` prints it),
182/// for verifying commits signed with SSH keys. Returns a map of the
183/// fingerprints found to user ids.
184#[derive(Debug, Serialize, Deserialize)]
185pub struct SshKeyOwnersArgs {
186 pub fingerprints: Vec<String>,
187}
188
189/// `add_ssh_key`: `public_key` is one line in OpenSSH format.
190/// Returns `Outcome<SshKey>`.
191#[derive(Debug, Serialize, Deserialize)]
192#[serde(rename_all = "camelCase")]
193pub struct AddSshKeyArgs {
194 pub user: User,
195 pub title: String,
196 pub public_key: String,
197}
198
199/// `remove_ssh_key` and `remove_access_token`.
200#[derive(Debug, Serialize, Deserialize)]
201pub struct RemoveArgs {
202 pub user: User,
203 pub id: String,
204}
205
206/// `create_access_token`: a token that acts as `user`. For a workspace
207/// acting through a token of its own, the new token belongs to that
208/// workspace too.
209#[derive(Debug, Serialize, Deserialize)]
210#[serde(rename_all = "camelCase")]
211pub struct CreateAccessTokenArgs {
212 pub user: User,
213 pub name: String,
214 /// When set, the token stops working after this many seconds and is
215 /// left out of the user's token list, unless `listed`. Used for hosted
216 /// attempts.
217 #[serde(default)]
218 pub ttl_seconds: Option<u64>,
219 /// Its scopes, as `resource:level`; unknown names are left out. Null:
220 /// full access.
221 #[serde(default)]
222 pub scopes: Option<Vec<String>>,
223 /// Listed with the person's tokens although it expires: one they made
224 /// themselves, with an expiry.
225 #[serde(default)]
226 pub listed: bool,
227 /// The one repository it reaches, as `owner/name`: every other is
228 /// refused, whatever its owner could reach. Used for a session g1t
229 /// starts on someone's Anthropic account (`start_agent_session`).
230 #[serde(default, skip_serializing_if = "Option::is_none")]
231 pub repo: Option<String>,
232}
233
234/// `create_job_token`: a workflow job's `G1T_TOKEN`. It acts as the
235/// repository's workspace, reaches that repository only, holds `scopes`
236/// (from the job's `permissions`), and is never listed. The actions service
237/// revokes it when the job ends (`revoke_job_tokens`); `ttl_seconds` is a
238/// backstop. Returns `CreatedAccessToken`.
239#[derive(Debug, Serialize, Deserialize)]
240#[serde(rename_all = "camelCase")]
241pub struct CreateJobTokenArgs {
242 /// The workspace the repository belongs to, as its own principal.
243 pub workspace: User,
244 pub repo: crate::repos::RepoPath,
245 pub run_id: String,
246 pub job_id: String,
247 /// What the token is listed as in logs: `G1T_TOKEN for acme/web run 4`.
248 pub name: String,
249 pub ttl_seconds: u64,
250 /// As `resource:level`; unknown names are left out.
251 pub scopes: Vec<String>,
252 /// Whether it may open and approve pull requests (`JobToken::pull_requests`).
253 #[serde(default)]
254 pub pull_requests: bool,
255}
256
257/// `revoke_job_tokens`: ends a workflow job's tokens at once, when the job
258/// finishes or is cancelled. Only job tokens are touched. Returns `bool`.
259#[derive(Debug, Default, Serialize, Deserialize)]
260#[serde(rename_all = "camelCase")]
261pub struct RevokeJobTokensArgs {
262 pub job_id: String,
263}
264
265/// `create_ask_token`: the credential Ask g1t reads g1t with while it
266/// answers one question, through the MCP server, as the person asking.
267///
268/// It is that person's own token, so every read is checked exactly as
269/// theirs would be, cut down three ways: it holds the read scopes only
270/// ([`ask_token_scopes`]), so every change is refused whatever the person's
271/// role; it is made for `workspace` alone (its repositories, and public
272/// ones); and it expires in [`ASK_TOKEN_TTL_SECONDS`]. It is never listed,
273/// never shown to the model or the browser, and the integrations service
274/// revokes it when the answer ends (`revoke_ask_token`). A workspace's
275/// rules for personal access tokens do not apply to it: g1t makes it, for
276/// a feature the workspace's owner turned on, and nobody ever holds it.
277///
278/// Only the integrations service calls it, over its service binding.
279/// Returns `Outcome<AskToken>`: refused for anyone but a person who belongs
280/// to the workspace.
281#[derive(Debug, Serialize, Deserialize)]
282#[serde(rename_all = "camelCase")]
283pub struct CreateAskTokenArgs {
284 pub actor: User,
285 pub workspace: String,
286}
287
288/// What `create_ask_token` returns. The plaintext token is returned once
289/// and never stored.
290#[derive(Debug, Serialize, Deserialize)]
291#[serde(rename_all = "camelCase")]
292pub struct AskToken {
293 pub token: String,
294 /// Its id, to revoke it with.
295 pub id: String,
296}
297
298/// `revoke_ask_token`: ends an Ask credential at once. Only Ask's tokens
299/// are touched. Returns `bool`.
300#[derive(Debug, Default, Serialize, Deserialize)]
301#[serde(rename_all = "camelCase")]
302pub struct RevokeAskTokenArgs {
303 pub id: String,
304}
305
306/// How long an Ask credential lives at most: longer than any one answer.
307pub const ASK_TOKEN_TTL_SECONDS: u64 = 5 * 60;
308/// What an Ask credential is named, in audit entries and logs.
309pub const ASK_TOKEN_NAME: &str = "Ask g1t";
310/// Marks a token as Ask's in identity's records (`access_tokens.purpose`).
311pub const ASK_TOKEN_PURPOSE: &str = "ask";
312
313/// What an Ask credential holds: every read scope and nothing else.
314pub fn ask_token_scopes() -> Vec<crate::scopes::Scope> {
315 crate::scopes::Preset::ReadOnly.scopes().unwrap_or_default()
316}
317
318/// The plaintext token is returned once and never stored.
319#[derive(Debug, Serialize, Deserialize)]
320pub struct CreatedAccessToken {
321 pub token: String,
322 pub info: AccessToken,
323}
324
325/// `register`: creates an account and signs it in.
326/// Returns `Outcome<SignedIn>`.
327///
328/// Anyone may register. `invite_code` is optional: an invitation sent to
329/// an address without an account (`invite_member`, or a repository
330/// invitation) carries one, and using it applies the invitation once the
331/// address is confirmed.
332#[derive(Debug, Serialize, Deserialize)]
333pub struct RegisterArgs {
334 pub username: String,
335 pub email: String,
336 pub password: String,
337 /// An invite code such as `g1t-k7m2-q9xd-4hpw-…`, from an invitation.
338 /// One that is unknown, spent or for another address is ignored.
339 #[serde(default)]
340 pub invite_code: Option<String>,
341 /// The `proof` from the invite email's link. When it is the invite's
342 /// own and `email` is the address the invite was sent to, the account
343 /// starts with that address confirmed; otherwise it is ignored.
344 #[serde(default)]
345 pub email_proof: Option<String>,
346 /// Who is asking, such as the visitor's IP address, for rate limits.
347 #[serde(default)]
348 pub client: Option<String>,
349}
350
351/// `verify_email`: the token from the emailed link. Returns `Outcome<User>`.
352#[derive(Debug, Serialize, Deserialize)]
353pub struct EmailTokenArgs {
354 pub token: String,
355}
356
357/// `request_password_reset`. Always succeeds, so it cannot be used to find
358/// out which addresses have accounts. Any confirmed address of an account
359/// works: the link goes to the address given, and the primary (and the
360/// backup) are told a reset was asked for. A few requests an hour per
361/// address and per `client`; past that, nothing is sent.
362#[derive(Debug, Serialize, Deserialize)]
363pub struct EmailArgs {
364 pub email: String,
365 /// Who is asking, such as the visitor's IP address, for rate limits.
366 #[serde(default)]
367 pub client: Option<String>,
368}
369
370/// `reset_password`: sets a new password and ends every session.
371/// Returns `Outcome<User>`.
372#[derive(Debug, Serialize, Deserialize)]
373pub struct ResetPasswordArgs {
374 pub token: String,
375 pub password: String,
376}
377
378/// `device_start`: begins a device sign-in. Returns `DeviceStart`.
379#[derive(Debug, Serialize, Deserialize)]
380#[serde(rename_all = "camelCase")]
381pub struct DeviceStartArgs {
382 /// What is asking, shown to the person approving, e.g. "Claude Code".
383 pub client_name: String,
384}
385
386#[derive(Debug, Serialize, Deserialize)]
387#[serde(rename_all = "camelCase")]
388pub struct DeviceStart {
389 /// Secret held by the tool and exchanged for a token once approved.
390 pub device_code: String,
391 /// Short code shown to the person, e.g. `WDJB-MJHT`.
392 pub user_code: String,
393 /// Seconds until both codes stop working.
394 pub expires_in: u32,
395 /// Seconds the tool should wait between polls.
396 pub interval: u32,
397}
398
399/// `device_lookup`: what a user code is asking for, or null if it is not
400/// valid. Returns `Option<DeviceRequest>`.
401#[derive(Debug, Serialize, Deserialize)]
402#[serde(rename_all = "camelCase")]
403pub struct DeviceLookupArgs {
404 pub user_code: String,
405}
406
407#[derive(Debug, Serialize, Deserialize)]
408#[serde(rename_all = "camelCase")]
409pub struct DeviceRequest {
410 pub user_code: String,
411 pub client_name: String,
412}
413
414/// `device_resolve`: the signed-in person approves or denies a request.
415/// Returns `Outcome<bool>`.
416#[derive(Debug, Serialize, Deserialize)]
417#[serde(rename_all = "camelCase")]
418pub struct DeviceResolveArgs {
419 pub user_code: String,
420 pub user: User,
421 pub approve: bool,
422}
423
424/// `device_claim`: the tool asks whether its request was approved.
425#[derive(Debug, Serialize, Deserialize)]
426#[serde(rename_all = "camelCase")]
427pub struct DeviceClaimArgs {
428 pub device_code: String,
429}
430
431/// The answer to a `device_claim`.
432#[derive(Debug, Serialize, Deserialize)]
433#[serde(tag = "status", rename_all = "snake_case")]
434pub enum DeviceClaim {
435 /// Nobody has approved or denied it yet; ask again after the interval.
436 Pending,
437 Denied,
438 /// The code was never issued, has expired, or was already used.
439 Expired,
440 /// The access token, returned once.
441 Approved {
442 token: String,
443 user: User,
444 },
445}
446
447/// A workspace: the owner of repositories, and the first segment of their
448/// URLs. A person's own space and a team's are the same thing.
449#[derive(Clone, Debug, Serialize, Deserialize)]
450#[serde(rename_all = "camelCase")]
451pub struct Workspace {
452 pub id: String,
453 pub slug: String,
454 pub name: String,
455 /// One line saying what the workspace is for.
456 pub description: Option<String>,
457 /// RFC 3339.
458 pub created_at: String,
459 pub member_count: u32,
460 /// The workspace's uploaded icon: the SHA-256 of its bytes, served at
461 /// `/avatars/<avatar>`. Null means the generated letter avatar.
462 #[serde(default)]
463 pub avatar: Option<String>,
464 /// What every member gets on each of its repositories; owners have
465 /// Admin. See [`crate::access`].
466 #[serde(default)]
467 pub base_permission: crate::access::BasePermission,
468 /// Who may create its teams. See [`crate::teams::TeamCreation`].
469 #[serde(default)]
470 pub team_creation: crate::teams::TeamCreation,
471 /// What members may do, by GitHub's names for each
472 /// (`members_can_create_public_repositories`...), at the top level as
473 /// GitHub's organization has them. See [`crate::MemberPrivileges`].
474 #[serde(flatten)]
475 pub privileges: crate::MemberPrivileges,
476 /// Whether members and outside collaborators need two-factor
477 /// authentication to use it.
478 #[serde(default)]
479 pub two_factor_requirement_enabled: bool,
480}
481
482#[derive(Clone, Debug, Serialize, Deserialize)]
483pub struct Member {
484 pub username: String,
485 /// The username as its owner wrote it (`Ana`), when that differs from
486 /// `username`: what pages show.
487 #[serde(default, skip_serializing_if = "Option::is_none")]
488 pub display_username: Option<String>,
489 pub role: crate::Role,
490 /// The roles they hold besides `role`.
491 #[serde(default)]
492 pub org_roles: Vec<crate::OrgRole>,
493 /// Whether they have two-factor authentication on. Shown to owners
494 /// only; null for anyone else.
495 #[serde(default)]
496 pub two_factor: Option<bool>,
497 /// Their display name, when they set one.
498 #[serde(default)]
499 pub name: Option<String>,
500 /// Their uploaded avatar: the SHA-256 of its bytes, served at
501 /// `/avatars/<avatar>`. None means the generated letter avatar.
502 #[serde(default)]
503 pub avatar: Option<String>,
504}
505
506/// Where a workspace keeps its repositories' git data: anywhere g1t
507/// stores it (the default), or in the EU only. It applies to repositories
508/// made after it is set; the repos service reads it when it places a new
509/// one (`storage_options` says whether the EU can be chosen).
510#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
511#[serde(rename_all = "lowercase")]
512pub enum DataResidency {
513 #[default]
514 Anywhere,
515 Eu,
516}
517
518impl DataResidency {
519 pub fn as_str(self) -> &'static str {
520 match self {
521 DataResidency::Anywhere => "anywhere",
522 DataResidency::Eu => "eu",
523 }
524 }
525
526 pub fn parse(text: &str) -> Option<Self> {
527 match text.trim().to_ascii_lowercase().as_str() {
528 "anywhere" => Some(DataResidency::Anywhere),
529 "eu" => Some(DataResidency::Eu),
530 _ => None,
531 }
532 }
533}
534
535/// `workspace_residency` takes [`SlugArgs`] and returns
536/// `Option<DataResidency>` (null when there is no such workspace).
537/// `set_workspace_residency`: owners only. Returns `Outcome<DataResidency>`.
538#[derive(Debug, Serialize, Deserialize)]
539pub struct SetResidencyArgs {
540 pub actor: User,
541 pub slug: String,
542 pub residency: DataResidency,
543}
544
545/// `create_workspace`. Returns `Outcome<Workspace>`.
546#[derive(Debug, Serialize, Deserialize)]
547pub struct CreateWorkspaceArgs {
548 pub user: User,
549 pub slug: String,
550 #[serde(default)]
551 pub name: String,
552}
553
554/// `get_workspace`: public details, or null. Returns `Option<Workspace>`.
555#[derive(Debug, Serialize, Deserialize)]
556pub struct SlugArgs {
557 pub slug: String,
558}
559
560/// `list_members`: members only. Owners also see each member's
561/// `two_factor`. Returns `Outcome<Vec<Member>>`.
562#[derive(Debug, Serialize, Deserialize)]
563pub struct ListMembersArgs {
564 pub slug: String,
565 pub viewer: crate::Viewer,
566}
567
568/// `add_member` and `remove_member`: owners only. `add_member` never adds a
569/// person at once: it sends them a workspace invitation to accept or
570/// decline, as `invite_member` with a username does. Only g1t's own agent
571/// is added at once. Removing yourself is
572/// leaving (`members::LeaveWorkspaceArgs`); removing an owner is refused
573/// when they are the last. Each returns `Outcome<bool>`.
574#[derive(Debug, Serialize, Deserialize)]
575pub struct MemberArgs {
576 pub actor: User,
577 pub slug: String,
578 pub username: String,
579 #[serde(default)]
580 pub surface: Option<crate::audit::Surface>,
581}
582
583/// `update_workspace`: owners only. An empty name falls back to the slug;
584/// an empty description clears it. Returns `Outcome<Workspace>`.
585#[derive(Debug, Serialize, Deserialize)]
586pub struct UpdateWorkspaceArgs {
587 pub actor: User,
588 pub slug: String,
589 pub name: String,
590 pub description: String,
591}
592
593/// `rename_workspace`: owners only. Changes the workspace's slug, the first
594/// segment of its URLs, to `new_slug`; the display name is untouched. The
595/// old slug redirects to the new one, and is held for this workspace, for
596/// [`SLUG_HOLD_DAYS`]. Publishes `workspace.renamed`. Returns
597/// `Outcome<Workspace>`.
598///
599/// `check_workspace_rename` takes the same arguments and answers whether
600/// the rename would be allowed, changing nothing. Returns `Outcome<bool>`.
601#[derive(Debug, Serialize, Deserialize)]
602#[serde(rename_all = "camelCase")]
603pub struct RenameWorkspaceArgs {
604 pub actor: User,
605 pub slug: String,
606 pub new_slug: String,
607}
608
609/// `delete_workspace`: owners only, and only a person. `confirm` must be
610/// the workspace's slug, typed out. Refused for a protected workspace
611/// ([`protected_names`]), whoever asks, and while billing cannot settle it
612/// (`close_workspace`). Everything in it goes with it at once: nobody can
613/// reach it, its tokens stop working, its pages are not found, and its
614/// repositories, projects and apps are deleted with it. It is kept for
615/// [`WORKSPACE_RESTORE_DAYS`] so g1t's staff can restore it, then purged:
616/// its memberships, access tokens and old-slug redirects go, and billing's
617/// ledger and the audit log keep its history. The slug is never given to
618/// another workspace; the person whose username it is may make a workspace
619/// of that name again once it is purged. Publishes `workspace.deleting`,
620/// and `workspace.deleted` at the purge. Returns `Outcome<bool>`.
621///
622/// `check_workspace_deletion` takes the same arguments (with `confirm`
623/// ignored) and says what would go and whether anything stands in the way,
624/// changing nothing. Returns `Outcome<WorkspaceDeletion>`.
625#[derive(Debug, Serialize, Deserialize)]
626pub struct DeleteWorkspaceArgs {
627 pub actor: User,
628 pub slug: String,
629 #[serde(default)]
630 pub confirm: String,
631 /// Where the request came in, for the audit log; g1t.sh when absent.
632 #[serde(default)]
633 pub surface: Option<crate::audit::Surface>,
634}
635
636/// What deleting a workspace takes with it, and what stands in the way.
637/// Nothing does when `billing` is null and it is not `protected`.
638#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
639pub struct WorkspaceDeletion {
640 /// Its live repositories, which are deleted with it.
641 pub repositories: u32,
642 /// Its projects, hidden with it.
643 pub projects: u32,
644 #[serde(default)]
645 pub members: u32,
646 /// Why billing cannot close the workspace yet, in words for its owner.
647 pub billing: Option<String>,
648 /// It can never be deleted, by anyone ([`protected_names`]).
649 #[serde(default)]
650 pub protected: bool,
651}
652
653impl WorkspaceDeletion {
654 pub fn blocked(&self) -> bool {
655 self.protected || self.billing.is_some()
656 }
657
658 /// Why the workspace cannot be deleted, as one sentence, or `None`.
659 pub fn reason(&self, slug: &str) -> Option<String> {
660 if self.protected {
661 return Some(protected_refusal(slug));
662 }
663 self.billing.clone()
664 }
665}
666
667/// How long a deleted workspace is kept, for staff to restore, before it is
668/// purged.
669pub const WORKSPACE_RESTORE_DAYS: u64 = 30;
670
671/// Workspaces nobody can delete, whatever identity's `PROTECTED_WORKSPACES`
672/// says: Flagon's, which runs g1t.
673pub const ALWAYS_PROTECTED: &[&str] = &["flagon-io"];
674
675/// The protected workspaces: `configured` (comma-separated slugs or
676/// workspace ids, as identity's `PROTECTED_WORKSPACES` holds them), and
677/// [`ALWAYS_PROTECTED`] whatever it says, so an empty or missing variable
678/// still protects them. Lowercased, without duplicates.
679pub fn protected_names(configured: Option<&str>) -> Vec<String> {
680 let mut names: Vec<String> = Vec::new();
681 let given = configured.unwrap_or_default().split(',');
682 for name in ALWAYS_PROTECTED.iter().copied().chain(given) {
683 let name = name.trim().to_lowercase();
684 if !name.is_empty() && !names.contains(&name) {
685 names.push(name);
686 }
687 }
688 names
689}
690
691/// Why a protected workspace is not deleted, purged or acted on.
692pub fn protected_refusal(slug: &str) -> String {
693 format!("{slug} is protected and can never be deleted.")
694}
695
696/// `admin_deleted_workspaces` takes no arguments (`{}`) and returns
697/// `Vec<DeletedWorkspace>`, newest first. Staff only.
698///
699/// A workspace an owner deleted, kept until `purge_after` for staff to
700/// restore.
701#[derive(Clone, Debug, Serialize, Deserialize)]
702#[serde(rename_all = "camelCase")]
703pub struct DeletedWorkspace {
704 pub workspace_id: String,
705 pub slug: String,
706 pub name: String,
707 /// RFC 3339.
708 pub deleted_at: String,
709 /// The username of the owner who deleted it, or the staff member (by
710 /// email) who deleted it with the account that was its only owner.
711 pub deleted_by: String,
712 /// RFC 3339: when it is purged unless restored first.
713 pub purge_after: String,
714 /// What went with it, counted when it was deleted.
715 pub went: WorkspaceDeletion,
716 /// Whether staff can still restore it.
717 pub restorable: bool,
718}
719
720/// `admin_restore_workspace` and `admin_purge_workspace`: staff restore a
721/// deleted workspace within [`WORKSPACE_RESTORE_DAYS`], or purge it now.
722/// `staff` is who, for the audit logs. Purging needs `confirm`, the slug
723/// typed out, and is refused for a protected workspace. Restoring publishes
724/// `workspace.restored`; purging, `workspace.deleted`. Both return
725/// `Outcome<bool>`.
726#[derive(Debug, Serialize, Deserialize)]
727#[serde(rename_all = "camelCase")]
728pub struct AdminDeletedWorkspaceArgs {
729 pub workspace_id: String,
730 pub staff: String,
731 #[serde(default)]
732 pub confirm: String,
733}
734
735/// `transfer_repo_scopes`: a repository moved from `from` to `to`; the
736/// tokens of agents at work on it are kept pointing at it. For repos'
737/// `transfer`. Returns `bool`.
738#[derive(Debug, Serialize, Deserialize)]
739pub struct TransferRepoScopesArgs {
740 pub from: crate::repos::RepoPath,
741 pub to: crate::repos::RepoPath,
742}
743
744/// How long a workspace's old slug keeps redirecting to it, and stays
745/// reserved for it, after a rename.
746pub const SLUG_HOLD_DAYS: u64 = 90;
747
748/// How long a workspace must wait between renames.
749pub const RENAME_COOLDOWN_HOURS: u64 = 24;
750
751// `resolve_slug` takes `SlugArgs` and returns `Option<String>`: the
752// workspace's current slug when `slug` is one it was renamed from within
753// the last `SLUG_HOLD_DAYS`, and null otherwise (including for a slug that
754// is in use), or the workspace's slug when `slug` is one of its aliases.
755
756// `resolve_alias` takes `SlugArgs` and returns `Option<String>`: the slug
757// now of the workspace `slug` is an alias of, and null when it is none.
758// Aliases are set by g1t's staff only: `g1t` is Flagon, Inc.'s `flagon-io`.
759// An alias follows its workspace through renames.
760
761/// `admin_aliases` takes no arguments (`{}`) and returns
762/// `Vec<WorkspaceAlias>`, by alias. Staff only.
763///
764/// A name staff point at a workspace, so that its addresses (pages, git,
765/// the API, packages) lead to the workspace under its own name.
766#[derive(Clone, Debug, Serialize, Deserialize)]
767#[serde(rename_all = "camelCase")]
768pub struct WorkspaceAlias {
769 pub alias: String,
770 pub workspace_id: String,
771 /// The workspace's slug and name now.
772 pub workspace: String,
773 pub workspace_name: String,
774 /// Why it exists, as staff wrote it.
775 pub note: String,
776 /// The staff member who set it, or `migration`.
777 pub created_by: String,
778 /// RFC 3339.
779 pub created_at: String,
780}
781
782/// `admin_set_alias`: points `alias` at the workspace whose slug is
783/// `workspace`. The alias must have a namespace's shape, must not be one of
784/// the site's routes, and must not be anyone's username, a workspace's slug
785/// (deleted, or held after a rename) or another alias. `note` is required:
786/// it is the reason, kept with the alias and in sudo's audit log. Staff
787/// only. Returns `Outcome<WorkspaceAlias>`.
788#[derive(Debug, Serialize, Deserialize)]
789#[serde(rename_all = "camelCase")]
790pub struct AdminSetAliasArgs {
791 pub alias: String,
792 pub workspace: String,
793 pub note: String,
794 pub staff: String,
795}
796
797/// `admin_remove_alias`: the alias stops leading anywhere, and the name is
798/// nobody's again unless it is reserved. `reason` goes in sudo's audit log.
799/// Staff only. Returns `Outcome<bool>`.
800#[derive(Debug, Serialize, Deserialize)]
801#[serde(rename_all = "camelCase")]
802pub struct AdminRemoveAliasArgs {
803 pub alias: String,
804 pub reason: String,
805 pub staff: String,
806}
807
808/// `set_workspace_avatar`: owners only. `image` is the file's bytes in
809/// base64: PNG, JPEG, WebP or GIF, at most `MAX_AVATAR_BYTES`. Null removes
810/// the icon. Returns `Outcome<Workspace>`.
811#[derive(Debug, Serialize, Deserialize)]
812pub struct SetWorkspaceAvatarArgs {
813 pub actor: User,
814 pub slug: String,
815 pub image: Option<String>,
816}
817
818/// `set_user_avatar`: a person's own avatar, as `SetWorkspaceAvatarArgs`.
819/// Returns `Outcome<Option<String>>`: the new avatar, or null once removed.
820#[derive(Debug, Serialize, Deserialize)]
821pub struct SetUserAvatarArgs {
822 pub user: User,
823 pub image: Option<String>,
824}
825
826/// The largest avatar that can be uploaded, in bytes.
827pub const MAX_AVATAR_BYTES: usize = 1024 * 1024;
828
829/// `list_workspace_tokens`: members only. Returns
830/// `Outcome<Vec<AccessToken>>`.
831#[derive(Debug, Serialize, Deserialize)]
832pub struct WorkspaceTokensArgs {
833 pub slug: String,
834 pub viewer: crate::Viewer,
835}
836
837/// `remove_workspace_token`: owners only. Returns `Outcome<bool>`.
838#[derive(Debug, Serialize, Deserialize)]
839pub struct RemoveWorkspaceTokenArgs {
840 pub actor: User,
841 pub slug: String,
842 pub id: String,
843}
844
845/// `oauth_authorize`: the signed-in person approved an application. The
846/// caller has checked the client and that it may be redirected to
847/// `redirect_uri`. Returns `OAuthCode`.
848#[derive(Debug, Serialize, Deserialize)]
849#[serde(rename_all = "camelCase")]
850pub struct OAuthAuthorizeArgs {
851 pub user: User,
852 pub client_id: String,
853 /// Shown wherever the application's access is listed.
854 pub client_name: String,
855 pub redirect_uri: String,
856 /// PKCE challenge, method S256.
857 pub code_challenge: String,
858 /// What the person granted, as `resource:level`. Null: full access.
859 #[serde(default)]
860 pub scopes: Option<Vec<String>>,
861}
862
863#[derive(Debug, Serialize, Deserialize)]
864pub struct OAuthCode {
865 pub code: String,
866}
867
868/// `oauth_exchange`: redeems an authorization code.
869/// Returns `Outcome<OAuthTokens>`.
870#[derive(Debug, Serialize, Deserialize)]
871#[serde(rename_all = "camelCase")]
872pub struct OAuthExchangeArgs {
873 pub code: String,
874 pub code_verifier: String,
875 pub client_id: String,
876 pub redirect_uri: String,
877}
878
879/// `oauth_refresh`: trades a refresh token for new tokens.
880/// Returns `Outcome<OAuthTokens>`.
881#[derive(Debug, Serialize, Deserialize)]
882#[serde(rename_all = "camelCase")]
883pub struct OAuthRefreshArgs {
884 pub refresh_token: String,
885 pub client_id: String,
886}
887
888#[derive(Debug, Serialize, Deserialize)]
889#[serde(rename_all = "camelCase")]
890pub struct OAuthTokens {
891 pub access_token: String,
892 /// Works once; using it returns the next one.
893 pub refresh_token: String,
894 /// Seconds until the access token stops working.
895 pub expires_in: u64,
896 /// The scopes granted, space-separated, or `*` for full access.
897 #[serde(default)]
898 pub scope: Option<String>,
899}
900
901/// An application a person has signed in to. Listed by `list_oauth_grants`
902/// and ended by `revoke_oauth_grant`.
903#[derive(Debug, Serialize, Deserialize)]
904#[serde(rename_all = "camelCase")]
905pub struct OAuthGrant {
906 pub id: String,
907 pub client_name: String,
908 /// RFC 3339.
909 pub created_at: String,
910 /// RFC 3339.
911 pub last_used_at: String,
912 /// What the person granted. Null: full access.
913 #[serde(default)]
914 pub scopes: Option<Vec<String>>,
915 /// Signed in before applications were given scopes: full access until
916 /// someone narrows it.
917 #[serde(default)]
918 pub legacy: bool,
919}
920
921/// `update_oauth_grant`: changes what an application the person signed in
922/// to may do, at once and when it refreshes. Returns `Outcome<OAuthGrant>`.
923#[derive(Debug, Serialize, Deserialize)]
924pub struct UpdateOAuthGrantArgs {
925 pub user: User,
926 pub id: String,
927 #[serde(default)]
928 pub scopes: Option<Vec<String>>,
929}
930
931
932/// What a scoped token may do: these operations, in this repository. Run
933/// credentials (a token for one CI or sandbox run, see
934/// [`crate::credentials`]) carry one today, and so do tokens g1t's retired
935/// hosted agents were issued, which still parse so their stored rows and
936/// the `@g1t` history they wrote read as before.
937#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
938pub struct AgentScope {
939 pub repo: crate::repos::RepoPath,
940 /// API and MCP operation names, such as `create_issue`.
941 pub operations: Vec<String>,
942 /// Set on a run credential: the run it belongs to, and what it may do
943 /// with git. See [`crate::credentials`].
944 #[serde(default, skip_serializing_if = "Option::is_none")]
945 pub run: Option<crate::credentials::RunBinding>,
946}
947
948/// The id g1t's retired hosted agent acted under. Only ever stored, never
949/// shown: rows it wrote keep it, and still render as g1t's
950/// ([`crate::system::ID`]) work without counting as g1t itself, such as
951/// for whether an approval counts.
952pub const AGENT_ID: &str = "usr_g1t_agent";
953/// The name g1t's agent is shown by: g1t's own, [`crate::system::USERNAME`].
954/// Everything it does, people see g1t do.
955pub const AGENT_NAME: &str = crate::system::USERNAME;
956
957// --- Staff ---------------------------------------------------------------
958//
959// Staff-only methods, for sudo.g1t.sh. They take no viewer and check no
960// membership: only sudo calls them, over its service binding, after it has
961// verified a Cloudflare Access sign-in and its staff list. Nothing a
962// customer can reach should ever forward to them.
963
964/// `notify_owners`: emails a short notice, with one link, to each owner of
965/// a workspace with a confirmed address. Called by other services (billing
966/// warns owners near their usage limit), never on a person's behalf.
967/// Returns how many were sent.
968#[derive(Clone, Debug, Serialize, Deserialize)]
969pub struct NotifyOwnersArgs {
970 pub workspace: String,
971 pub subject: String,
972 /// One or two sentences: what happened and what it means.
973 pub intro: String,
974 /// The button's words, such as `Open billing`.
975 pub action: String,
976 /// Where the button goes; must be on g1t.sh.
977 pub link: String,
978 /// Small print: why they got it.
979 pub footer: String,
980}
981
982/// `admin_workspaces`: every workspace, newest first, at most
983/// [`ADMIN_WORKSPACES_LIMIT`], optionally only those whose slug, name or
984/// an owner's username or email contains `query`. Returns
985/// `Vec<AdminWorkspace>`. Staff only.
986#[derive(Debug, Default, Serialize, Deserialize)]
987pub struct AdminWorkspacesArgs {
988 #[serde(default)]
989 pub query: Option<String>,
990}
991
992/// The most workspaces one `admin_workspaces` call returns.
993pub const ADMIN_WORKSPACES_LIMIT: usize = 500;
994
995/// An owner of a workspace, as staff see them.
996#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
997pub struct AdminOwner {
998 pub username: String,
999 pub email: Option<String>,
1000}
1001
1002/// A workspace as staff see it: who owns it and how many belong to it.
1003#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1004#[serde(rename_all = "camelCase")]
1005pub struct AdminWorkspace {
1006 pub slug: String,
1007 pub name: String,
1008 /// RFC 3339.
1009 pub created_at: String,
1010 pub owners: Vec<AdminOwner>,
1011 pub member_count: u32,
1012}
1013
1014/// `admin_workspace`: one workspace with every member, or null. Takes
1015/// `SlugArgs`; returns `Option<AdminWorkspaceDetail>`. Staff only.
1016#[derive(Clone, Debug, Serialize, Deserialize)]
1017#[serde(rename_all = "camelCase")]
1018pub struct AdminWorkspaceDetail {
1019 pub slug: String,
1020 pub name: String,
1021 pub description: Option<String>,
1022 /// RFC 3339.
1023 pub created_at: String,
1024 /// Owners first, then by username.
1025 pub members: Vec<AdminMember>,
1026 /// It can never be deleted ([`protected_names`]).
1027 #[serde(default)]
1028 pub protected: bool,
1029 /// Set while staff have it suspended.
1030 #[serde(default)]
1031 pub suspended: Option<Suspension>,
1032}
1033
1034/// A member of a workspace, as staff see them.
1035#[derive(Clone, Debug, Serialize, Deserialize)]
1036pub struct AdminMember {
1037 pub username: String,
1038 pub email: Option<String>,
1039 pub role: crate::Role,
1040 /// When they joined the workspace. RFC 3339.
1041 pub joined: String,
1042}
1043
1044// --- Profiles ------------------------------------------------------------
1045//
1046// A person's public page at `g1t.sh/u/<username>`. Everything in a
1047// `Profile` is shown to anyone, signed in or not; an email address never is.
1048
1049/// The most characters each profile field takes.
1050pub const MAX_PROFILE_NAME: usize = 80;
1051pub const MAX_PROFILE_BIO: usize = 160;
1052pub const MAX_PROFILE_LOCATION: usize = 80;
1053pub const MAX_PROFILE_WEBSITE: usize = 200;
1054pub const MAX_PROFILE_PRONOUNS: usize = 40;
1055pub const MAX_PROFILE_TIMEZONE: usize = 64;
1056
1057/// What anyone may see about a person.
1058#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1059#[serde(rename_all = "camelCase")]
1060pub struct Profile {
1061 /// Lowercased: what the profile is found and linked by.
1062 pub username: String,
1063 /// The username as its owner wrote it, when that differs: what the page shows.
1064 #[serde(default, skip_serializing_if = "Option::is_none")]
1065 pub display_username: Option<String>,
1066 /// The name they go by, if they gave one.
1067 pub name: Option<String>,
1068 /// One or two lines about them, at most [`MAX_PROFILE_BIO`] characters.
1069 pub bio: Option<String>,
1070 pub location: Option<String>,
1071 /// An `https://` address.
1072 pub website: Option<String>,
1073 pub pronouns: Option<String>,
1074 /// The time zone they are in, an IANA name such as `America/Denver`.
1075 #[serde(default)]
1076 pub timezone: Option<String>,
1077 /// The uploaded avatar's hash, served at `/avatars/<avatar>`.
1078 pub avatar: Option<String>,
1079 /// When the account was made. RFC 3339.
1080 pub created_at: String,
1081}
1082
1083// `profile` takes `UsernameArgs` and returns `Option<Profile>`: null for
1084// an account that does not exist.
1085
1086/// `update_profile`: a person changes their own profile. Every field is
1087/// replaced; an empty one is cleared. Returns `Outcome<Profile>`.
1088#[derive(Debug, Default, Serialize, Deserialize)]
1089#[serde(rename_all = "camelCase")]
1090pub struct UpdateProfileArgs {
1091 pub actor: User,
1092 #[serde(default)]
1093 pub name: String,
1094 #[serde(default)]
1095 pub bio: String,
1096 #[serde(default)]
1097 pub location: String,
1098 #[serde(default)]
1099 pub website: String,
1100 #[serde(default)]
1101 pub pronouns: String,
1102 /// An IANA time zone name, such as `America/Denver`.
1103 #[serde(default)]
1104 pub timezone: String,
1105}
1106
1107/// `profile_workspaces`: the workspaces shown on a person's profile, as
1108/// `viewer` may see them. A membership is shown only when it is no secret
1109/// from the viewer: a workspace the viewer belongs to as well, or one of
1110/// `public`, the workspaces the caller found the person has made a public
1111/// project in (whose page shows that already). Returns
1112/// `Vec<ProfileWorkspace>`; empty for an account that does not exist.
1113#[derive(Debug, Serialize, Deserialize)]
1114pub struct ProfileWorkspacesArgs {
1115 pub username: String,
1116 pub viewer: crate::Viewer,
1117 #[serde(default)]
1118 pub public: Vec<String>,
1119}
1120
1121/// A workspace on a person's profile.
1122#[derive(Clone, Debug, Serialize, Deserialize)]
1123pub struct ProfileWorkspace {
1124 pub slug: String,
1125 pub name: String,
1126 pub avatar: Option<String>,
1127}
1128
1129// --- Dock pins -------------------------------------------------------------
1130//
1131// The apps a person pins to their dock in a workspace, kept with their
1132// account so the dock follows them to every device. Each person's own:
1133// nobody else reads or sets them.
1134
1135/// The most apps a person pins in one workspace.
1136pub const MAX_DOCK_PINS: usize = 24;
1137/// The most characters an app key takes.
1138pub const MAX_DOCK_APP_KEY: usize = 32;
1139
1140/// `dock_pins`: the apps `user` pinned in the workspace `workspace` (a
1141/// slug), in the order they set. Returns `Option<Vec<String>>`: null when
1142/// they never saved any there, or are not one of its members.
1143#[derive(Debug, Default, Serialize, Deserialize)]
1144#[serde(rename_all = "camelCase")]
1145pub struct DockPinsArgs {
1146 pub user: User,
1147 pub workspace: String,
1148}
1149
1150/// `set_dock_pins`: replaces `user`'s pins in `workspace` with `apps`, in
1151/// that order. Each key is lowercase letters, digits and hyphens, at most
1152/// [`MAX_DOCK_APP_KEY`] characters; a repeat is dropped; at most
1153/// [`MAX_DOCK_PINS`]. Which keys name real apps is the web app's to say.
1154/// Returns `Outcome<Vec<String>>`: the pins as saved.
1155#[derive(Debug, Default, Serialize, Deserialize)]
1156#[serde(rename_all = "camelCase")]
1157pub struct SetDockPinsArgs {
1158 pub user: User,
1159 pub workspace: String,
1160 #[serde(default)]
1161 pub apps: Vec<String>,
1162}
1163
1164// --- Getting started in a workspace ----------------------------------------
1165//
1166// The setup guide a workspace's owners see on its Home until they finish
1167// or dismiss it: adding an AI provider, Ask's model, bringing code,
1168// connecting a harness, inviting people and a runner. Whether each step is
1169// done is read from the workspace itself (its providers, repositories,
1170// members, runners), never kept here; identity keeps only what the person
1171// chose: that they dismissed it, and the steps they skipped. Each person's
1172// own, per workspace. Mirrors `Onboarding` in
1173// packages/contracts/src/identity.ts.
1174
1175/// The steps of the guide, in order. `ask`, `people` and `runner` can be
1176/// skipped; the rest are what a workspace needs to get going.
1177pub const ONBOARDING_STEPS: [&str; 6] = ["ai", "ask", "code", "harness", "people", "runner"];
1178
1179/// A person's own state of the guide in one workspace, as kept and as
1180/// answered. Wire fields are snake_case, as the API's are.
1181#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1182pub struct Onboarding {
1183 /// When they dismissed it, so it no longer opens by itself; null while
1184 /// it still does. Opening it again from Settings or the AI page leaves
1185 /// this as it is.
1186 #[serde(default)]
1187 pub dismissed_at: Option<String>,
1188 /// The steps they chose to skip, in [`ONBOARDING_STEPS`] order: shown
1189 /// as skipped rather than to do, and not counted against finishing.
1190 #[serde(default)]
1191 pub skipped: Vec<String>,
1192 /// When they last changed it; null when they never have.
1193 #[serde(default)]
1194 pub updated_at: Option<String>,
1195}
1196
1197/// A change to it: only what is sent changes. `dismissed` true dismisses
1198/// it now (a second dismissal keeps the first time), false brings it back
1199/// to opening by itself. `skipped` replaces the skipped steps.
1200#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1201pub struct OnboardingChange {
1202 #[serde(default)]
1203 pub dismissed: Option<bool>,
1204 #[serde(default)]
1205 pub skipped: Option<Vec<String>>,
1206}
1207
1208/// `onboarding`: `user`'s own state of the guide in the workspace
1209/// `workspace` (a slug). Returns `Outcome<Onboarding>`: the defaults (not
1210/// dismissed, nothing skipped) when they never changed it, `not_found`
1211/// when they are not one of its members. People only.
1212#[derive(Debug, Default, Serialize, Deserialize)]
1213#[serde(rename_all = "camelCase")]
1214pub struct OnboardingArgs {
1215 pub user: User,
1216 pub workspace: String,
1217}
1218
1219/// `set_onboarding`: changes `user`'s own state of the guide in
1220/// `workspace`. Returns `Outcome<Onboarding>`: as kept, or `invalid` for a
1221/// step the guide does not have.
1222#[derive(Debug, Default, Serialize, Deserialize)]
1223#[serde(rename_all = "camelCase")]
1224pub struct SetOnboardingArgs {
1225 pub user: User,
1226 pub workspace: String,
1227 #[serde(default)]
1228 pub change: OnboardingChange,
1229}
1230
1231// --- Sounds and desktop notifications --------------------------------------
1232//
1233// What a person hears when chat moves, kept with their account so a phone,
1234// a laptop and the desktop app all sound the same. Which sound plays when
1235// is the web app's rule (apps/web/app/lib/chat-sounds.ts); identity keeps
1236// the choices. Do not disturb is not here: it is the person's presence
1237// (`dnd_until`, services/notify), which also silences pop-ups and pushes.
1238// Mirrors `SoundSettings` in packages/contracts/src/identity.ts.
1239
1240/// The sets of sounds a person can choose from.
1241pub const SOUND_SETS: [&str; 2] = ["soft", "bright"];
1242/// The cues a person can turn on and off. `call` is reserved and has no setting.
1243pub const SOUND_CUES: [&str; 4] = ["message", "direct", "mention", "sent"];
1244/// Cues that no longer play: `agent_done`, from g1t's retired hosted
1245/// agents. Saved settings that name one still read, without it, and a
1246/// change that names one leaves it out rather than failing.
1247pub const RETIRED_SOUND_CUES: [&str; 1] = ["agent_done"];
1248/// Before anyone changes them: every cue but the tick as you send.
1249pub const SOUND_CUES_OFF_BY_DEFAULT: [&str; 1] = ["sent"];
1250pub const DEFAULT_SOUND_SET: &str = "soft";
1251pub const DEFAULT_SOUND_VOLUME: u8 = 60;
1252
1253/// A person's sound settings, as kept and as answered. Wire fields are
1254/// snake_case, as the site's JSON is.
1255#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1256pub struct SoundSettings {
1257 /// Whether anything plays at all.
1258 pub sounds_enabled: bool,
1259 /// One of [`SOUND_SETS`].
1260 pub sound_set: String,
1261 /// 0 to 100.
1262 pub sound_volume: u8,
1263 /// Each cue on or off, by name; a cue left out is on, except `sent`.
1264 #[serde(default)]
1265 pub sound_cues: std::collections::BTreeMap<String, bool>,
1266 /// Whether an open tab shows a system notification for a message to
1267 /// you while its window is not in front.
1268 pub desktop_toasts: bool,
1269}
1270
1271impl Default for SoundSettings {
1272 fn default() -> Self {
1273 SoundSettings {
1274 sounds_enabled: true,
1275 sound_set: DEFAULT_SOUND_SET.to_owned(),
1276 sound_volume: DEFAULT_SOUND_VOLUME,
1277 sound_cues: SOUND_CUES
1278 .iter()
1279 .map(|cue| ((*cue).to_owned(), !SOUND_CUES_OFF_BY_DEFAULT.contains(cue)))
1280 .collect(),
1281 desktop_toasts: false,
1282 }
1283 }
1284}
1285
1286/// A change to them: only what is sent changes; `sound_cues` merges by cue.
1287#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1288pub struct SoundSettingsChange {
1289 #[serde(default)]
1290 pub sounds_enabled: Option<bool>,
1291 #[serde(default)]
1292 pub sound_set: Option<String>,
1293 #[serde(default)]
1294 pub sound_volume: Option<i64>,
1295 #[serde(default)]
1296 pub sound_cues: Option<std::collections::BTreeMap<String, bool>>,
1297 #[serde(default)]
1298 pub desktop_toasts: Option<bool>,
1299}
1300
1301/// `sound_settings`: `user`'s own, or the defaults when they never changed
1302/// them. Returns `SoundSettings`. People only.
1303#[derive(Debug, Default, Serialize, Deserialize)]
1304#[serde(rename_all = "camelCase")]
1305pub struct SoundSettingsArgs {
1306 pub user: User,
1307}
1308
1309/// `set_sound_settings`: changes `user`'s own. Returns
1310/// `Outcome<SoundSettings>`: the settings as kept, or `invalid` for a set
1311/// or cue g1t does not have, or a volume outside 0 to 100.
1312#[derive(Debug, Default, Serialize, Deserialize)]
1313#[serde(rename_all = "camelCase")]
1314pub struct SetSoundSettingsArgs {
1315 pub user: User,
1316 #[serde(default)]
1317 pub change: SoundSettingsChange,
1318}
1319
1320/// `directory`: every account or every workspace, as their public pages
1321/// show them, a page at a time in name order. For services that index
1322/// them, such as search; nothing private is in it. Returns
1323/// `DirectoryPage`.
1324#[derive(Debug, Default, Serialize, Deserialize)]
1325pub struct DirectoryArgs {
1326 /// `user` or `workspace`.
1327 pub kind: String,
1328 /// Names after this one.
1329 #[serde(default)]
1330 pub after: Option<String>,
1331 pub limit: u32,
1332}
1333
1334/// One account or workspace in the directory.
1335#[derive(Clone, Debug, Serialize, Deserialize)]
1336#[serde(rename_all = "camelCase")]
1337pub struct DirectoryEntry {
1338 /// The account's or workspace's id.
1339 pub id: String,
1340 /// A username or a workspace's slug.
1341 pub slug: String,
1342 /// A person's display name or a workspace's name.
1343 pub name: Option<String>,
1344 /// A person's bio or a workspace's description.
1345 pub bio: Option<String>,
1346 pub avatar: Option<String>,
1347 /// RFC 3339.
1348 pub created_at: String,
1349}
1350
1351#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1352pub struct DirectoryPage {
1353 pub entries: Vec<DirectoryEntry>,
1354 /// Where the next page starts; null on the last.
1355 pub next: Option<String>,
1356}
1357
1358// --- Invites ---------------------------------------------------------------
1359//
1360// An invitation into a workspace or onto a repository, sent to an address
1361// without an account, carries an invite code: registering with it applies
1362// the invitation once the address is confirmed. Anyone may register
1363// without one. See services/identity/src/invites.rs.
1364//
1365// Any person may also invite a friend to g1t by email ("Invite a friend",
1366// `create_invite`): word of mouth, never a gate. Each person has
1367// `INVITES_PER_USER` of those for good; one revoked or expired before it
1368// was used comes back, one used is spent. See
1369// services/identity/src/invites/friends.rs.
1370
1371/// How long an invite works, unless identity's `INVITE_TTL_DAYS` var says
1372/// otherwise.
1373pub const INVITE_TTL_DAYS: u64 = 30;
1374
1375/// How many friends one person may invite to g1t, unless identity's
1376/// `INVITES_PER_USER` var says otherwise. Staff may grant more.
1377pub const INVITES_PER_USER: u32 = 20;
1378
1379/// Where an invite stands. Only a pending invite can be used. A pending
1380/// invite can be revoked, and so can one awaiting confirmation.
1381#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1382#[serde(rename_all = "snake_case")]
1383pub enum InviteStatus {
1384 Pending,
1385 /// Used to make an account that has not confirmed its email address
1386 /// yet. The code is spent; the workspace (or repository) it gives is
1387 /// joined when the address is confirmed, unless it is revoked first.
1388 AwaitingConfirmation,
1389 /// Used to make an account that has confirmed its address, for a
1390 /// workspace it has not yet joined or declined: the workspace
1391 /// invitation waits for the person's answer (`accept_invitation`).
1392 AwaitingAnswer,
1393 Redeemed,
1394 /// Its person declined the workspace it invited them to.
1395 Declined,
1396 Expired,
1397 Revoked,
1398}
1399
1400/// What using an invite does.
1401#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1402#[serde(rename_all = "snake_case")]
1403pub enum InviteKind {
1404 /// Makes a new account, and joins `workspace` when one is set.
1405 Account,
1406 /// An existing account joins `workspace`. Never makes an account.
1407 Workspace,
1408}
1409
1410/// Whose invites an invite used.
1411#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1412#[serde(rename_all = "snake_case")]
1413pub enum InviteCharge {
1414 /// Its inviter's own: an invite to g1t made with Invite a friend.
1415 User,
1416 /// A workspace's, granted by staff before registration opened. Read
1417 /// only: none are made any more.
1418 Workspace,
1419 /// Nobody's: an invitation into a workspace or onto a repository, or
1420 /// one staff made.
1421 #[default]
1422 None,
1423}
1424
1425/// One invite, as the person who made it sees it.
1426#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1427#[serde(rename_all = "camelCase")]
1428pub struct Invite {
1429 pub id: String,
1430 /// The code, such as `g1t-k7m2-q9xd-…`: returned once when the invite
1431 /// is made, and afterwards to whoever made it while it is pending.
1432 /// Null otherwise.
1433 pub code: Option<String>,
1434 /// The code's first group, such as `g1t-k7m2`, to recognise it by.
1435 pub hint: String,
1436 /// Only an account with this address can use it. Null: anyone with
1437 /// the code.
1438 pub email: Option<String>,
1439 pub kind: InviteKind,
1440 /// The workspace it joins, by slug.
1441 pub workspace: Option<String>,
1442 pub status: InviteStatus,
1443 /// Whose invites it used: `user` for an invite to g1t from Invite a
1444 /// friend, which counts against its inviter's.
1445 #[serde(default)]
1446 pub charged_to: InviteCharge,
1447 /// Who made it, by username. Null when g1t staff did.
1448 pub invited_by: Option<String>,
1449 /// The account that used it, by username.
1450 pub redeemed_by: Option<String>,
1451 /// RFC 3339.
1452 pub created_at: String,
1453 /// RFC 3339.
1454 pub expires_at: String,
1455 /// RFC 3339.
1456 pub redeemed_at: Option<String>,
1457 /// RFC 3339.
1458 pub revoked_at: Option<String>,
1459 /// The account a workspace invitation is for, by username: someone
1460 /// invited by username, or the account the invite made.
1461 #[serde(default)]
1462 pub invitee: Option<String>,
1463 /// The role `workspace` is joined with. Null when it names none.
1464 #[serde(default)]
1465 pub role: Option<crate::Role>,
1466 /// The staff member who minted it. Only in staff views.
1467 #[serde(default, skip_serializing_if = "Option::is_none")]
1468 pub staff: Option<String>,
1469}
1470
1471/// How many friends a person may invite to g1t, and how many they have.
1472#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1473pub struct Allowance {
1474 /// [`INVITES_PER_USER`] (or identity's var) plus what staff granted.
1475 pub limit: u32,
1476 /// Pending and used invites; revoked and expired ones never used are
1477 /// not counted.
1478 pub used: u32,
1479 pub remaining: u32,
1480}
1481
1482impl Allowance {
1483 pub fn new(limit: u32, used: u32) -> Allowance {
1484 Allowance { limit, used, remaining: limit.saturating_sub(used) }
1485 }
1486
1487 pub fn exhausted(&self) -> bool {
1488 self.remaining == 0
1489 }
1490}
1491
1492/// `list_invites` (takes `UserArgs`): the invites to g1t a person made,
1493/// newest first, and how many they have left. Returns `InvitesOverview`.
1494#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1495pub struct InvitesOverview {
1496 pub allowance: Allowance,
1497 pub invites: Vec<Invite>,
1498}
1499
1500/// `create_invite`: a person invites a friend to g1t by email. Anyone may
1501/// sign up without one; the invite is a note from a friend, with a link
1502/// that opens sign-up with the address filled in and, from the email,
1503/// confirmed. People only, never an agent or a workspace's token, and not
1504/// before their own address is confirmed. Uses one of the person's
1505/// invites. Refused with `Conflict` when the address has a g1t account or
1506/// the person already has a pending invite for it (neither costs one), and
1507/// `Limit` when none are left. Returns `Outcome<Invite>`, with the code.
1508///
1509/// `revoke_invite` (takes `RemoveArgs`): its maker revokes a pending
1510/// invite (or a workspace's owner one made for the workspace); one that
1511/// was not used comes back. Returns `Outcome<Invite>`.
1512///
1513/// `resend_invite` (takes `RemoveArgs`): its maker sends a pending invite
1514/// to g1t again, the same email to the same address. Returns
1515/// `Outcome<Invite>`; one that is not pending answers `Conflict`.
1516#[derive(Debug, Serialize, Deserialize)]
1517pub struct CreateInviteArgs {
1518 pub user: User,
1519 pub email: String,
1520 /// A note from whoever invites, quoted in the email. Up to
1521 /// [`MAX_INVITE_MESSAGE`] characters; longer is cut, blank is none.
1522 #[serde(default)]
1523 pub message: Option<String>,
1524 /// Also invite them to this workspace, by slug: one the person owns,
1525 /// on a paid plan (a free one is refused with `PaymentRequired`). Once
1526 /// the account is confirmed it gets a workspace invitation to accept or
1527 /// decline, and no workspace of its own is made for it.
1528 #[serde(default)]
1529 pub join: Option<String>,
1530 /// The role `join` invites them with; member when absent. Ignored
1531 /// without `join`.
1532 #[serde(default)]
1533 pub join_role: Option<crate::Role>,
1534 /// Where the request came in, for the audit log; g1t.sh when absent.
1535 #[serde(default)]
1536 pub surface: Option<crate::audit::Surface>,
1537}
1538
1539/// `check_invite`: what an invite code is for, before using it. Returns
1540/// `Outcome<InvitePreview>`; a code that is unknown, used, revoked or
1541/// expired gets the same answer, so codes cannot be probed. With
1542/// `any_status`, a real code that can no longer be used is described
1543/// instead (its `status` says why), so the page can say whom to ask for a
1544/// new one; an unknown code still gets the one answer.
1545#[derive(Debug, Serialize, Deserialize)]
1546pub struct InviteCodeArgs {
1547 pub code: String,
1548 /// Who is asking, such as the visitor's IP address, for rate limits.
1549 #[serde(default)]
1550 pub client: Option<String>,
1551 /// Who is looking, if signed in: sets `InvitePreview::for_viewer`.
1552 #[serde(default)]
1553 pub viewer: Option<User>,
1554 #[serde(default)]
1555 pub any_status: bool,
1556 /// The `proof` from the invite email's link, if the page was opened
1557 /// from it: sets `InvitePreview::email_proven`.
1558 #[serde(default)]
1559 pub email_proof: Option<String>,
1560}
1561
1562/// Someone shown on an invite.
1563#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1564pub struct InviteFrom {
1565 pub username: String,
1566 pub name: Option<String>,
1567 pub avatar: Option<String>,
1568}
1569
1570/// A repository an invite code was sent with: using the code accepts the
1571/// invitation to collaborate on it.
1572#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1573pub struct InviteRepository {
1574 /// `workspace/repo`.
1575 pub name: String,
1576 /// The role it gives, such as `write`.
1577 pub role: String,
1578}
1579
1580/// What a valid invite code is for.
1581#[derive(Clone, Debug, Serialize, Deserialize)]
1582#[serde(rename_all = "camelCase")]
1583pub struct InvitePreview {
1584 pub kind: InviteKind,
1585 /// Pending, unless `any_status` asked about a code that is spent.
1586 pub status: InviteStatus,
1587 /// Null when g1t staff sent it.
1588 pub invited_by: Option<InviteFrom>,
1589 pub workspace: Option<ProfileWorkspace>,
1590 /// The repository it accepts an invitation to, if it was sent with one.
1591 pub repository: Option<InviteRepository>,
1592 /// The address it is for, partly hidden, such as `a•••@example.com`.
1593 pub email: Option<String>,
1594 /// The address in full, while it is pending: whoever holds the code
1595 /// was sent it there. Fills in and locks the sign-up form.
1596 pub address: Option<String>,
1597 /// Whether the address it is for has a g1t account already, so the
1598 /// page asks them to sign in rather than sign up.
1599 pub has_account: bool,
1600 /// With a viewer: whether the invite is theirs (it is for one of their
1601 /// confirmed addresses, or they used it). Null without a viewer or,
1602 /// for a pending invite, when it is for anyone with the code.
1603 pub for_viewer: Option<bool>,
1604 /// RFC 3339.
1605 pub expires_at: String,
1606 /// Whether `email_proof` was this pending invite's own, from the email
1607 /// it was sent in: the account made with it starts with `address`
1608 /// confirmed. False without a proof, with a wrong one, and for an
1609 /// invite bound to no address.
1610 #[serde(default)]
1611 pub email_proven: bool,
1612}
1613
1614/// `accept_invite`: a signed-in person uses a workspace invite made for
1615/// their confirmed address, and joins the workspace, or an invite sent with
1616/// a repository invitation, and accepts it. Returns `Outcome<String>`: the
1617/// workspace's slug, or `workspace/repo`.
1618#[derive(Debug, Serialize, Deserialize)]
1619pub struct AcceptInviteArgs {
1620 pub user: User,
1621 pub code: String,
1622}
1623
1624/// `invite_member`: an owner invites an email address into a workspace.
1625/// It always makes an invite bound to that address and emails it, so the
1626/// answer never says whether the address has an account. Without one, the
1627/// invite registers and joins in one step. Returns `Outcome<Invite>`, with
1628/// the code.
1629#[derive(Debug, Serialize, Deserialize)]
1630pub struct InviteMemberArgs {
1631 pub actor: User,
1632 pub slug: String,
1633 /// An email address. Give this or `username`.
1634 #[serde(default)]
1635 pub email: String,
1636 /// A g1t username: that account gets a workspace invitation to accept
1637 /// or decline, in its inbox and by email. Nobody joins without saying
1638 /// yes.
1639 #[serde(default)]
1640 pub username: Option<String>,
1641 /// The role they join with; member when absent.
1642 #[serde(default)]
1643 pub role: Option<crate::Role>,
1644 /// A note from whoever invites, quoted in the invitation email. Up to
1645 /// [`MAX_INVITE_MESSAGE`] characters; longer is cut, blank is none.
1646 #[serde(default)]
1647 pub message: Option<String>,
1648 /// Where the request came in, for the audit log; g1t.sh when absent.
1649 #[serde(default)]
1650 pub surface: Option<crate::audit::Surface>,
1651}
1652
1653/// The most characters an invitation's note keeps.
1654pub const MAX_INVITE_MESSAGE: usize = 500;
1655
1656/// A workspace invitation waiting for its person's answer, as they see it.
1657/// `list_invitations` (takes `UserArgs`) returns `Vec<WorkspaceInvitation>`,
1658/// newest first: pending ones only, never expired, revoked or answered.
1659#[derive(Clone, Debug, Serialize, Deserialize)]
1660#[serde(rename_all = "camelCase")]
1661pub struct WorkspaceInvitation {
1662 pub id: String,
1663 pub workspace: ProfileWorkspace,
1664 /// The role accepting joins with.
1665 pub role: crate::Role,
1666 /// Null when g1t staff sent it.
1667 pub invited_by: Option<InviteFrom>,
1668 /// RFC 3339.
1669 pub created_at: String,
1670 /// RFC 3339.
1671 pub expires_at: String,
1672}
1673
1674/// `accept_invitation`: the person it is for joins the workspace with the
1675/// role it names. Returns `Outcome<String>`, the workspace's slug.
1676///
1677/// `decline_invitation`: they say no; whoever sent it is told in their
1678/// inbox. Returns `Outcome<bool>`.
1679#[derive(Debug, Serialize, Deserialize)]
1680pub struct InvitationArgs {
1681 pub user: User,
1682 pub id: String,
1683 /// Where the request came in, for the audit log; g1t.sh when absent.
1684 #[serde(default)]
1685 pub surface: Option<crate::audit::Surface>,
1686}
1687
1688/// `find_people`: accounts whose username starts with `query`, or whose
1689/// name contains it, for picking someone to invite. Only what a profile
1690/// shows: a username, a name and an avatar, never an email address.
1691/// Returns `Vec<InviteFrom>`, at most `limit` (10 at most, 8 when absent).
1692#[derive(Debug, Serialize, Deserialize)]
1693pub struct FindPeopleArgs {
1694 pub query: String,
1695 #[serde(default)]
1696 pub limit: Option<u32>,
1697}
1698
1699/// `workspace_invites` (takes `ListMembersArgs`): a workspace's invites,
1700/// newest first. Owners only. Returns `Outcome<Vec<Invite>>`.
1701///
1702/// `revoke_workspace_invite`: owners only. Returns `Outcome<Invite>`.
1703///
1704/// `resend_workspace_invite`: owners only. Sends a pending invitation
1705/// again, by email to the address it is bound to or the invited account's
1706/// confirmed address, and again in that account's inbox. The invitation
1707/// itself is unchanged: same code, same day it stops working. Returns
1708/// `Outcome<Invite>`; one that is not pending answers `409`.
1709#[derive(Debug, Serialize, Deserialize)]
1710pub struct WorkspaceInviteArgs {
1711 pub actor: User,
1712 pub slug: String,
1713 pub id: String,
1714}
1715
1716// --- Invites, staff only ---
1717
1718/// The most rows one staff listing of invites returns.
1719pub const ADMIN_INVITES_LIMIT: usize = 500;
1720
1721/// `admin_invites`: every invite, newest first, at most
1722/// [`ADMIN_INVITES_LIMIT`], optionally only those whose code starts with
1723/// `query`, or whose email, inviter or redeemer contains it, and with
1724/// `to_g1t` only invites to g1t from Invite a friend. Returns
1725/// `Vec<Invite>`.
1726#[derive(Debug, Default, Serialize, Deserialize)]
1727pub struct AdminInvitesArgs {
1728 #[serde(default)]
1729 pub query: Option<String>,
1730 #[serde(default)]
1731 pub to_g1t: bool,
1732}
1733
1734/// `admin_grant_invites`: gives a person (by username) `amount` more
1735/// invites to g1t; a negative amount takes some back. Kept with `note` and
1736/// the staff member. Returns `Outcome<Allowance>`: theirs afterwards.
1737#[derive(Debug, Serialize, Deserialize)]
1738pub struct AdminGrantInvitesArgs {
1739 pub username: String,
1740 pub amount: i32,
1741 #[serde(default)]
1742 pub note: String,
1743 pub staff: String,
1744}
1745
1746/// The most invites one grant gives or takes back.
1747pub const MAX_INVITE_GRANT: i32 = 1000;
1748
1749/// `admin_revoke_invite`: revokes any pending invite. Returns
1750/// `Outcome<Invite>`.
1751#[derive(Debug, Serialize, Deserialize)]
1752pub struct AdminRevokeInviteArgs {
1753 pub id: String,
1754 pub staff: String,
1755}
1756
1757// --- Suspension and blocked email domains, staff only ---
1758//
1759// See services/identity/src/suspension.rs. A suspended account cannot sign
1760// in, and its sessions and tokens stop working at once; a suspended
1761// workspace's own tokens stop working, and sudo also puts a hold on its
1762// compute (billing), which stops its runs, deploys, new self-hosted
1763// runners and telemetry. Both are undone the same way. A blocked email
1764// domain makes no new accounts and confirms no new addresses.
1765
1766/// Why and since when staff suspended an account or a workspace.
1767#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1768#[serde(rename_all = "camelCase")]
1769pub struct Suspension {
1770 pub reason: String,
1771 /// RFC 3339.
1772 pub at: String,
1773 /// The staff member, by email.
1774 pub by: String,
1775}
1776
1777/// `admin_suspend_user` (`name` a username) and `admin_suspend_workspace`
1778/// (`name` a slug): `suspend` true suspends with `reason` (required),
1779/// false lifts it. Returns `Outcome<Option<Suspension>>`: what stands now.
1780#[derive(Debug, Serialize, Deserialize)]
1781pub struct AdminSuspendArgs {
1782 pub name: String,
1783 pub suspend: bool,
1784 #[serde(default)]
1785 pub reason: String,
1786 pub staff: String,
1787}
1788
1789/// An email domain no new account may sign up with.
1790#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1791#[serde(rename_all = "camelCase")]
1792pub struct BlockedDomain {
1793 /// Lowercased, such as `spam.example`. Its subdomains are blocked too.
1794 pub domain: String,
1795 pub reason: String,
1796 pub blocked_by: String,
1797 /// RFC 3339.
1798 pub created_at: String,
1799}
1800
1801/// `admin_blocked_domains` takes `{}` and returns `Vec<BlockedDomain>`.
1802///
1803/// `admin_block_domain`: `block` true blocks `domain` with `reason`,
1804/// false unblocks it. Returns `Outcome<Vec<BlockedDomain>>`, the list now.
1805#[derive(Debug, Serialize, Deserialize)]
1806pub struct AdminBlockDomainArgs {
1807 pub domain: String,
1808 pub block: bool,
1809 #[serde(default)]
1810 pub reason: String,
1811 pub staff: String,
1812}
1813
1814// --- Shared invite links ---
1815//
1816// Before registration opened, staff handed groups shared invite links.
1817// None are made or used any more; staff still see which one an account
1818// was made with.
1819
1820/// The shared invite link an account was made with.
1821#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1822pub struct SharedInviteSource {
1823 pub id: String,
1824 pub label: String,
1825}
1826
1827#[cfg(test)]
1828mod deletion_tests {
1829 use super::{WorkspaceDeletion, protected_names};
1830
1831 #[test]
1832 fn only_billing_or_protection_stands_in_the_way() {
1833 let clear = WorkspaceDeletion {
1834 repositories: 2,
1835 projects: 1,
1836 members: 3,
1837 ..WorkspaceDeletion::default()
1838 };
1839 assert!(!clear.blocked());
1840 assert_eq!(clear.reason("acme"), None);
1841 let owing = WorkspaceDeletion {
1842 billing: Some("Pay first.".into()),
1843 ..WorkspaceDeletion::default()
1844 };
1845 assert!(owing.blocked());
1846 assert_eq!(owing.reason("acme").as_deref(), Some("Pay first."));
1847 let protected = WorkspaceDeletion {
1848 billing: Some("Pay first.".into()),
1849 protected: true,
1850 ..WorkspaceDeletion::default()
1851 };
1852 assert!(protected.blocked());
1853 assert_eq!(
1854 protected.reason("flagon-io").as_deref(),
1855 Some("flagon-io is protected and can never be deleted.")
1856 );
1857 }
1858
1859 #[test]
1860 fn flagon_is_protected_whatever_the_variable_says() {
1861 assert_eq!(protected_names(None), ["flagon-io"]);
1862 assert_eq!(protected_names(Some("")), ["flagon-io"]);
1863 assert_eq!(protected_names(Some(" , ")), ["flagon-io"]);
1864 assert_eq!(
1865 protected_names(Some("Flagon-IO, acme ,wsp_1")),
1866 ["flagon-io", "acme", "wsp_1"]
1867 );
1868 }
1869}