drive_v3/objects/content_restriction.rs
1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4use super::User;
5
6/// A restriction for accessing the content of the file.
7///
8/// # Warning:
9///
10/// The field `type` is renamed to `restriction_type` as the word type is a reserved keyword in Rust.
11#[derive(Default, Debug, Clone, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct ContentRestriction {
14 /// Whether the content of the file is read-only.
15 ///
16 /// If a file is read-only, a new revision of the file may not be added, comments may not be added or modified, and the title
17 /// of the file may not be modified.
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub read_only: Option<bool>,
20
21 /// Reason for why the content of the file is restricted.
22 ///
23 /// This is only mutable on requests that also set readOnly=true.
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub reason: Option<String>,
26
27 /// The type of the content restriction. Currently the only possible value is `globalContentRestriction`.
28 #[serde(rename = "type")]
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub restriction_type: Option<String>,
31
32 /// The user who set the content restriction.
33 ///
34 /// Only populated if [`read_only`](ContentRestriction::read_only) is true.
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub restricting_user: Option<User>,
37
38 /// The time at which the content restriction was set (formatted RFC 3339 timestamp).
39 ///
40 /// Only populated if [`read_only`](ContentRestriction::read_only) is true.
41 #[serde(skip_serializing_if = "Option::is_none")]
42 pub restriction_time: Option<String>,
43
44 /// Whether the content restriction can only be modified or removed by a user who owns the file.
45 ///
46 /// For files in shared drives, any user with organizer capabilities can modify or remove this content restriction.
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub owner_restricted: Option<bool>,
49
50 /// Whether the content restriction was applied by the system, for example due to an esignature.
51 ///
52 /// Users cannot modify or remove system restricted content restrictions.
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub system_restricted: Option<bool>,
55}
56
57impl fmt::Display for ContentRestriction {
58 fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
59 let json = serde_json::to_string_pretty(&self)
60 .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
61
62 write!(f, "{}", json)
63 }
64}
65
66impl ContentRestriction {
67 /// Creates a new, empty instance of this struct.
68 pub fn new() -> Self {
69 Self { ..Default::default() }
70 }
71}