|
| 1 | +# coding: utf-8 |
| 2 | +from __future__ import unicode_literals, absolute_import |
| 3 | + |
| 4 | +import json |
| 5 | + |
| 6 | +from .base_endpoint import BaseEndpoint |
| 7 | +from ..pagination.marker_based_object_collection import MarkerBasedObjectCollection |
| 8 | +from ..util.api_call_decorator import api_call |
| 9 | +from ..util.text_enum import TextEnum |
| 10 | + |
| 11 | + |
| 12 | +class AllowlistDirection(TextEnum): |
| 13 | + """ |
| 14 | + Used to determine the direction of the allowlist. |
| 15 | + """ |
| 16 | + INBOUND = 'inbound' |
| 17 | + OUTBOUNT = 'outbound' |
| 18 | + BOTH = 'both' |
| 19 | + |
| 20 | + |
| 21 | +class CollaborationAllowlist(BaseEndpoint): |
| 22 | + """Represents the allowlist of email domains that users in an enterprise may collaborate with.""" |
| 23 | + |
| 24 | + @api_call |
| 25 | + def get_entries(self, limit=None, marker=None, fields=None): |
| 26 | + """ |
| 27 | + Get the entries in the collaboration allowlist using limit-offset paging. |
| 28 | +
|
| 29 | + :param limit: |
| 30 | + The maximum number of entries to return per page. If not specified, then will use the server-side default. |
| 31 | + :type limit: |
| 32 | + `int` or None |
| 33 | + :param marker: |
| 34 | + The paging marker to start paging from. |
| 35 | + :type marker: |
| 36 | + `unicode` or None |
| 37 | + :param fields: |
| 38 | + List of fields to request. |
| 39 | + :type fields: |
| 40 | + `Iterable` of `unicode` |
| 41 | + :returns: |
| 42 | + An iterator of the entries in the allowlist. |
| 43 | + :rtype: |
| 44 | + :class:`BoxObjectCollection` |
| 45 | + """ |
| 46 | + return MarkerBasedObjectCollection( |
| 47 | + session=self._session, |
| 48 | + url=self.get_url('collaboration_whitelist_entries'), |
| 49 | + limit=limit, |
| 50 | + marker=marker, |
| 51 | + fields=fields, |
| 52 | + return_full_pages=False, |
| 53 | + ) |
| 54 | + |
| 55 | + @api_call |
| 56 | + def add_domain(self, domain, direction): |
| 57 | + """ |
| 58 | + Add a new domain to the collaboration allowlist. |
| 59 | +
|
| 60 | + :param domain: |
| 61 | + The email domain to add to the allowlist. |
| 62 | + :type domain: |
| 63 | + `unicode` |
| 64 | + :param direction: |
| 65 | + The direction in which collaboration should be allowed: 'inbound', 'outbound', or 'both'. |
| 66 | + :type direction: |
| 67 | + `unicode` |
| 68 | + :returns: |
| 69 | + The created allowlist entry for the domain. |
| 70 | + :rtype: |
| 71 | + :class:`CollaborationAllowlistEntry` |
| 72 | + """ |
| 73 | + url = self.get_url('collaboration_whitelist_entries') |
| 74 | + data = { |
| 75 | + 'domain': domain, |
| 76 | + 'direction': direction |
| 77 | + } |
| 78 | + response = self._session.post(url, data=json.dumps(data)).json() |
| 79 | + return self.translator.translate( |
| 80 | + session=self._session, |
| 81 | + response_object=response, |
| 82 | + ) |
| 83 | + |
| 84 | + @api_call |
| 85 | + def get_exemptions(self, limit=None, marker=None, fields=None): |
| 86 | + """ |
| 87 | + Get the list of exempted users who are not subject to the collaboration allowlist rules. |
| 88 | +
|
| 89 | + :param limit: |
| 90 | + The maximum number of entries to return per page. If not specified, then will use the server-side default. |
| 91 | + :type limit: |
| 92 | + `int` or None |
| 93 | + :param marker: |
| 94 | + The paging marker to start paging from. |
| 95 | + :type marker: |
| 96 | + `unicode` or None |
| 97 | + :param fields: |
| 98 | + List of fields to request. |
| 99 | + :type fields: |
| 100 | + `Iterable` of `unicode` |
| 101 | + :returns: |
| 102 | + An iterator of the exemptions to the allowlist. |
| 103 | + :rtype: |
| 104 | + :class:`BoxObjectCollection` |
| 105 | + """ |
| 106 | + return MarkerBasedObjectCollection( |
| 107 | + session=self._session, |
| 108 | + url=self.get_url('collaboration_whitelist_exempt_targets'), |
| 109 | + limit=limit, |
| 110 | + marker=marker, |
| 111 | + fields=fields, |
| 112 | + return_full_pages=False, |
| 113 | + ) |
| 114 | + |
| 115 | + @api_call |
| 116 | + def add_exemption(self, user): |
| 117 | + """ |
| 118 | + Exempt a user from the collaboration allowlist. |
| 119 | +
|
| 120 | + :param user: |
| 121 | + The user to exempt from the allowlist. |
| 122 | + :type user: |
| 123 | + :class:`User` |
| 124 | + :returns: |
| 125 | + The created allowlist exemption. |
| 126 | + :rtype: |
| 127 | + :class:`CollaborationAllowlistExemptTarget` |
| 128 | + """ |
| 129 | + url = self.get_url('collaboration_whitelist_exempt_targets') |
| 130 | + data = { |
| 131 | + 'user': { |
| 132 | + 'id': user.object_id # pylint:disable=protected-access |
| 133 | + } |
| 134 | + } |
| 135 | + response = self._session.post(url, data=json.dumps(data)).json() |
| 136 | + return self.translator.translate( |
| 137 | + session=self._session, |
| 138 | + response_object=response, |
| 139 | + ) |
0 commit comments