| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (c) 2026 UtopiaIA |
| 3 | |
| 4 | //! Blocks (section 22) and the account's settings (section 3). |
| 5 | //! |
| 6 | //! An account blocks another from every repository it owns; an admin of a |
| 7 | //! repository blocks an account from that one alone. A blocked account |
| 8 | //! still reads what is public, and cannot star, watch, comment, open |
| 9 | //! threads, review or fork there, nor follow whoever blocked it. The lists |
| 10 | //! of blocks are [`UserCards`](crate::cards::UserCards): each account with |
| 11 | //! `since`, when it was blocked. |
| 12 | |
| 13 | use serde::{Deserialize, Serialize}; |
| 14 | |
| 15 | /// The most accounts one account blocks, and the most one repository |
| 16 | /// blocks. |
| 17 | pub const MAX_BLOCKS: usize = 1_000; |
| 18 | |
| 19 | /// Text and data mining allowed: what a new repository starts with unless |
| 20 | /// its owner says otherwise. |
| 21 | pub const TDM_ALLOWED: &str = "allowed"; |
| 22 | |
| 23 | /// Text and data mining reserved by the owner. |
| 24 | pub const TDM_RESERVED: &str = "reserved"; |
| 25 | |
| 26 | /// `PATCH /v1/me`: the settings of the account to change. Those left out |
| 27 | /// stay as they are. |
| 28 | #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] |
| 29 | pub struct MePatch { |
| 30 | /// What text and data mining the account's new repositories start |
| 31 | /// with: [`TDM_ALLOWED`] or [`TDM_RESERVED`]. |
| 32 | #[serde(default, skip_serializing_if = "Option::is_none")] |
| 33 | pub tdm_default: Option<String>, |
| 34 | /// Whether the repositories the account starred show on its profile |
| 35 | /// and in its list of stars to others. |
| 36 | #[serde(default, skip_serializing_if = "Option::is_none")] |
| 37 | pub stars_public: Option<bool>, |
| 38 | } |
| 39 | |
| 40 | #[cfg(test)] |
| 41 | mod tests { |
| 42 | use super::*; |
| 43 | |
| 44 | #[test] |
| 45 | fn a_patch_says_only_what_it_changes() { |
| 46 | let empty = MePatch::default(); |
| 47 | assert_eq!(serde_json::to_string(&empty).unwrap(), "{}"); |
| 48 | let patch: MePatch = serde_json::from_str(r#"{"stars_public":false}"#).unwrap(); |
| 49 | assert_eq!( |
| 50 | patch, |
| 51 | MePatch { |
| 52 | tdm_default: None, |
| 53 | stars_public: Some(false), |
| 54 | } |
| 55 | ); |
| 56 | let both = MePatch { |
| 57 | tdm_default: Some(TDM_RESERVED.into()), |
| 58 | stars_public: Some(true), |
| 59 | }; |
| 60 | let text = serde_json::to_string(&both).unwrap(); |
| 61 | assert_eq!(serde_json::from_str::<MePatch>(&text).unwrap(), both); |
| 62 | assert!(serde_json::from_str::<MePatch>(r#"{"stars_public":"no"}"#).is_err()); |
| 63 | } |
| 64 | } |