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.

1,895 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/// `admin_growth` takes `{}` and returns `AdminGrowth`: how many people
996/// and workspaces there are, and how many are new. Deleted ones are not
997/// counted. Staff only.
998#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
999pub struct AdminGrowth {
1000 pub people: GrowthCount,
1001 pub workspaces: GrowthCount,
1002}
1003
1004/// One count for [`AdminGrowth`], with what is new in it.
1005#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
1006#[serde(rename_all = "camelCase")]
1007pub struct GrowthCount {
1008 pub total: u32,
1009 /// Created in the last 24 hours.
1010 pub day: u32,
1011 /// Created in the last 7 days.
1012 pub week: u32,
1013 /// Created in the 7 days before those.
1014 pub prior_week: u32,
1015 /// The newest one's username or slug.
1016 pub newest: Option<String>,
1017 /// When the newest one was created. RFC 3339.
1018 pub newest_at: Option<String>,
1019}
1020
1021/// An owner of a workspace, as staff see them.
1022#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1023pub struct AdminOwner {
1024 pub username: String,
1025 pub email: Option<String>,
1026}
1027
1028/// A workspace as staff see it: who owns it and how many belong to it.
1029#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1030#[serde(rename_all = "camelCase")]
1031pub struct AdminWorkspace {
1032 pub slug: String,
1033 pub name: String,
1034 /// RFC 3339.
1035 pub created_at: String,
1036 pub owners: Vec<AdminOwner>,
1037 pub member_count: u32,
1038}
1039
1040/// `admin_workspace`: one workspace with every member, or null. Takes
1041/// `SlugArgs`; returns `Option<AdminWorkspaceDetail>`. Staff only.
1042#[derive(Clone, Debug, Serialize, Deserialize)]
1043#[serde(rename_all = "camelCase")]
1044pub struct AdminWorkspaceDetail {
1045 pub slug: String,
1046 pub name: String,
1047 pub description: Option<String>,
1048 /// RFC 3339.
1049 pub created_at: String,
1050 /// Owners first, then by username.
1051 pub members: Vec<AdminMember>,
1052 /// It can never be deleted ([`protected_names`]).
1053 #[serde(default)]
1054 pub protected: bool,
1055 /// Set while staff have it suspended.
1056 #[serde(default)]
1057 pub suspended: Option<Suspension>,
1058}
1059
1060/// A member of a workspace, as staff see them.
1061#[derive(Clone, Debug, Serialize, Deserialize)]
1062pub struct AdminMember {
1063 pub username: String,
1064 pub email: Option<String>,
1065 pub role: crate::Role,
1066 /// When they joined the workspace. RFC 3339.
1067 pub joined: String,
1068}
1069
1070// --- Profiles ------------------------------------------------------------
1071//
1072// A person's public page at `g1t.sh/u/<username>`. Everything in a
1073// `Profile` is shown to anyone, signed in or not; an email address never is.
1074
1075/// The most characters each profile field takes.
1076pub const MAX_PROFILE_NAME: usize = 80;
1077pub const MAX_PROFILE_BIO: usize = 160;
1078pub const MAX_PROFILE_LOCATION: usize = 80;
1079pub const MAX_PROFILE_WEBSITE: usize = 200;
1080pub const MAX_PROFILE_PRONOUNS: usize = 40;
1081pub const MAX_PROFILE_TIMEZONE: usize = 64;
1082
1083/// What anyone may see about a person.
1084#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1085#[serde(rename_all = "camelCase")]
1086pub struct Profile {
1087 /// Lowercased: what the profile is found and linked by.
1088 pub username: String,
1089 /// The username as its owner wrote it, when that differs: what the page shows.
1090 #[serde(default, skip_serializing_if = "Option::is_none")]
1091 pub display_username: Option<String>,
1092 /// The name they go by, if they gave one.
1093 pub name: Option<String>,
1094 /// One or two lines about them, at most [`MAX_PROFILE_BIO`] characters.
1095 pub bio: Option<String>,
1096 pub location: Option<String>,
1097 /// An `https://` address.
1098 pub website: Option<String>,
1099 pub pronouns: Option<String>,
1100 /// The time zone they are in, an IANA name such as `America/Denver`.
1101 #[serde(default)]
1102 pub timezone: Option<String>,
1103 /// The uploaded avatar's hash, served at `/avatars/<avatar>`.
1104 pub avatar: Option<String>,
1105 /// When the account was made. RFC 3339.
1106 pub created_at: String,
1107}
1108
1109// `profile` takes `UsernameArgs` and returns `Option<Profile>`: null for
1110// an account that does not exist.
1111
1112/// `update_profile`: a person changes their own profile. Every field is
1113/// replaced; an empty one is cleared. Returns `Outcome<Profile>`.
1114#[derive(Debug, Default, Serialize, Deserialize)]
1115#[serde(rename_all = "camelCase")]
1116pub struct UpdateProfileArgs {
1117 pub actor: User,
1118 #[serde(default)]
1119 pub name: String,
1120 #[serde(default)]
1121 pub bio: String,
1122 #[serde(default)]
1123 pub location: String,
1124 #[serde(default)]
1125 pub website: String,
1126 #[serde(default)]
1127 pub pronouns: String,
1128 /// An IANA time zone name, such as `America/Denver`.
1129 #[serde(default)]
1130 pub timezone: String,
1131}
1132
1133/// `profile_workspaces`: the workspaces shown on a person's profile, as
1134/// `viewer` may see them. A membership is shown only when it is no secret
1135/// from the viewer: a workspace the viewer belongs to as well, or one of
1136/// `public`, the workspaces the caller found the person has made a public
1137/// project in (whose page shows that already). Returns
1138/// `Vec<ProfileWorkspace>`; empty for an account that does not exist.
1139#[derive(Debug, Serialize, Deserialize)]
1140pub struct ProfileWorkspacesArgs {
1141 pub username: String,
1142 pub viewer: crate::Viewer,
1143 #[serde(default)]
1144 pub public: Vec<String>,
1145}
1146
1147/// A workspace on a person's profile.
1148#[derive(Clone, Debug, Serialize, Deserialize)]
1149pub struct ProfileWorkspace {
1150 pub slug: String,
1151 pub name: String,
1152 pub avatar: Option<String>,
1153}
1154
1155// --- Dock pins -------------------------------------------------------------
1156//
1157// The apps a person pins to their dock in a workspace, kept with their
1158// account so the dock follows them to every device. Each person's own:
1159// nobody else reads or sets them.
1160
1161/// The most apps a person pins in one workspace.
1162pub const MAX_DOCK_PINS: usize = 24;
1163/// The most characters an app key takes.
1164pub const MAX_DOCK_APP_KEY: usize = 32;
1165
1166/// `dock_pins`: the apps `user` pinned in the workspace `workspace` (a
1167/// slug), in the order they set. Returns `Option<Vec<String>>`: null when
1168/// they never saved any there, or are not one of its members.
1169#[derive(Debug, Default, Serialize, Deserialize)]
1170#[serde(rename_all = "camelCase")]
1171pub struct DockPinsArgs {
1172 pub user: User,
1173 pub workspace: String,
1174}
1175
1176/// `set_dock_pins`: replaces `user`'s pins in `workspace` with `apps`, in
1177/// that order. Each key is lowercase letters, digits and hyphens, at most
1178/// [`MAX_DOCK_APP_KEY`] characters; a repeat is dropped; at most
1179/// [`MAX_DOCK_PINS`]. Which keys name real apps is the web app's to say.
1180/// Returns `Outcome<Vec<String>>`: the pins as saved.
1181#[derive(Debug, Default, Serialize, Deserialize)]
1182#[serde(rename_all = "camelCase")]
1183pub struct SetDockPinsArgs {
1184 pub user: User,
1185 pub workspace: String,
1186 #[serde(default)]
1187 pub apps: Vec<String>,
1188}
1189
1190// --- Getting started in a workspace ----------------------------------------
1191//
1192// The setup guide a workspace's owners see on its Home until they finish
1193// or dismiss it: adding an AI provider, Ask's model, bringing code,
1194// connecting a harness, inviting people and a runner. Whether each step is
1195// done is read from the workspace itself (its providers, repositories,
1196// members, runners), never kept here; identity keeps only what the person
1197// chose: that they dismissed it, and the steps they skipped. Each person's
1198// own, per workspace. Mirrors `Onboarding` in
1199// packages/contracts/src/identity.ts.
1200
1201/// The steps of the guide, in order. `ask`, `people` and `runner` can be
1202/// skipped; the rest are what a workspace needs to get going.
1203pub const ONBOARDING_STEPS: [&str; 6] = ["ai", "ask", "code", "harness", "people", "runner"];
1204
1205/// A person's own state of the guide in one workspace, as kept and as
1206/// answered. Wire fields are snake_case, as the API's are.
1207#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1208pub struct Onboarding {
1209 /// When they dismissed it, so it no longer opens by itself; null while
1210 /// it still does. Opening it again from Settings or the AI page leaves
1211 /// this as it is.
1212 #[serde(default)]
1213 pub dismissed_at: Option<String>,
1214 /// The steps they chose to skip, in [`ONBOARDING_STEPS`] order: shown
1215 /// as skipped rather than to do, and not counted against finishing.
1216 #[serde(default)]
1217 pub skipped: Vec<String>,
1218 /// When they last changed it; null when they never have.
1219 #[serde(default)]
1220 pub updated_at: Option<String>,
1221}
1222
1223/// A change to it: only what is sent changes. `dismissed` true dismisses
1224/// it now (a second dismissal keeps the first time), false brings it back
1225/// to opening by itself. `skipped` replaces the skipped steps.
1226#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1227pub struct OnboardingChange {
1228 #[serde(default)]
1229 pub dismissed: Option<bool>,
1230 #[serde(default)]
1231 pub skipped: Option<Vec<String>>,
1232}
1233
1234/// `onboarding`: `user`'s own state of the guide in the workspace
1235/// `workspace` (a slug). Returns `Outcome<Onboarding>`: the defaults (not
1236/// dismissed, nothing skipped) when they never changed it, `not_found`
1237/// when they are not one of its members. People only.
1238#[derive(Debug, Default, Serialize, Deserialize)]
1239#[serde(rename_all = "camelCase")]
1240pub struct OnboardingArgs {
1241 pub user: User,
1242 pub workspace: String,
1243}
1244
1245/// `set_onboarding`: changes `user`'s own state of the guide in
1246/// `workspace`. Returns `Outcome<Onboarding>`: as kept, or `invalid` for a
1247/// step the guide does not have.
1248#[derive(Debug, Default, Serialize, Deserialize)]
1249#[serde(rename_all = "camelCase")]
1250pub struct SetOnboardingArgs {
1251 pub user: User,
1252 pub workspace: String,
1253 #[serde(default)]
1254 pub change: OnboardingChange,
1255}
1256
1257// --- Sounds and desktop notifications --------------------------------------
1258//
1259// What a person hears when chat moves, kept with their account so a phone,
1260// a laptop and the desktop app all sound the same. Which sound plays when
1261// is the web app's rule (apps/web/app/lib/chat-sounds.ts); identity keeps
1262// the choices. Do not disturb is not here: it is the person's presence
1263// (`dnd_until`, services/notify), which also silences pop-ups and pushes.
1264// Mirrors `SoundSettings` in packages/contracts/src/identity.ts.
1265
1266/// The sets of sounds a person can choose from.
1267pub const SOUND_SETS: [&str; 2] = ["soft", "bright"];
1268/// The cues a person can turn on and off. `call` is reserved and has no setting.
1269pub const SOUND_CUES: [&str; 4] = ["message", "direct", "mention", "sent"];
1270/// Cues that no longer play: `agent_done`, from g1t's retired hosted
1271/// agents. Saved settings that name one still read, without it, and a
1272/// change that names one leaves it out rather than failing.
1273pub const RETIRED_SOUND_CUES: [&str; 1] = ["agent_done"];
1274/// Before anyone changes them: every cue but the tick as you send.
1275pub const SOUND_CUES_OFF_BY_DEFAULT: [&str; 1] = ["sent"];
1276pub const DEFAULT_SOUND_SET: &str = "soft";
1277pub const DEFAULT_SOUND_VOLUME: u8 = 60;
1278
1279/// A person's sound settings, as kept and as answered. Wire fields are
1280/// snake_case, as the site's JSON is.
1281#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1282pub struct SoundSettings {
1283 /// Whether anything plays at all.
1284 pub sounds_enabled: bool,
1285 /// One of [`SOUND_SETS`].
1286 pub sound_set: String,
1287 /// 0 to 100.
1288 pub sound_volume: u8,
1289 /// Each cue on or off, by name; a cue left out is on, except `sent`.
1290 #[serde(default)]
1291 pub sound_cues: std::collections::BTreeMap<String, bool>,
1292 /// Whether an open tab shows a system notification for a message to
1293 /// you while its window is not in front.
1294 pub desktop_toasts: bool,
1295}
1296
1297impl Default for SoundSettings {
1298 fn default() -> Self {
1299 SoundSettings {
1300 sounds_enabled: true,
1301 sound_set: DEFAULT_SOUND_SET.to_owned(),
1302 sound_volume: DEFAULT_SOUND_VOLUME,
1303 sound_cues: SOUND_CUES
1304 .iter()
1305 .map(|cue| ((*cue).to_owned(), !SOUND_CUES_OFF_BY_DEFAULT.contains(cue)))
1306 .collect(),
1307 desktop_toasts: false,
1308 }
1309 }
1310}
1311
1312/// A change to them: only what is sent changes; `sound_cues` merges by cue.
1313#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1314pub struct SoundSettingsChange {
1315 #[serde(default)]
1316 pub sounds_enabled: Option<bool>,
1317 #[serde(default)]
1318 pub sound_set: Option<String>,
1319 #[serde(default)]
1320 pub sound_volume: Option<i64>,
1321 #[serde(default)]
1322 pub sound_cues: Option<std::collections::BTreeMap<String, bool>>,
1323 #[serde(default)]
1324 pub desktop_toasts: Option<bool>,
1325}
1326
1327/// `sound_settings`: `user`'s own, or the defaults when they never changed
1328/// them. Returns `SoundSettings`. People only.
1329#[derive(Debug, Default, Serialize, Deserialize)]
1330#[serde(rename_all = "camelCase")]
1331pub struct SoundSettingsArgs {
1332 pub user: User,
1333}
1334
1335/// `set_sound_settings`: changes `user`'s own. Returns
1336/// `Outcome<SoundSettings>`: the settings as kept, or `invalid` for a set
1337/// or cue g1t does not have, or a volume outside 0 to 100.
1338#[derive(Debug, Default, Serialize, Deserialize)]
1339#[serde(rename_all = "camelCase")]
1340pub struct SetSoundSettingsArgs {
1341 pub user: User,
1342 #[serde(default)]
1343 pub change: SoundSettingsChange,
1344}
1345
1346/// `directory`: every account or every workspace, as their public pages
1347/// show them, a page at a time in name order. For services that index
1348/// them, such as search; nothing private is in it. Returns
1349/// `DirectoryPage`.
1350#[derive(Debug, Default, Serialize, Deserialize)]
1351pub struct DirectoryArgs {
1352 /// `user` or `workspace`.
1353 pub kind: String,
1354 /// Names after this one.
1355 #[serde(default)]
1356 pub after: Option<String>,
1357 pub limit: u32,
1358}
1359
1360/// One account or workspace in the directory.
1361#[derive(Clone, Debug, Serialize, Deserialize)]
1362#[serde(rename_all = "camelCase")]
1363pub struct DirectoryEntry {
1364 /// The account's or workspace's id.
1365 pub id: String,
1366 /// A username or a workspace's slug.
1367 pub slug: String,
1368 /// A person's display name or a workspace's name.
1369 pub name: Option<String>,
1370 /// A person's bio or a workspace's description.
1371 pub bio: Option<String>,
1372 pub avatar: Option<String>,
1373 /// RFC 3339.
1374 pub created_at: String,
1375}
1376
1377#[derive(Clone, Debug, Default, Serialize, Deserialize)]
1378pub struct DirectoryPage {
1379 pub entries: Vec<DirectoryEntry>,
1380 /// Where the next page starts; null on the last.
1381 pub next: Option<String>,
1382}
1383
1384// --- Invites ---------------------------------------------------------------
1385//
1386// An invitation into a workspace or onto a repository, sent to an address
1387// without an account, carries an invite code: registering with it applies
1388// the invitation once the address is confirmed. Anyone may register
1389// without one. See services/identity/src/invites.rs.
1390//
1391// Any person may also invite a friend to g1t by email ("Invite a friend",
1392// `create_invite`): word of mouth, never a gate. Each person has
1393// `INVITES_PER_USER` of those for good; one revoked or expired before it
1394// was used comes back, one used is spent. See
1395// services/identity/src/invites/friends.rs.
1396
1397/// How long an invite works, unless identity's `INVITE_TTL_DAYS` var says
1398/// otherwise.
1399pub const INVITE_TTL_DAYS: u64 = 30;
1400
1401/// How many friends one person may invite to g1t, unless identity's
1402/// `INVITES_PER_USER` var says otherwise. Staff may grant more.
1403pub const INVITES_PER_USER: u32 = 20;
1404
1405/// Where an invite stands. Only a pending invite can be used. A pending
1406/// invite can be revoked, and so can one awaiting confirmation.
1407#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1408#[serde(rename_all = "snake_case")]
1409pub enum InviteStatus {
1410 Pending,
1411 /// Used to make an account that has not confirmed its email address
1412 /// yet. The code is spent; the workspace (or repository) it gives is
1413 /// joined when the address is confirmed, unless it is revoked first.
1414 AwaitingConfirmation,
1415 /// Used to make an account that has confirmed its address, for a
1416 /// workspace it has not yet joined or declined: the workspace
1417 /// invitation waits for the person's answer (`accept_invitation`).
1418 AwaitingAnswer,
1419 Redeemed,
1420 /// Its person declined the workspace it invited them to.
1421 Declined,
1422 Expired,
1423 Revoked,
1424}
1425
1426/// What using an invite does.
1427#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
1428#[serde(rename_all = "snake_case")]
1429pub enum InviteKind {
1430 /// Makes a new account, and joins `workspace` when one is set.
1431 Account,
1432 /// An existing account joins `workspace`. Never makes an account.
1433 Workspace,
1434}
1435
1436/// Whose invites an invite used.
1437#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1438#[serde(rename_all = "snake_case")]
1439pub enum InviteCharge {
1440 /// Its inviter's own: an invite to g1t made with Invite a friend.
1441 User,
1442 /// A workspace's, granted by staff before registration opened. Read
1443 /// only: none are made any more.
1444 Workspace,
1445 /// Nobody's: an invitation into a workspace or onto a repository, or
1446 /// one staff made.
1447 #[default]
1448 None,
1449}
1450
1451/// One invite, as the person who made it sees it.
1452#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1453#[serde(rename_all = "camelCase")]
1454pub struct Invite {
1455 pub id: String,
1456 /// The code, such as `g1t-k7m2-q9xd-…`: returned once when the invite
1457 /// is made, and afterwards to whoever made it while it is pending.
1458 /// Null otherwise.
1459 pub code: Option<String>,
1460 /// The code's first group, such as `g1t-k7m2`, to recognise it by.
1461 pub hint: String,
1462 /// Only an account with this address can use it. Null: anyone with
1463 /// the code.
1464 pub email: Option<String>,
1465 pub kind: InviteKind,
1466 /// The workspace it joins, by slug.
1467 pub workspace: Option<String>,
1468 pub status: InviteStatus,
1469 /// Whose invites it used: `user` for an invite to g1t from Invite a
1470 /// friend, which counts against its inviter's.
1471 #[serde(default)]
1472 pub charged_to: InviteCharge,
1473 /// Who made it, by username. Null when g1t staff did.
1474 pub invited_by: Option<String>,
1475 /// The account that used it, by username.
1476 pub redeemed_by: Option<String>,
1477 /// RFC 3339.
1478 pub created_at: String,
1479 /// RFC 3339.
1480 pub expires_at: String,
1481 /// RFC 3339.
1482 pub redeemed_at: Option<String>,
1483 /// RFC 3339.
1484 pub revoked_at: Option<String>,
1485 /// The account a workspace invitation is for, by username: someone
1486 /// invited by username, or the account the invite made.
1487 #[serde(default)]
1488 pub invitee: Option<String>,
1489 /// The role `workspace` is joined with. Null when it names none.
1490 #[serde(default)]
1491 pub role: Option<crate::Role>,
1492 /// The staff member who minted it. Only in staff views.
1493 #[serde(default, skip_serializing_if = "Option::is_none")]
1494 pub staff: Option<String>,
1495}
1496
1497/// How many friends a person may invite to g1t, and how many they have.
1498#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1499pub struct Allowance {
1500 /// [`INVITES_PER_USER`] (or identity's var) plus what staff granted.
1501 pub limit: u32,
1502 /// Pending and used invites; revoked and expired ones never used are
1503 /// not counted.
1504 pub used: u32,
1505 pub remaining: u32,
1506}
1507
1508impl Allowance {
1509 pub fn new(limit: u32, used: u32) -> Allowance {
1510 Allowance { limit, used, remaining: limit.saturating_sub(used) }
1511 }
1512
1513 pub fn exhausted(&self) -> bool {
1514 self.remaining == 0
1515 }
1516}
1517
1518/// `list_invites` (takes `UserArgs`): the invites to g1t a person made,
1519/// newest first, and how many they have left. Returns `InvitesOverview`.
1520#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1521pub struct InvitesOverview {
1522 pub allowance: Allowance,
1523 pub invites: Vec<Invite>,
1524}
1525
1526/// `create_invite`: a person invites a friend to g1t by email. Anyone may
1527/// sign up without one; the invite is a note from a friend, with a link
1528/// that opens sign-up with the address filled in and, from the email,
1529/// confirmed. People only, never an agent or a workspace's token, and not
1530/// before their own address is confirmed. Uses one of the person's
1531/// invites. Refused with `Conflict` when the address has a g1t account or
1532/// the person already has a pending invite for it (neither costs one), and
1533/// `Limit` when none are left. Returns `Outcome<Invite>`, with the code.
1534///
1535/// `revoke_invite` (takes `RemoveArgs`): its maker revokes a pending
1536/// invite (or a workspace's owner one made for the workspace); one that
1537/// was not used comes back. Returns `Outcome<Invite>`.
1538///
1539/// `resend_invite` (takes `RemoveArgs`): its maker sends a pending invite
1540/// to g1t again, the same email to the same address. Returns
1541/// `Outcome<Invite>`; one that is not pending answers `Conflict`.
1542#[derive(Debug, Serialize, Deserialize)]
1543pub struct CreateInviteArgs {
1544 pub user: User,
1545 pub email: String,
1546 /// A note from whoever invites, quoted in the email. Up to
1547 /// [`MAX_INVITE_MESSAGE`] characters; longer is cut, blank is none.
1548 #[serde(default)]
1549 pub message: Option<String>,
1550 /// Also invite them to this workspace, by slug: one the person owns,
1551 /// on a paid plan (a free one is refused with `PaymentRequired`). Once
1552 /// the account is confirmed it gets a workspace invitation to accept or
1553 /// decline, and no workspace of its own is made for it.
1554 #[serde(default)]
1555 pub join: Option<String>,
1556 /// The role `join` invites them with; member when absent. Ignored
1557 /// without `join`.
1558 #[serde(default)]
1559 pub join_role: Option<crate::Role>,
1560 /// Where the request came in, for the audit log; g1t.sh when absent.
1561 #[serde(default)]
1562 pub surface: Option<crate::audit::Surface>,
1563}
1564
1565/// `check_invite`: what an invite code is for, before using it. Returns
1566/// `Outcome<InvitePreview>`; a code that is unknown, used, revoked or
1567/// expired gets the same answer, so codes cannot be probed. With
1568/// `any_status`, a real code that can no longer be used is described
1569/// instead (its `status` says why), so the page can say whom to ask for a
1570/// new one; an unknown code still gets the one answer.
1571#[derive(Debug, Serialize, Deserialize)]
1572pub struct InviteCodeArgs {
1573 pub code: String,
1574 /// Who is asking, such as the visitor's IP address, for rate limits.
1575 #[serde(default)]
1576 pub client: Option<String>,
1577 /// Who is looking, if signed in: sets `InvitePreview::for_viewer`.
1578 #[serde(default)]
1579 pub viewer: Option<User>,
1580 #[serde(default)]
1581 pub any_status: bool,
1582 /// The `proof` from the invite email's link, if the page was opened
1583 /// from it: sets `InvitePreview::email_proven`.
1584 #[serde(default)]
1585 pub email_proof: Option<String>,
1586}
1587
1588/// Someone shown on an invite.
1589#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1590pub struct InviteFrom {
1591 pub username: String,
1592 pub name: Option<String>,
1593 pub avatar: Option<String>,
1594}
1595
1596/// A repository an invite code was sent with: using the code accepts the
1597/// invitation to collaborate on it.
1598#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1599pub struct InviteRepository {
1600 /// `workspace/repo`.
1601 pub name: String,
1602 /// The role it gives, such as `write`.
1603 pub role: String,
1604}
1605
1606/// What a valid invite code is for.
1607#[derive(Clone, Debug, Serialize, Deserialize)]
1608#[serde(rename_all = "camelCase")]
1609pub struct InvitePreview {
1610 pub kind: InviteKind,
1611 /// Pending, unless `any_status` asked about a code that is spent.
1612 pub status: InviteStatus,
1613 /// Null when g1t staff sent it.
1614 pub invited_by: Option<InviteFrom>,
1615 pub workspace: Option<ProfileWorkspace>,
1616 /// The repository it accepts an invitation to, if it was sent with one.
1617 pub repository: Option<InviteRepository>,
1618 /// The address it is for, partly hidden, such as `a•••@example.com`.
1619 pub email: Option<String>,
1620 /// The address in full, while it is pending: whoever holds the code
1621 /// was sent it there. Fills in and locks the sign-up form.
1622 pub address: Option<String>,
1623 /// Whether the address it is for has a g1t account already, so the
1624 /// page asks them to sign in rather than sign up.
1625 pub has_account: bool,
1626 /// With a viewer: whether the invite is theirs (it is for one of their
1627 /// confirmed addresses, or they used it). Null without a viewer or,
1628 /// for a pending invite, when it is for anyone with the code.
1629 pub for_viewer: Option<bool>,
1630 /// RFC 3339.
1631 pub expires_at: String,
1632 /// Whether `email_proof` was this pending invite's own, from the email
1633 /// it was sent in: the account made with it starts with `address`
1634 /// confirmed. False without a proof, with a wrong one, and for an
1635 /// invite bound to no address.
1636 #[serde(default)]
1637 pub email_proven: bool,
1638}
1639
1640/// `accept_invite`: a signed-in person uses a workspace invite made for
1641/// their confirmed address, and joins the workspace, or an invite sent with
1642/// a repository invitation, and accepts it. Returns `Outcome<String>`: the
1643/// workspace's slug, or `workspace/repo`.
1644#[derive(Debug, Serialize, Deserialize)]
1645pub struct AcceptInviteArgs {
1646 pub user: User,
1647 pub code: String,
1648}
1649
1650/// `invite_member`: an owner invites an email address into a workspace.
1651/// It always makes an invite bound to that address and emails it, so the
1652/// answer never says whether the address has an account. Without one, the
1653/// invite registers and joins in one step. Returns `Outcome<Invite>`, with
1654/// the code.
1655#[derive(Debug, Serialize, Deserialize)]
1656pub struct InviteMemberArgs {
1657 pub actor: User,
1658 pub slug: String,
1659 /// An email address. Give this or `username`.
1660 #[serde(default)]
1661 pub email: String,
1662 /// A g1t username: that account gets a workspace invitation to accept
1663 /// or decline, in its inbox and by email. Nobody joins without saying
1664 /// yes.
1665 #[serde(default)]
1666 pub username: Option<String>,
1667 /// The role they join with; member when absent.
1668 #[serde(default)]
1669 pub role: Option<crate::Role>,
1670 /// A note from whoever invites, quoted in the invitation email. Up to
1671 /// [`MAX_INVITE_MESSAGE`] characters; longer is cut, blank is none.
1672 #[serde(default)]
1673 pub message: Option<String>,
1674 /// Where the request came in, for the audit log; g1t.sh when absent.
1675 #[serde(default)]
1676 pub surface: Option<crate::audit::Surface>,
1677}
1678
1679/// The most characters an invitation's note keeps.
1680pub const MAX_INVITE_MESSAGE: usize = 500;
1681
1682/// A workspace invitation waiting for its person's answer, as they see it.
1683/// `list_invitations` (takes `UserArgs`) returns `Vec<WorkspaceInvitation>`,
1684/// newest first: pending ones only, never expired, revoked or answered.
1685#[derive(Clone, Debug, Serialize, Deserialize)]
1686#[serde(rename_all = "camelCase")]
1687pub struct WorkspaceInvitation {
1688 pub id: String,
1689 pub workspace: ProfileWorkspace,
1690 /// The role accepting joins with.
1691 pub role: crate::Role,
1692 /// Null when g1t staff sent it.
1693 pub invited_by: Option<InviteFrom>,
1694 /// RFC 3339.
1695 pub created_at: String,
1696 /// RFC 3339.
1697 pub expires_at: String,
1698}
1699
1700/// `accept_invitation`: the person it is for joins the workspace with the
1701/// role it names. Returns `Outcome<String>`, the workspace's slug.
1702///
1703/// `decline_invitation`: they say no; whoever sent it is told in their
1704/// inbox. Returns `Outcome<bool>`.
1705#[derive(Debug, Serialize, Deserialize)]
1706pub struct InvitationArgs {
1707 pub user: User,
1708 pub id: String,
1709 /// Where the request came in, for the audit log; g1t.sh when absent.
1710 #[serde(default)]
1711 pub surface: Option<crate::audit::Surface>,
1712}
1713
1714/// `find_people`: accounts whose username starts with `query`, or whose
1715/// name contains it, for picking someone to invite. Only what a profile
1716/// shows: a username, a name and an avatar, never an email address.
1717/// Returns `Vec<InviteFrom>`, at most `limit` (10 at most, 8 when absent).
1718#[derive(Debug, Serialize, Deserialize)]
1719pub struct FindPeopleArgs {
1720 pub query: String,
1721 #[serde(default)]
1722 pub limit: Option<u32>,
1723}
1724
1725/// `workspace_invites` (takes `ListMembersArgs`): a workspace's invites,
1726/// newest first. Owners only. Returns `Outcome<Vec<Invite>>`.
1727///
1728/// `revoke_workspace_invite`: owners only. Returns `Outcome<Invite>`.
1729///
1730/// `resend_workspace_invite`: owners only. Sends a pending invitation
1731/// again, by email to the address it is bound to or the invited account's
1732/// confirmed address, and again in that account's inbox. The invitation
1733/// itself is unchanged: same code, same day it stops working. Returns
1734/// `Outcome<Invite>`; one that is not pending answers `409`.
1735#[derive(Debug, Serialize, Deserialize)]
1736pub struct WorkspaceInviteArgs {
1737 pub actor: User,
1738 pub slug: String,
1739 pub id: String,
1740}
1741
1742// --- Invites, staff only ---
1743
1744/// The most rows one staff listing of invites returns.
1745pub const ADMIN_INVITES_LIMIT: usize = 500;
1746
1747/// `admin_invites`: every invite, newest first, at most
1748/// [`ADMIN_INVITES_LIMIT`], optionally only those whose code starts with
1749/// `query`, or whose email, inviter or redeemer contains it, and with
1750/// `to_g1t` only invites to g1t from Invite a friend. Returns
1751/// `Vec<Invite>`.
1752#[derive(Debug, Default, Serialize, Deserialize)]
1753pub struct AdminInvitesArgs {
1754 #[serde(default)]
1755 pub query: Option<String>,
1756 #[serde(default)]
1757 pub to_g1t: bool,
1758}
1759
1760/// `admin_grant_invites`: gives a person (by username) `amount` more
1761/// invites to g1t; a negative amount takes some back. Kept with `note` and
1762/// the staff member. Returns `Outcome<Allowance>`: theirs afterwards.
1763#[derive(Debug, Serialize, Deserialize)]
1764pub struct AdminGrantInvitesArgs {
1765 pub username: String,
1766 pub amount: i32,
1767 #[serde(default)]
1768 pub note: String,
1769 pub staff: String,
1770}
1771
1772/// The most invites one grant gives or takes back.
1773pub const MAX_INVITE_GRANT: i32 = 1000;
1774
1775/// `admin_revoke_invite`: revokes any pending invite. Returns
1776/// `Outcome<Invite>`.
1777#[derive(Debug, Serialize, Deserialize)]
1778pub struct AdminRevokeInviteArgs {
1779 pub id: String,
1780 pub staff: String,
1781}
1782
1783// --- Suspension and blocked email domains, staff only ---
1784//
1785// See services/identity/src/suspension.rs. A suspended account cannot sign
1786// in, and its sessions and tokens stop working at once; a suspended
1787// workspace's own tokens stop working, and sudo also puts a hold on its
1788// compute (billing), which stops its runs, deploys, new self-hosted
1789// runners and telemetry. Both are undone the same way. A blocked email
1790// domain makes no new accounts and confirms no new addresses.
1791
1792/// Why and since when staff suspended an account or a workspace.
1793#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1794#[serde(rename_all = "camelCase")]
1795pub struct Suspension {
1796 pub reason: String,
1797 /// RFC 3339.
1798 pub at: String,
1799 /// The staff member, by email.
1800 pub by: String,
1801}
1802
1803/// `admin_suspend_user` (`name` a username) and `admin_suspend_workspace`
1804/// (`name` a slug): `suspend` true suspends with `reason` (required),
1805/// false lifts it. Returns `Outcome<Option<Suspension>>`: what stands now.
1806#[derive(Debug, Serialize, Deserialize)]
1807pub struct AdminSuspendArgs {
1808 pub name: String,
1809 pub suspend: bool,
1810 #[serde(default)]
1811 pub reason: String,
1812 pub staff: String,
1813}
1814
1815/// An email domain no new account may sign up with.
1816#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1817#[serde(rename_all = "camelCase")]
1818pub struct BlockedDomain {
1819 /// Lowercased, such as `spam.example`. Its subdomains are blocked too.
1820 pub domain: String,
1821 pub reason: String,
1822 pub blocked_by: String,
1823 /// RFC 3339.
1824 pub created_at: String,
1825}
1826
1827/// `admin_blocked_domains` takes `{}` and returns `Vec<BlockedDomain>`.
1828///
1829/// `admin_block_domain`: `block` true blocks `domain` with `reason`,
1830/// false unblocks it. Returns `Outcome<Vec<BlockedDomain>>`, the list now.
1831#[derive(Debug, Serialize, Deserialize)]
1832pub struct AdminBlockDomainArgs {
1833 pub domain: String,
1834 pub block: bool,
1835 #[serde(default)]
1836 pub reason: String,
1837 pub staff: String,
1838}
1839
1840// --- Shared invite links ---
1841//
1842// Before registration opened, staff handed groups shared invite links.
1843// None are made or used any more; staff still see which one an account
1844// was made with.
1845
1846/// The shared invite link an account was made with.
1847#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1848pub struct SharedInviteSource {
1849 pub id: String,
1850 pub label: String,
1851}
1852
1853#[cfg(test)]
1854mod deletion_tests {
1855 use super::{WorkspaceDeletion, protected_names};
1856
1857 #[test]
1858 fn only_billing_or_protection_stands_in_the_way() {
1859 let clear = WorkspaceDeletion {
1860 repositories: 2,
1861 projects: 1,
1862 members: 3,
1863 ..WorkspaceDeletion::default()
1864 };
1865 assert!(!clear.blocked());
1866 assert_eq!(clear.reason("acme"), None);
1867 let owing = WorkspaceDeletion {
1868 billing: Some("Pay first.".into()),
1869 ..WorkspaceDeletion::default()
1870 };
1871 assert!(owing.blocked());
1872 assert_eq!(owing.reason("acme").as_deref(), Some("Pay first."));
1873 let protected = WorkspaceDeletion {
1874 billing: Some("Pay first.".into()),
1875 protected: true,
1876 ..WorkspaceDeletion::default()
1877 };
1878 assert!(protected.blocked());
1879 assert_eq!(
1880 protected.reason("flagon-io").as_deref(),
1881 Some("flagon-io is protected and can never be deleted.")
1882 );
1883 }
1884
1885 #[test]
1886 fn flagon_is_protected_whatever_the_variable_says() {
1887 assert_eq!(protected_names(None), ["flagon-io"]);
1888 assert_eq!(protected_names(Some("")), ["flagon-io"]);
1889 assert_eq!(protected_names(Some(" , ")), ["flagon-io"]);
1890 assert_eq!(
1891 protected_names(Some("Flagon-IO, acme ,wsp_1")),
1892 ["flagon-io", "acme", "wsp_1"]
1893 );
1894 }
1895}