Permissions for DriveItem :param parent: parent for this operation :type parent: DriveItem :param Connection con: connection to use if no parent specified :param Protocol protocol: protocol to use if no parent specified (kwargs) :param str main_reso
(self, *, parent=None, con=None, **kwargs)
| 312 | } |
| 313 | |
| 314 | def __init__(self, *, parent=None, con=None, **kwargs): |
| 315 | """ Permissions for DriveItem |
| 316 | |
| 317 | :param parent: parent for this operation |
| 318 | :type parent: DriveItem |
| 319 | :param Connection con: connection to use if no parent specified |
| 320 | :param Protocol protocol: protocol to use if no parent specified |
| 321 | (kwargs) |
| 322 | :param str main_resource: use this resource instead of parent resource |
| 323 | (kwargs) |
| 324 | """ |
| 325 | if parent and con: |
| 326 | raise ValueError('Need a parent or a connection but not both') |
| 327 | self.con = parent.con if parent else con |
| 328 | self._parent = parent if isinstance(parent, DriveItem) else None |
| 329 | # Choose the main_resource passed in kwargs over parent main_resource |
| 330 | main_resource = kwargs.pop('main_resource', None) or ( |
| 331 | getattr(parent, 'main_resource', None) if parent else None) |
| 332 | |
| 333 | protocol = parent.protocol if parent else kwargs.get('protocol') |
| 334 | super().__init__(protocol=protocol, main_resource=main_resource) |
| 335 | |
| 336 | self.driveitem_id = self._parent.object_id |
| 337 | cloud_data = kwargs.get(self._cloud_data_key, {}) |
| 338 | self.object_id = cloud_data.get(self._cc('id')) |
| 339 | self.inherited_from = cloud_data.get(self._cc('inheritedFrom'), None) |
| 340 | |
| 341 | link = cloud_data.get(self._cc('link'), None) |
| 342 | self.permission_type = 'owner' |
| 343 | if link: |
| 344 | self.permission_type = 'link' |
| 345 | self.share_type = link.get('type', 'view') |
| 346 | self.share_scope = link.get('scope', 'anonymous') |
| 347 | self.share_link = link.get('webUrl', None) |
| 348 | |
| 349 | invitation = cloud_data.get(self._cc('invitation'), None) |
| 350 | if invitation: |
| 351 | self.permission_type = 'invitation' |
| 352 | self.share_email = invitation.get('email', '') |
| 353 | invited_by = invitation.get('invitedBy', {}) |
| 354 | self.invited_by = invited_by.get('user', {}).get( |
| 355 | self._cc('displayName'), None) or invited_by.get('application', |
| 356 | {}).get( |
| 357 | self._cc('displayName'), None) |
| 358 | self.require_sign_in = invitation.get(self._cc('signInRequired'), |
| 359 | True) |
| 360 | |
| 361 | self.roles = cloud_data.get(self._cc('roles'), []) |
| 362 | granted_to = cloud_data.get(self._cc('grantedTo'), {}) |
| 363 | self.granted_to = granted_to.get('user', {}).get( |
| 364 | self._cc('displayName')) or granted_to.get('application', {}).get( |
| 365 | self._cc('displayName')) |
| 366 | self.share_id = cloud_data.get(self._cc('shareId'), None) |
| 367 | |
| 368 | def __str__(self): |
| 369 | return self.__repr__() |