Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support App item associations (box/box-codegen#561) #299

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "a3c5813", "specHash": "739d87b", "version": "1.4.1" }
{ "engineHash": "66f851a", "specHash": "6ca858e", "version": "1.4.1" }
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
ENTERPRISE_ID: ${{ secrets.ENTERPRISE_ID }}
BOX_FILE_REQUEST_ID: ${{ secrets.BOX_FILE_REQUEST_ID }}
BOX_EXTERNAL_USER_EMAIL: ${{ secrets.BOX_EXTERNAL_USER_EMAIL }}
APP_ITEM_ASSOCIATION_FILE_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FILE_ID }}
APP_ITEM_ASSOCIATION_FOLDER_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FOLDER_ID }}
WORKFLOW_FOLDER_ID: ${{ secrets.WORKFLOW_FOLDER_ID }}
run: |
tox
Expand Down Expand Up @@ -73,3 +75,5 @@ jobs:
BOX_FILE_REQUEST_ID: ${{ secrets.BOX_FILE_REQUEST_ID }}
BOX_EXTERNAL_USER_EMAIL: ${{ secrets.BOX_EXTERNAL_USER_EMAIL }}
WORKFLOW_FOLDER_ID: ${{ secrets.WORKFLOW_FOLDER_ID }}
APP_ITEM_ASSOCIATION_FILE_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FILE_ID }}
APP_ITEM_ASSOCIATION_FOLDER_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FOLDER_ID }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Now select `Authorization` and submit application to be reviewed by account admi
3. Set environment variable: `JWT_CONFIG_BASE_64` with base64 encoded jwt configuration file
4. Set environment variable: `BOX_FILE_REQUEST_ID` with ID of file request already created in the user account, `BOX_EXTERNAL_USER_EMAIL` with email of free external user which not belongs to any enterprise.
5. Set environment variable: `WORKFLOW_FOLDER_ID` with the ID of the Relay workflow that deletes the file that triggered the workflow. The workflow should have a manual start to be able to start it from the API.
6. Set environment variable: `APP_ITEM_ASSOCIATION_FILE_ID` to the ID of the file with associated app item and `APP_ITEM_ASSOCIATION_FOLDER_ID` to the ID of the folder with associated app item.

### Running tests

Expand Down
5 changes: 5 additions & 0 deletions box_sdk_gen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from box_sdk_gen.managers.trashed_files import TrashedFilesManager

from box_sdk_gen.managers.app_item_associations import AppItemAssociationsManager

from box_sdk_gen.managers.downloads import DownloadsManager

from box_sdk_gen.managers.uploads import UploadsManager
Expand Down Expand Up @@ -182,6 +184,9 @@ def __init__(self, auth: Authentication, *, network_session: NetworkSession = No
self.trashed_files = TrashedFilesManager(
auth=self.auth, network_session=self.network_session
)
self.app_item_associations = AppItemAssociationsManager(
auth=self.auth, network_session=self.network_session
)
self.downloads = DownloadsManager(
auth=self.auth, network_session=self.network_session
)
Expand Down
2 changes: 2 additions & 0 deletions box_sdk_gen/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from box_sdk_gen.managers.trashed_files import *

from box_sdk_gen.managers.app_item_associations import *

from box_sdk_gen.managers.downloads import *

from box_sdk_gen.managers.uploads import *
Expand Down
195 changes: 195 additions & 0 deletions box_sdk_gen/managers/app_item_associations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
from typing import Optional

from typing import Dict

from box_sdk_gen.internal.utils import to_string

from box_sdk_gen.serialization.json.serializer import deserialize

from box_sdk_gen.schemas.app_item_associations import AppItemAssociations

from box_sdk_gen.schemas.client_error import ClientError

from box_sdk_gen.networking.auth import Authentication

from box_sdk_gen.networking.network import NetworkSession

from box_sdk_gen.internal.utils import prepare_params

from box_sdk_gen.internal.utils import to_string

from box_sdk_gen.internal.utils import ByteStream

from box_sdk_gen.serialization.json.json_data import sd_to_json

from box_sdk_gen.networking.fetch import FetchOptions

from box_sdk_gen.networking.fetch import FetchResponse

from box_sdk_gen.networking.fetch import fetch

from box_sdk_gen.serialization.json.json_data import SerializedData


class AppItemAssociationsManager:
def __init__(
self,
*,
auth: Optional[Authentication] = None,
network_session: NetworkSession = None
):
if network_session is None:
network_session = NetworkSession()
self.auth = auth
self.network_session = network_session

def get_file_app_item_associations(
self,
file_id: str,
*,
limit: Optional[int] = None,
marker: Optional[str] = None,
application_type: Optional[str] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> AppItemAssociations:
"""
**This is a beta feature, which means that its availability might be limited.**

Returns all app items the file is associated with. This includes app items


associated with ancestors of the file. Assuming the context user has access


to the file, the type/ids are revealed even if the context user does not


have **View** permission on the app item.

:param file_id: The unique identifier that represents a file.

The ID for any file can be determined
by visiting a file in the web application
and copying the ID from the URL. For example,
for the URL `https://*.app.box.com/files/123`
the `file_id` is `123`.
Example: "12345"
:type file_id: str
:param limit: The maximum number of items to return per page., defaults to None
:type limit: Optional[int], optional
:param marker: Defines the position marker at which to begin returning results. This is
used when paginating using marker-based pagination.

This requires `usemarker` to be set to `true`., defaults to None
:type marker: Optional[str], optional
:param application_type: If given, only return app items for this application type, defaults to None
:type application_type: Optional[str], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
if extra_headers is None:
extra_headers = {}
query_params_map: Dict[str, str] = prepare_params(
{
'limit': to_string(limit),
'marker': to_string(marker),
'application_type': to_string(application_type),
}
)
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
FetchOptions(
url=''.join(
[
self.network_session.base_urls.base_url,
'/2.0/files/',
to_string(file_id),
'/app_item_associations',
]
),
method='GET',
params=query_params_map,
headers=headers_map,
response_format='json',
auth=self.auth,
network_session=self.network_session,
)
)
return deserialize(response.data, AppItemAssociations)

def get_folder_app_item_associations(
self,
folder_id: str,
*,
limit: Optional[int] = None,
marker: Optional[str] = None,
application_type: Optional[str] = None,
extra_headers: Optional[Dict[str, Optional[str]]] = None
) -> AppItemAssociations:
"""
**This is a beta feature, which means that its availability might be limited.**

Returns all app items the folder is associated with. This includes app items


associated with ancestors of the folder. Assuming the context user has access


to the folder, the type/ids are revealed even if the context user does not


have **View** permission on the app item.

:param folder_id: The unique identifier that represent a folder.

The ID for any folder can be determined
by visiting this folder in the web application
and copying the ID from the URL. For example,
for the URL `https://*.app.box.com/folder/123`
the `folder_id` is `123`.

The root folder of a Box account is
always represented by the ID `0`.
Example: "12345"
:type folder_id: str
:param limit: The maximum number of items to return per page., defaults to None
:type limit: Optional[int], optional
:param marker: Defines the position marker at which to begin returning results. This is
used when paginating using marker-based pagination.

This requires `usemarker` to be set to `true`., defaults to None
:type marker: Optional[str], optional
:param application_type: If given, returns only app items for this application type, defaults to None
:type application_type: Optional[str], optional
:param extra_headers: Extra headers that will be included in the HTTP request., defaults to None
:type extra_headers: Optional[Dict[str, Optional[str]]], optional
"""
if extra_headers is None:
extra_headers = {}
query_params_map: Dict[str, str] = prepare_params(
{
'limit': to_string(limit),
'marker': to_string(marker),
'application_type': to_string(application_type),
}
)
headers_map: Dict[str, str] = prepare_params({**extra_headers})
response: FetchResponse = fetch(
FetchOptions(
url=''.join(
[
self.network_session.base_urls.base_url,
'/2.0/folders/',
to_string(folder_id),
'/app_item_associations',
]
),
method='GET',
params=query_params_map,
headers=headers_map,
response_format='json',
auth=self.auth,
network_session=self.network_session,
)
)
return deserialize(response.data, AppItemAssociations)
6 changes: 6 additions & 0 deletions box_sdk_gen/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from box_sdk_gen.schemas.ai_response import *

from box_sdk_gen.schemas.app_item import *

from box_sdk_gen.schemas.classification import *

from box_sdk_gen.schemas.classification_template import *
Expand Down Expand Up @@ -314,6 +316,10 @@

from box_sdk_gen.schemas.webhook_invocation import *

from box_sdk_gen.schemas.app_item_association import *

from box_sdk_gen.schemas.app_item_associations import *

from box_sdk_gen.schemas.workflow_mini import *

from box_sdk_gen.schemas.workflow import *
Expand Down
32 changes: 32 additions & 0 deletions box_sdk_gen/schemas/app_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from enum import Enum

from box_sdk_gen.internal.base_object import BaseObject


class AppItemTypeField(str, Enum):
APP_ITEM = 'app_item'


class AppItem(BaseObject):
_discriminator = 'type', {'app_item'}

def __init__(
self,
id: str,
application_type: str,
*,
type: AppItemTypeField = AppItemTypeField.APP_ITEM.value,
**kwargs
):
"""
:param id: The unique identifier for this app item.
:type id: str
:param application_type: The type of the app that owns this app item.
:type application_type: str
:param type: `app_item`, defaults to AppItemTypeField.APP_ITEM.value
:type type: AppItemTypeField, optional
"""
super().__init__(**kwargs)
self.id = id
self.application_type = application_type
self.type = type
42 changes: 42 additions & 0 deletions box_sdk_gen/schemas/app_item_association.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from enum import Enum

from typing import Union

from box_sdk_gen.internal.base_object import BaseObject

from box_sdk_gen.schemas.app_item import AppItem

from box_sdk_gen.schemas.file_base import FileBase

from box_sdk_gen.schemas.folder_base import FolderBase

from box_sdk_gen.schemas.web_link_base import WebLinkBase


class AppItemAssociationTypeField(str, Enum):
APP_ITEM_ASSOCIATION = 'app_item_association'


class AppItemAssociation(BaseObject):
_discriminator = 'type', {'app_item_association'}

def __init__(
self,
id: str,
app_item: AppItem,
item: Union[FileBase, FolderBase, WebLinkBase],
*,
type: AppItemAssociationTypeField = AppItemAssociationTypeField.APP_ITEM_ASSOCIATION.value,
**kwargs
):
"""
:param id: The unique identifier for this app item association.
:type id: str
:param type: `app_item_association`, defaults to AppItemAssociationTypeField.APP_ITEM_ASSOCIATION.value
:type type: AppItemAssociationTypeField, optional
"""
super().__init__(**kwargs)
self.id = id
self.app_item = app_item
self.item = item
self.type = type
34 changes: 34 additions & 0 deletions box_sdk_gen/schemas/app_item_associations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from typing import Optional

from typing import List

from box_sdk_gen.internal.base_object import BaseObject

from box_sdk_gen.schemas.app_item_association import AppItemAssociation


class AppItemAssociations(BaseObject):
def __init__(
self,
*,
limit: Optional[int] = None,
next_marker: Optional[str] = None,
prev_marker: Optional[str] = None,
entries: Optional[List[AppItemAssociation]] = None,
**kwargs
):
"""
:param limit: The limit that was used for these entries. This will be the same as the
`limit` query parameter unless that value exceeded the maximum value
allowed. The maximum value varies by API., defaults to None
:type limit: Optional[int], optional
:param next_marker: The marker for the start of the next page of results., defaults to None
:type next_marker: Optional[str], optional
:param prev_marker: The marker for the start of the previous page of results., defaults to None
:type prev_marker: Optional[str], optional
"""
super().__init__(**kwargs)
self.limit = limit
self.next_marker = next_marker
self.prev_marker = prev_marker
self.entries = entries
Loading
Loading