drive_v3/objects/
capabilities.rs

1use std::fmt;
2use serde::{Serialize, Deserialize};
3
4/// Capabilities the current user has on a file.
5///
6/// Each capability corresponds to a fine-grained action that a user may take.
7#[derive(Default, Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct FileCapabilities {
10    /// Whether the current user can move children of this folder outside of the
11    /// shared drive.
12    ///
13    /// This is false when the item is not a folder. Only populated for items
14    /// in shared drives.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub can_move_children_out_of_drive: Option<bool>,
17
18    /// Whether the current user can read the shared drive to which this file
19    /// belongs.
20    ///
21    /// Only populated for items in shared drives.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub can_read_drive: Option<bool>,
24
25    /// Whether the current user can edit this file.
26    ///
27    /// Other factors may limit the type of changes a user can make to a file.
28    /// For example, see
29    /// [`can_change_copy_requires_writer_permission`](FileCapabilities::can_change_copy_requires_writer_permission)
30    /// or [`can_modify_content`](FileCapabilities::can_modify_content).
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub can_edit: Option<bool>,
33
34    /// Whether the current user can copy this file.
35    ///
36    /// For an item in a shared drive, whether the current user can copy
37    /// non-folder descendants of this item, or this item itself if it is not a
38    /// folder.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub can_copy: Option<bool>,
41
42    /// Whether the current user can comment on this file.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub can_comment: Option<bool>,
45
46    /// Whether the current user can add children to this folder.
47    ///
48    /// This is always false when the item is not a folder.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub can_add_children: Option<bool>,
51
52    /// Whether the current user can delete this file.
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub can_delete: Option<bool>,
55
56    /// Whether the current user can download this file.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub can_download: Option<bool>,
59
60    /// Whether the current user can list the children of this folder.
61    ///
62    /// This is always false when the item is not a folder.
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub can_list_children: Option<bool>,
65
66    /// Whether the current user can remove children from this folder.
67    ///
68    /// This is always false when the item is not a folder. For a folder in a
69    /// shared drive, use
70    /// [`can_delete_children`](FileCapabilities::can_delete_children) or
71    /// [`can_trash_children`](FileCapabilities::can_trash_children) instead.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub can_remove_children: Option<bool>,
74
75    /// Whether the current user can rename this file.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub can_rename: Option<bool>,
78
79    /// Whether the current user can move this file to trash.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub can_trash: Option<bool>,
82
83    /// Whether the current user can read the revisions resource of this file.
84    ///
85    /// For a shared drive item, whether revisions of non-folder descendants of
86    /// this item, or this item itself if it is not a folder, can be read.
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub can_read_revisions: Option<bool>,
89
90    /// Whether the current user can change the
91    /// [`copy_requires_writer_permission`](super::File::copy_requires_writer_permission)
92    /// restriction of this file.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub can_change_copy_requires_writer_permission: Option<bool>,
95
96    /// Whether the current user can restore this file from trash.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub can_untrash: Option<bool>,
99
100    /// Whether the current user can modify the content of this file.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub can_modify_content: Option<bool>,
103
104    /// Whether the current user can delete children of this folder.
105    ///
106    /// This is false when the item is not a folder. Only populated for items in
107    /// shared drives.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub can_delete_children: Option<bool>,
110
111    /// Whether the current user can trash children of this folder.
112    ///
113    /// This is false when the item is not a folder. Only populated for items in
114    /// shared drives.
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub can_trash_children: Option<bool>,
117
118    /// Whether the current user can move this item outside of this drive by
119    /// changing its parent.
120    ///
121    /// Note that a request to change the parent of the item may still fail
122    /// depending on the new parent that is being added.
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub can_move_item_out_of_drive: Option<bool>,
125
126    /// Whether the current user can add a parent for the item without removing
127    /// an existing parent in the same request.
128    ///
129    /// Not populated for shared drive files.
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub can_add_my_drive_parent: Option<bool>,
132
133    /// Whether the current user can move this item within this drive.
134    ///
135    /// Note that a request to change the parent of the item may still fail
136    /// depending on the new parent that is being added and the parent that is
137    /// being removed.
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub can_move_item_within_drive: Option<bool>,
140
141    /// Whether the current user can modify the sharing settings for this file.
142    #[serde(skip_serializing_if = "Option::is_none")]
143    pub can_share: Option<bool>,
144
145    /// Whether the current user can move children of this folder within this
146    /// drive.
147    ///
148    /// This is false when the item is not a folder. Note that a request to move
149    /// the child may still fail depending on the current user's access to the
150    /// child and to the destination folder.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub can_move_children_within_drive: Option<bool>,
153
154    /// Whether the current user can add a folder from another drive (different
155    /// shared drive or My Drive) to this folder.
156    ///
157    /// This is false when the item is not a folder. Only populated for items in
158    /// shared drives.
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub can_add_folder_from_another_drive: Option<bool>,
161
162    /// Whether the current user can change the
163    /// [`security_update_enabled`](super::LinkShareMetadata::security_update_enabled)
164    /// field on link share metadata.
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub can_change_security_update_enabled: Option<bool>,
167
168    /// Whether the current user is the pending owner of the file.
169    ///
170    /// Not populated for shared drive files.
171    #[serde(skip_serializing_if = "Option::is_none")]
172    pub can_accept_ownership: Option<bool>,
173
174    /// Whether the current user can read the labels on the file.
175    #[serde(skip_serializing_if = "Option::is_none")]
176    pub can_read_labels: Option<bool>,
177
178    /// Whether the current user can modify the labels on the file.
179    #[serde(skip_serializing_if = "Option::is_none")]
180    pub can_modify_labels: Option<bool>,
181
182    /// Whether the current user can add or modify content restrictions on the
183    /// file which are editor restricted.
184    #[serde(skip_serializing_if = "Option::is_none")]
185    pub can_modify_editor_content_restriction: Option<bool>,
186
187    /// Whether the current user can add or modify content restrictions which
188    /// are owner restricted.
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub can_modify_owner_content_restriction: Option<bool>,
191
192    /// Whether there is a content restriction on the file that can be removed
193    /// by the current user.
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub can_remove_content_restriction: Option<bool>,
196}
197
198impl fmt::Display for FileCapabilities {
199    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
200        let json = serde_json::to_string_pretty(&self)
201            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
202
203        write!(f, "{}", json)
204    }
205}
206
207impl FileCapabilities {
208    /// Creates a new, empty instance of this struct.
209    pub fn new() -> Self {
210        Self { ..Default::default() }
211    }
212}
213
214/// Capabilities the current user has on a shared drive.
215///
216/// Each capability corresponds to a fine-grained action that a user may take.
217#[derive(Default, Debug, Clone, Serialize, Deserialize)]
218#[serde(rename_all = "camelCase")]
219pub struct DriveCapabilities {
220    /// Whether the current user can add children to folders in this shared
221    /// drive.
222    #[serde(skip_serializing_if = "Option::is_none")]
223    pub can_add_children: Option<bool>,
224
225    /// Whether the current user can comment on files in this shared drive.
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub can_comment: Option<bool>,
228
229    /// Whether the current user can copy files in this shared drive.
230    #[serde(skip_serializing_if = "Option::is_none")]
231    pub can_copy: Option<bool>,
232
233    /// Whether the current user can delete this shared drive.
234    ///
235    /// Attempting to delete the shared drive may still fail if there are
236    /// untrashed items inside the shared drive.
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub can_delete_drive: Option<bool>,
239
240    /// Whether the current user can download files in this shared drive.
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub can_download: Option<bool>,
243
244    /// Whether the current user can edit files in this shared drive
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub can_edit: Option<bool>,
247
248    /// Whether the current user can list the children of folders in this shared
249    /// drive.
250    #[serde(skip_serializing_if = "Option::is_none")]
251    pub can_list_children: Option<bool>,
252
253    /// Whether the current user can add members to this shared drive or remove
254    /// them or change their role.
255    #[serde(skip_serializing_if = "Option::is_none")]
256    pub can_manage_members: Option<bool>,
257
258    /// Whether the current user can read the revisions resource of files in
259    /// this shared drive.
260    #[serde(skip_serializing_if = "Option::is_none")]
261    pub can_read_revisions: Option<bool>,
262
263    /// Whether the current user can rename files or folders in this shared
264    /// drive.
265    #[serde(skip_serializing_if = "Option::is_none")]
266    pub can_rename: Option<bool>,
267
268    /// Whether the current user can rename this shared drive.
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub can_rename_drive: Option<bool>,
271
272    /// Whether the current user can change the background of this shared drive.
273    #[serde(skip_serializing_if = "Option::is_none")]
274    pub can_change_drive_background: Option<bool>,
275
276    /// Whether the current user can share files or folders in this shared
277    /// drive.
278    #[serde(skip_serializing_if = "Option::is_none")]
279    pub can_share: Option<bool>,
280
281    /// Whether the current user can change the `copyRequiresWriterPermission`
282    /// restriction of this shared drive.
283    #[serde(skip_serializing_if = "Option::is_none")]
284    pub can_change_copy_requires_writer_permission_restriction: Option<bool>,
285
286    /// Whether the current user can change the `domainUsersOnly` restriction
287    /// of this shared drive.
288    #[serde(skip_serializing_if = "Option::is_none")]
289    pub can_change_domain_users_only_restriction: Option<bool>,
290
291    /// Whether the current user can change the driveMembersOnly restriction of
292    /// this shared drive.
293    #[serde(skip_serializing_if = "Option::is_none")]
294    pub can_change_drive_members_only_restriction: Option<bool>,
295
296    /// Whether the current user can change the
297    /// `sharingFoldersRequiresOrganizerPermission` restriction of this shared
298    /// drive.
299    #[serde(skip_serializing_if = "Option::is_none")]
300    pub can_change_sharing_folders_requires_organizer_permission_restriction: Option<bool>,
301
302    /// Whether the current user can reset the shared drive restrictions to
303    /// defaults.
304    #[serde(skip_serializing_if = "Option::is_none")]
305    pub can_reset_drive_restrictions: Option<bool>,
306
307    /// Whether the current user can delete children from folders in this shared
308    /// drive.
309    #[serde(skip_serializing_if = "Option::is_none")]
310    pub can_delete_children: Option<bool>,
311
312    /// Whether the current user can trash children from folders in this shared
313    /// drive.
314    #[serde(skip_serializing_if = "Option::is_none")]
315    pub can_trash_children: Option<bool>,
316}
317
318impl fmt::Display for DriveCapabilities {
319    fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result {
320        let json = serde_json::to_string_pretty(&self)
321            .unwrap_or( format!("unable to parse JSON, this is the debug view:\n{:#?}", self) );
322
323        write!(f, "{}", json)
324    }
325}
326
327impl DriveCapabilities {
328    /// Creates a new, empty instance of this struct.
329    pub fn new() -> Self {
330        Self { ..Default::default() }
331    }
332}