drive_v3/objects/permission.rs
1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4/// Details of whether the permissions on this shared drive item are inherited or directly on this item.
5///
6/// This is an output-only
7/// field which is present only for shared drive items.
8#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct PermissionDetails {
11 /// The permission type for this user.
12 ///
13 /// While new values may be added in future, the following are currently
14 /// possible:
15 /// - `file`
16 /// - `member`
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub permission_type: Option<String>,
19
20 /// The ID of the item from which this permission is inherited.
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub inherited_from: Option<String>,
23
24 /// The primary role for this user.
25 ///
26 /// While new values may be added in the future, the following are currently
27 /// possible:
28 /// - `organizer`
29 /// - `fileOrganizer`
30 /// - `writer`
31 /// - `commenter`
32 /// - `reader`
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub role: Option<String>,
35
36 /// Whether this permission is inherited.
37 #[serde(skip_serializing_if = "Option::is_none")]
38 pub inherited: Option<bool>,
39}
40
41impl fmt::Display for PermissionDetails {
42 fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
43 let json = serde_json::to_string_pretty(&self)
44 .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
45
46 write!(f, "{}", json)
47 }
48}
49
50impl PermissionDetails {
51 /// Creates a new, empty instance of this struct.
52 pub fn new() -> Self {
53 Self { ..Default::default() }
54 }
55}
56
57/// A permission for a file.
58///
59/// A permission grants a user, group, domain, or the world access to a file or
60/// a folder hierarchy.
61///
62/// # Warning:
63///
64/// The field `type` is renamed to `permission_type` as the word type is a reserved keyword in Rust.
65#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
66#[serde(rename_all = "camelCase")]
67pub struct Permission {
68 /// The ID of this permission. This is a unique identifier for the grantee, and is published in User resources as
69 /// permissionId. IDs should be treated as opaque values.
70 #[serde(skip_serializing_if = "Option::is_none")]
71 pub id: Option<String>,
72
73 /// The "pretty" name of the value of the permission.
74 ///
75 /// The following is a list of examples for each type of permission:
76 /// - `user`: User's full name, as defined for their Google account, such as "Joe Smith."
77 /// - `group`: Name of the Google Group, such as "The Company Administrators."
78 /// - `domain`: String domain name, such as "company.com."
79 /// - `anyone`: No displayName is present.
80 #[serde(skip_serializing_if = "Option::is_none")]
81 pub display_name: Option<String>,
82
83 /// The type of the grantee.
84 ///
85 /// Valid values are:
86 /// - `user`
87 /// - `group`
88 /// - `domain`
89 /// - `anyone`
90 ///
91 /// When creating a permission, if type is `user` or `group`, you must provide an `emailAddress` for the user or group. When
92 /// type is `domain`, you must provide a domain. There isn't extra information required for an anyone type.
93 /// # Warning:
94 ///
95 /// This field is renamed from `type` as the word type is a reserved keyword in Rust.
96 #[serde(rename = "type")]
97 #[serde(skip_serializing_if = "Option::is_none")]
98 pub permission_type: Option<String>,
99
100 /// Identifies what kind of resource this is. Value: the fixed string "drive#permission".
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub kind: Option<String>,
103
104 /// Details of whether the permissions on this shared drive item are inherited or directly on this item. This is an
105 /// output-only field which is present only for shared drive items.
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub permission_details: Option<Vec<PermissionDetails>>,
108
109 /// A link to the user's profile photo, if available.
110 #[serde(skip_serializing_if = "Option::is_none")]
111 pub photo_link: Option<String>,
112
113 /// The email address of the user or group to which this permission refers.
114 #[serde(skip_serializing_if = "Option::is_none")]
115 pub email_address: Option<String>,
116
117 /// The role granted by this permission.
118 ///
119 /// While new values may be supported in the future, the following are currently allowed:
120 /// - `owner`
121 /// - `organizer`
122 /// - `fileOrganizer`
123 /// - `writer`
124 /// - `commenter`
125 /// - `reader`
126 #[serde(skip_serializing_if = "Option::is_none")]
127 pub role: Option<String>,
128
129 /// Whether the permission allows the file to be discovered through search. This is only applicable for permissions of type
130 /// `domain` or `anyone`.
131 #[serde(skip_serializing_if = "Option::is_none")]
132 pub allow_file_discovery: Option<bool>,
133
134 /// The domain to which this permission refers.
135 #[serde(skip_serializing_if = "Option::is_none")]
136 pub domain: Option<String>,
137
138 /// The time at which this permission will expire (RFC 3339 date-time).
139 ///
140 /// Expiration times have the following restrictions:
141 /// - They can only be set on `user` and `group` permissions.
142 /// - The time must be in the future.
143 /// - The time cannot be more than a year in the future.
144 #[serde(skip_serializing_if = "Option::is_none")]
145 pub expiration_time: Option<String>,
146
147 /// Whether the account associated with this permission has been deleted.
148 ///
149 /// This field only pertains to `user` and `group` permissions.
150 #[serde(skip_serializing_if = "Option::is_none")]
151 pub deleted: Option<bool>,
152
153 /// Indicates the view for this permission.
154 ///
155 /// Only populated for permissions that belong to a view. `published` is the only supported value.
156 #[serde(skip_serializing_if = "Option::is_none")]
157 pub view: Option<String>,
158
159 /// Whether the account associated with this permission is a pending owner.
160 ///
161 /// Only populated for user type permissions for files that are not in a shared drive.
162 #[serde(skip_serializing_if = "Option::is_none")]
163 pub pending_owner: Option<bool>,
164}
165
166#[doc(hidden)]
167impl From<&Self> for Permission {
168 fn from( reference: &Self ) -> Self {
169 reference.clone()
170 }
171}
172
173impl fmt::Display for Permission {
174 fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
175 let json = serde_json::to_string_pretty(&self)
176 .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
177
178 write!(f, "{}", json)
179 }
180}
181
182impl Permission {
183 /// Creates a new, empty instance of this struct.
184 pub fn new() -> Self {
185 Self { ..Default::default() }
186 }
187}
188
189/// A list of permissions for a file.
190#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
191#[serde(rename_all = "camelCase")]
192pub struct PermissionList {
193 /// The page token for the next page of permissions.
194 ///
195 /// This will be absent if the end of the list has been reached. If the
196 /// token is rejected for any reason, it should be discarded, and
197 /// pagination should be restarted from the first page of results. The page
198 /// token is typically valid for several hours. However, if new items are
199 /// added or removed, your expected results might differ.
200 #[serde(skip_serializing_if = "Option::is_none")]
201 pub next_page_token: Option<String>,
202
203 /// Identifies what kind of resource this is.
204 ///
205 /// This is always `drive#permissionList`.
206 #[serde(skip_serializing_if = "Option::is_none")]
207 pub kind: Option<String>,
208
209 /// The list of shared drives.
210 ///
211 /// If [`next_page_token`](PermissionList::next_page_token) is populated,
212 /// then this list may be incomplete and an additional page of results
213 /// should be fetched.
214 #[serde(skip_serializing_if = "Option::is_none")]
215 pub permissions: Option<Vec<Permission>>,
216}
217
218impl fmt::Display for PermissionList {
219 fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
220 let json = serde_json::to_string_pretty(&self)
221 .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
222
223 write!(f, "{}", json)
224 }
225}
226
227impl PermissionList {
228 /// Creates a new, empty instance of this struct.
229 pub fn new() -> Self {
230 Self { ..Default::default() }
231 }
232}