Skip to content

Latest commit

 

History

History
217 lines (166 loc) · 9.32 KB

classifications.md

File metadata and controls

217 lines (166 loc) · 9.32 KB

Classifications

Classifications are a type of metadata that allows users and applications to define and assign a content classification to files and folders.

Classifications use the metadata APIs to add and remove classifications, and assign them to files. For more details on metadata templates please see the metadata documentation.

Add initial classifications

If an enterprise does not already have a classification defined, the first classification(s) can be added with the client.create_metadata_template(display_name, fields, template_key=None, hidden=False, scope='enterprise')](https://box-python-sdk.readthedocs.io/en/latest/boxsdk.client.html#boxsdk.client.client.Client.create_metadata_template) method.

from boxsdk.object.metadata_template import MetadataField, MetadataFieldType

fields = [
    MetadataField(MetadataFieldType.ENUM, 'Classification', key='Box__Security__Classification__Key', options=['Top Secret'])
]

template = client.create_metadata_template('Classification', fields, template_key='securityClassification-6VMVochwUWo')

List all classifications

To retrieve a list of all the classifications in an enterprise call the client.metadata_template(scope, template_key) method to get the classifications template, which will contain a list of all the classifications.

template = client.metadata_template('enterprise', 'securityClassification-6VMVochwUWo').get()

Add another classification

To add another classification, call the template.start_update() API to start making changes to the template, and then call the template.update_info(updates=new_updates) with the changes to apply to the template.

template = client.metadata_template('enterprise', 'securityClassification-6VMVochwUWo')
new_updates = template.start_update()
new_updates.add_enum_option('Box__Security__Classification__Key', 'Sensitive')
updated_template = template.update_info(updates=new_updates)

Update a classification

To update a classification, call the template.start_update() API to start making changes to the template, and then call the template.update_info(updates=new_updates) with the classification to change on the template.

template = client.metadata_template('enterprise', 'securityClassification-6VMVochwUWo')
new_updates = template.start_update()
new_updates.edit_enum_option('Box__Security__Classification__Key', 'Sensitive', 'Very Sensitive')
updated_template = template.update_info(updates=new_updates)

Add classification to file

To add a classification to a file, call file.metadata(scope='global', template='properties') with the name of the classification template, as well as the details of the classification to add to the file.

classification = {
    'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.file(file_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)

Update classification on file

To update a classification on a file, call file.metadata(scope='global', template='properties') with the name of the classification template, as well as the details of the classification to add to the file.

classification = {
    'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.file(file_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)

Get classification on file

Retrieve the classification on a file by calling file.metadata(scope='global', template='properties').get() on a file.

metadata = client.file(file_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').get()

Remove classification from file

A classification can be removed from a file by calling file.metadata(scope='global', template='properties').delete().

client.file(file_id='11111').metadata(scope='securityClassification-6VMVochwUWo', template='myMetadata').delete()

Add classification to folder

To add a classification to a folder, call folder.metadata(scope='global', template='properties') with the name of the classification template, as well as the details of the classification to add to the folder.

classification = {
    'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.folder(folder_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)

Update classification on folder

To update a classification on a folder, call folder.metadata(scope='global', template='properties') with the name of the classification template, as well as the details of the classification to add to the folder.

classification = {
    'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.folder(folder_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)

Get classification on folder

Retrieve the classification on a folder by calling folder.metadata(scope='global', template='properties').get() on a folder.

metadata = client.folder(folder_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').get()

Remove classification from folder

A classification can be removed from a folder by calling folder.metadata(scope='global', template='properties').delete().

client.folder(folder_id='11111').metadata(scope='securityClassification-6VMVochwUWo', template='myMetadata').delete()