google_drive/
permissions.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Permissions {
5    pub client: Client,
6}
7
8impl Permissions {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Permissions { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/files/{fileId}/permissions` endpoint.
16     *
17     * Lists a file's or shared drive's permissions.
18     *
19     * **Parameters:**
20     *
21     * * `file_id: &str` -- A link to this theme's background image.
22     * * `include_permissions_for_view: &str` -- Specifies which additional view's permissions to include in the response. Only 'published' is supported.
23     * * `page_size: i64` -- The maximum number of permissions to return per page. When not set for files in a shared drive, at most 100 results will be returned. When not set for files that are not in a shared drive, the entire list will be returned.
24     * * `page_token: &str` -- The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response.
25     * * `supports_all_drives: bool` -- Whether the requesting application supports both My Drives and shared drives.
26     * * `supports_team_drives: bool` -- Whether the user has installed the requesting app.
27     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if the file ID parameter refers to a shared drive and the requester is an administrator of the domain to which the shared drive belongs.
28     */
29    pub async fn list(
30        &self,
31        file_id: &str,
32        include_permissions_for_view: &str,
33        page_size: i64,
34        page_token: &str,
35        supports_all_drives: bool,
36        supports_team_drives: bool,
37        use_domain_admin_access: bool,
38    ) -> ClientResult<crate::Response<Vec<crate::types::Permission>>> {
39        let mut query_args: Vec<(String, String)> = Default::default();
40        if !include_permissions_for_view.is_empty() {
41            query_args.push((
42                "includePermissionsForView".to_string(),
43                include_permissions_for_view.to_string(),
44            ));
45        }
46        if page_size > 0 {
47            query_args.push(("pageSize".to_string(), page_size.to_string()));
48        }
49        if !page_token.is_empty() {
50            query_args.push(("pageToken".to_string(), page_token.to_string()));
51        }
52        if supports_all_drives {
53            query_args.push((
54                "supportsAllDrives".to_string(),
55                supports_all_drives.to_string(),
56            ));
57        }
58        if supports_team_drives {
59            query_args.push((
60                "supportsTeamDrives".to_string(),
61                supports_team_drives.to_string(),
62            ));
63        }
64        if use_domain_admin_access {
65            query_args.push((
66                "useDomainAdminAccess".to_string(),
67                use_domain_admin_access.to_string(),
68            ));
69        }
70        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
71        let url = self.client.url(
72            &format!(
73                "/files/{}/permissions?{}",
74                crate::progenitor_support::encode_path(file_id),
75                query_
76            ),
77            None,
78        );
79        let resp: crate::Response<crate::types::PermissionList> = self
80            .client
81            .get(
82                &url,
83                crate::Message {
84                    body: None,
85                    content_type: None,
86                },
87            )
88            .await?;
89
90        // Return our response data.
91        Ok(crate::Response::new(
92            resp.status,
93            resp.headers,
94            resp.body.permissions.to_vec(),
95        ))
96    }
97    /**
98     * This function performs a `GET` to the `/files/{fileId}/permissions` endpoint.
99     *
100     * As opposed to `list`, this function returns all the pages of the request at once.
101     *
102     * Lists a file's or shared drive's permissions.
103     */
104    pub async fn list_all(
105        &self,
106        file_id: &str,
107        include_permissions_for_view: &str,
108        supports_all_drives: bool,
109        supports_team_drives: bool,
110        use_domain_admin_access: bool,
111    ) -> ClientResult<crate::Response<Vec<crate::types::Permission>>> {
112        let mut query_args: Vec<(String, String)> = Default::default();
113        if !include_permissions_for_view.is_empty() {
114            query_args.push((
115                "includePermissionsForView".to_string(),
116                include_permissions_for_view.to_string(),
117            ));
118        }
119        if supports_all_drives {
120            query_args.push((
121                "supportsAllDrives".to_string(),
122                supports_all_drives.to_string(),
123            ));
124        }
125        if supports_team_drives {
126            query_args.push((
127                "supportsTeamDrives".to_string(),
128                supports_team_drives.to_string(),
129            ));
130        }
131        if use_domain_admin_access {
132            query_args.push((
133                "useDomainAdminAccess".to_string(),
134                use_domain_admin_access.to_string(),
135            ));
136        }
137        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
138        let url = self.client.url(
139            &format!(
140                "/files/{}/permissions?{}",
141                crate::progenitor_support::encode_path(file_id),
142                query_
143            ),
144            None,
145        );
146        let crate::Response::<crate::types::PermissionList> {
147            mut status,
148            mut headers,
149            mut body,
150        } = self
151            .client
152            .get(
153                &url,
154                crate::Message {
155                    body: None,
156                    content_type: None,
157                },
158            )
159            .await?;
160
161        let mut permissions = body.permissions;
162        let mut page = body.next_page_token;
163
164        // Paginate if we should.
165        while !page.is_empty() {
166            if !url.contains('?') {
167                crate::Response::<crate::types::PermissionList> {
168                    status,
169                    headers,
170                    body,
171                } = self
172                    .client
173                    .get(
174                        &format!("{}?pageToken={}", url, page),
175                        crate::Message {
176                            body: None,
177                            content_type: None,
178                        },
179                    )
180                    .await?;
181            } else {
182                crate::Response::<crate::types::PermissionList> {
183                    status,
184                    headers,
185                    body,
186                } = self
187                    .client
188                    .get(
189                        &format!("{}&pageToken={}", url, page),
190                        crate::Message {
191                            body: None,
192                            content_type: None,
193                        },
194                    )
195                    .await?;
196            }
197
198            permissions.append(&mut body.permissions);
199
200            if !body.next_page_token.is_empty() && body.next_page_token != page {
201                page = body.next_page_token.to_string();
202            } else {
203                page = "".to_string();
204            }
205        }
206
207        // Return our response data.
208        Ok(crate::Response::new(status, headers, permissions))
209    }
210    /**
211     * This function performs a `POST` to the `/files/{fileId}/permissions` endpoint.
212     *
213     * Creates a permission for a file or shared drive.
214     *
215     * **Parameters:**
216     *
217     * * `file_id: &str` -- A link to this theme's background image.
218     * * `email_message: &str` -- A plain text custom message to include in the notification email.
219     * * `enforce_single_parent: bool` -- Whether the user has installed the requesting app.
220     * * `move_to_new_owners_root: bool` -- This parameter will only take effect if the item is not in a shared drive and the request is attempting to transfer the ownership of the item. If set to true, the item will be moved to the new owner's My Drive root folder and all prior parents removed. If set to false, parents are not changed.
221     * * `send_notification_email: bool` -- Whether to send a notification email when sharing to users or groups. This defaults to true for users and groups, and is not allowed for other requests. It must not be disabled for ownership transfers.
222     * * `supports_all_drives: bool` -- Whether the requesting application supports both My Drives and shared drives.
223     * * `supports_team_drives: bool` -- Whether the user has installed the requesting app.
224     * * `transfer_ownership: bool` -- Whether to transfer ownership to the specified user and downgrade the current owner to a writer. This parameter is required as an acknowledgement of the side effect. File owners can only transfer ownership of files existing on My Drive. Files existing in a shared drive are owned by the organization that owns that shared drive. Ownership transfers are not supported for files and folders in shared drives. Organizers of a shared drive can move items from that shared drive into their My Drive which transfers the ownership to them.
225     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if the file ID parameter refers to a shared drive and the requester is an administrator of the domain to which the shared drive belongs.
226     */
227    pub async fn create(
228        &self,
229        file_id: &str,
230        email_message: &str,
231        move_to_new_owners_root: bool,
232        send_notification_email: bool,
233        supports_all_drives: bool,
234        supports_team_drives: bool,
235        transfer_ownership: bool,
236        use_domain_admin_access: bool,
237        body: &crate::types::Permission,
238    ) -> ClientResult<crate::Response<crate::types::Permission>> {
239        let mut query_args: Vec<(String, String)> = Default::default();
240        if !email_message.is_empty() {
241            query_args.push(("emailMessage".to_string(), email_message.to_string()));
242        }
243        if move_to_new_owners_root {
244            query_args.push((
245                "moveToNewOwnersRoot".to_string(),
246                move_to_new_owners_root.to_string(),
247            ));
248        }
249        query_args.push((
250            "sendNotificationEmail".to_string(),
251            send_notification_email.to_string(),
252        ));
253        if supports_all_drives {
254            query_args.push((
255                "supportsAllDrives".to_string(),
256                supports_all_drives.to_string(),
257            ));
258        }
259        if supports_team_drives {
260            query_args.push((
261                "supportsTeamDrives".to_string(),
262                supports_team_drives.to_string(),
263            ));
264        }
265        if transfer_ownership {
266            query_args.push((
267                "transferOwnership".to_string(),
268                transfer_ownership.to_string(),
269            ));
270        }
271        if use_domain_admin_access {
272            query_args.push((
273                "useDomainAdminAccess".to_string(),
274                use_domain_admin_access.to_string(),
275            ));
276        }
277        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
278        let url = self.client.url(
279            &format!(
280                "/files/{}/permissions?{}",
281                crate::progenitor_support::encode_path(file_id),
282                query_
283            ),
284            None,
285        );
286        self.client
287            .post(
288                &url,
289                crate::Message {
290                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
291                    content_type: Some("application/json".to_string()),
292                },
293            )
294            .await
295    }
296    /**
297     * This function performs a `GET` to the `/files/{fileId}/permissions/{permissionId}` endpoint.
298     *
299     * Gets a permission by ID.
300     *
301     * **Parameters:**
302     *
303     * * `file_id: &str` -- A link to this theme's background image.
304     * * `permission_id: &str` -- A link to this theme's background image.
305     * * `supports_all_drives: bool` -- Whether the requesting application supports both My Drives and shared drives.
306     * * `supports_team_drives: bool` -- Whether the user has installed the requesting app.
307     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if the file ID parameter refers to a shared drive and the requester is an administrator of the domain to which the shared drive belongs.
308     */
309    pub async fn get(
310        &self,
311        file_id: &str,
312        permission_id: &str,
313        supports_all_drives: bool,
314        supports_team_drives: bool,
315        use_domain_admin_access: bool,
316    ) -> ClientResult<crate::Response<crate::types::Permission>> {
317        let mut query_args: Vec<(String, String)> = Default::default();
318        if supports_all_drives {
319            query_args.push((
320                "supportsAllDrives".to_string(),
321                supports_all_drives.to_string(),
322            ));
323        }
324        if supports_team_drives {
325            query_args.push((
326                "supportsTeamDrives".to_string(),
327                supports_team_drives.to_string(),
328            ));
329        }
330        if use_domain_admin_access {
331            query_args.push((
332                "useDomainAdminAccess".to_string(),
333                use_domain_admin_access.to_string(),
334            ));
335        }
336        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
337        let url = self.client.url(
338            &format!(
339                "/files/{}/permissions/{}?{}",
340                crate::progenitor_support::encode_path(file_id),
341                crate::progenitor_support::encode_path(permission_id),
342                query_
343            ),
344            None,
345        );
346        self.client
347            .get(
348                &url,
349                crate::Message {
350                    body: None,
351                    content_type: None,
352                },
353            )
354            .await
355    }
356    /**
357     * This function performs a `DELETE` to the `/files/{fileId}/permissions/{permissionId}` endpoint.
358     *
359     * Deletes a permission.
360     *
361     * **Parameters:**
362     *
363     * * `file_id: &str` -- A link to this theme's background image.
364     * * `permission_id: &str` -- A link to this theme's background image.
365     * * `supports_all_drives: bool` -- Whether the requesting application supports both My Drives and shared drives.
366     * * `supports_team_drives: bool` -- Whether the user has installed the requesting app.
367     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if the file ID parameter refers to a shared drive and the requester is an administrator of the domain to which the shared drive belongs.
368     */
369    pub async fn delete(
370        &self,
371        file_id: &str,
372        permission_id: &str,
373        supports_all_drives: bool,
374        supports_team_drives: bool,
375        use_domain_admin_access: bool,
376    ) -> ClientResult<crate::Response<()>> {
377        let mut query_args: Vec<(String, String)> = Default::default();
378        if supports_all_drives {
379            query_args.push((
380                "supportsAllDrives".to_string(),
381                supports_all_drives.to_string(),
382            ));
383        }
384        if supports_team_drives {
385            query_args.push((
386                "supportsTeamDrives".to_string(),
387                supports_team_drives.to_string(),
388            ));
389        }
390        if use_domain_admin_access {
391            query_args.push((
392                "useDomainAdminAccess".to_string(),
393                use_domain_admin_access.to_string(),
394            ));
395        }
396        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
397        let url = self.client.url(
398            &format!(
399                "/files/{}/permissions/{}?{}",
400                crate::progenitor_support::encode_path(file_id),
401                crate::progenitor_support::encode_path(permission_id),
402                query_
403            ),
404            None,
405        );
406        self.client
407            .delete(
408                &url,
409                crate::Message {
410                    body: None,
411                    content_type: None,
412                },
413            )
414            .await
415    }
416    /**
417     * This function performs a `PATCH` to the `/files/{fileId}/permissions/{permissionId}` endpoint.
418     *
419     * Updates a permission with patch semantics.
420     *
421     * **Parameters:**
422     *
423     * * `file_id: &str` -- A link to this theme's background image.
424     * * `permission_id: &str` -- A link to this theme's background image.
425     * * `remove_expiration: bool` -- Whether the user has installed the requesting app.
426     * * `supports_all_drives: bool` -- Whether the requesting application supports both My Drives and shared drives.
427     * * `supports_team_drives: bool` -- Whether the user has installed the requesting app.
428     * * `transfer_ownership: bool` -- Whether to transfer ownership to the specified user and downgrade the current owner to a writer. This parameter is required as an acknowledgement of the side effect. File owners can only transfer ownership of files existing on My Drive. Files existing in a shared drive are owned by the organization that owns that shared drive. Ownership transfers are not supported for files and folders in shared drives. Organizers of a shared drive can move items from that shared drive into their My Drive which transfers the ownership to them.
429     * * `use_domain_admin_access: bool` -- Issue the request as a domain administrator; if set to true, then the requester will be granted access if the file ID parameter refers to a shared drive and the requester is an administrator of the domain to which the shared drive belongs.
430     */
431    pub async fn update(
432        &self,
433        file_id: &str,
434        permission_id: &str,
435        remove_expiration: bool,
436        supports_all_drives: bool,
437        supports_team_drives: bool,
438        transfer_ownership: bool,
439        use_domain_admin_access: bool,
440        body: &crate::types::Permission,
441    ) -> ClientResult<crate::Response<crate::types::Permission>> {
442        let mut query_args: Vec<(String, String)> = Default::default();
443        if remove_expiration {
444            query_args.push((
445                "removeExpiration".to_string(),
446                remove_expiration.to_string(),
447            ));
448        }
449        if supports_all_drives {
450            query_args.push((
451                "supportsAllDrives".to_string(),
452                supports_all_drives.to_string(),
453            ));
454        }
455        if supports_team_drives {
456            query_args.push((
457                "supportsTeamDrives".to_string(),
458                supports_team_drives.to_string(),
459            ));
460        }
461        if transfer_ownership {
462            query_args.push((
463                "transferOwnership".to_string(),
464                transfer_ownership.to_string(),
465            ));
466        }
467        if use_domain_admin_access {
468            query_args.push((
469                "useDomainAdminAccess".to_string(),
470                use_domain_admin_access.to_string(),
471            ));
472        }
473        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
474        let url = self.client.url(
475            &format!(
476                "/files/{}/permissions/{}?{}",
477                crate::progenitor_support::encode_path(file_id),
478                crate::progenitor_support::encode_path(permission_id),
479                query_
480            ),
481            None,
482        );
483        self.client
484            .patch(
485                &url,
486                crate::Message {
487                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
488                    content_type: Some("application/json".to_string()),
489                },
490            )
491            .await
492    }
493}