Terms of Service allows Box Admins to configure a custom Terms of Service for end users to accept/re-accept/decline for platform applications
A Terms of Service can be created in an enterprise. Please note that only two can be created. One external and one managed. If a terms of service already exists please use the update call to change the current terms of service.
To create a Terms of Service object, calling client.create_terms_of_service(status, tos_type, text)
will let
you create a new TermsOfService
object with the specified status, type, and text. This
method will return a newly created TermsOfService
object populated with data from the API.
from boxsdk.object.terms_of_service import TermsOfServiceType, TermsOfServiceStatus
terms_of_service = client.create_terms_of_service(TermsOfServiceStatus.ENABLED,TermsOfServiceType.MANAGED, 'Example Text')
print(f'Terms of Service status is {terms_of_service.status} and the message is {terms_of_service.text}')
To update a terms of service object, first call terms_of_service.update_info(data=update_object)
with
a dict
of properties to update on the terms of service. This method returns a newly updated TermsOfService
object, leaving the original object unmodified.
update_object = {'text': 'New Text'}
updated_tos = client.terms_of_service(tos_id='12345').update_info(data=update_object)
print(f'The updated message for your custom terms of service is {updated_tos.text} with ID {updated_tos.id}')
To get a terms of service object, call client.terms_of_service(service_id)
to construct the
appropriate TermsOfService
, and then calling terms_of_service.get(*, fields=None, headers=None, **kwargs)
will return the TermsOfService
object populated with data from the API.
terms_of_service = client.terms_of_service(tos_id='12345').get()
print(f'Terms of Service ID is {terms_of_service.id} and the message is {terms_of_service.text}')
To retrieve all terms of service for an enterprise, call
client.get_terms_of_services(limit=None, marker=None, fields=None)
. This method returns a
BoxObjectCollection
that allows you to iterate over the TermOfService
objects in the
collection.
terms_of_services = client.get_terms_of_services()
for terms_of_service in terms_of_services:
print(f'Terms of Service ID is {terms_of_service.id} and the message is {terms_of_service.text}')
To accept or decline a terms of service, calling terms_of_service.set_user_status(is_accepted, user)
will allow you to create a newly updated TermsOfServiceUserStatus
object
populated with data from the API, leaving the original object umodified if a TermsOfService
object already exists for a user. If the user does not have a TermsOfService
object
assigned then terms_of_service.set_user_status(is_accepted, user)
will create a new
TermsOfServiceUserStatus
object populated with data from the API.
user = client.user(user_id='22222')
user_status = client.terms_of_service(tos_id='12345').set_user_status(is_accepted=True, user=user)
print(f'User status ID is {user_status.id} and the accepted status is {user_status.is_accepted}')
It is important to note that regardless of whether the user has taken action on this terms of service. This will create and update the user status on the terms of service.
Note that this example will make multiple API calls, if you know that your user has already accepted or decline a
Terms of Service and you wish to change their status, call terms_of_service_user_status.update_info(data=data_to_update)
with a dict
of properties to update on the terms of service user status. This method returns a newly updated
TermsOfServiceUserStatus
object, leaving the original object unmodified.
user_status = client.terms_of_service_user_status(tos_user_status_id='12345').update_info(data={'is_accepted': True})
print(f'Terms of Service User Status ID is {user_status.id} and the accepted status is {user_status.is_accepted}')
It is important to note that this will accept or decline a custom terms of service for a user. For a user that has taken action in this terms of service, this will update their status. If the user has never taken action on this terms of service then this will return a 404 Not Found Error.
To get a terms of service user status object, first call
client.terms_of_service_user_status(status_id)
to construct the appropriate TermsOfServiceUserStatus
object. Then calling
client.user(user_id)
to construct the user you wish to retrieve a
TermsOfServiceUserStatus
object for. Finally, calling
terms_of_service_user_status.get(*, fields=None, headers=None, **kwargs)
will return the
TermsOfServiceUserStatus
object populated with data from the API.
user = client.user(user_id='11111')
user_status = client.terms_of_service(tos_id='12345').get_user_status(user)
print(f'User status ID is {user_status.id} and the accepted status is {user_status.is_accepted}')