-
Notifications
You must be signed in to change notification settings - Fork 220
Storage Policies v2 #327
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
Merged
Merged
Storage Policies v2 #327
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9067f01
front porting storage policies
b317656
fixed tests for client and added object_type in base object
dcba51c
removed extraneous line in storage policy assignment
c196988
removed extraneous lines from test_storage_policy_assignment
5654ae0
switched import order
51ddeff
added docs for storage policy endpoint
2d80470
fixed docs for storage policy and removed constructors usage
e6a3e8b
fixed updates to storage policies
55505d8
updated docs and moved assignment onto user
52f6bc8
fixed assign on storage policy
c9fd61b
removedu unused fields
5bfc330
added limit and marker
409023d
removed unused fields
197bace
removed unused import
b5af4fa
fixed from feedback
e19babf
changes to storage policy
1c6d8af
fixed docs for storage policy
eff576b
removed unused lines
072f68a
removed unused import
defb9f1
fixed from feedback
f60b81c
Merge branch 'master' into storage_policies_v2
146284a
updates to storage policies
23ba14a
added tests for storage policy assign method
ed17f80
Merge branch 'master' into storage_policies_v2
e90bb38
replace hard coded type
f0465dd
Merge branch 'storage_policies_v2' of https://github.com/box/box-pyth…
81cb159
added asserts to test client for storage policies get
1ef7425
converted translator to use new one
afc6ee9
added test for storage policy and storage policy constructor returns …
2885870
Merge branch 'master' into storage_policies_v2
470b334
Merge branch 'master' into storage_policies_v2
d262b8c
added end of paging method
c3d34ce
added additional line spacing between tests in test_client
8d10cc6
Merge branch 'master' into storage_policies_v2
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # coding:utf-8 | ||
| from __future__ import unicode_literals, absolute_import | ||
|
|
||
| import json | ||
|
|
||
| from .base_object import BaseObject | ||
|
|
||
|
|
||
| class StoragePolicy(BaseObject): | ||
| """Represents the storage policy""" | ||
|
|
||
| _item_type = 'storage_policy' | ||
|
|
||
| def get_url(self, *args): | ||
| """ | ||
| Get url for storage policies. | ||
| """ | ||
| return self._session.get_url('storage_policies', self._object_id, *args) | ||
|
|
||
| def assign(self, user): | ||
| """ | ||
| Checks to see if a user is already assigned a storage policy or if the storage policy assigned | ||
| to user belongs to the enterprise. If neither, then update the user storage policy to the new one. | ||
|
|
||
| :param user: | ||
| The class:`User` to assign the storage policy to | ||
| :type user: | ||
| :class:`User` | ||
| :returns: | ||
| Information about the :class:`StoragePolicyAssignment` object. | ||
| :rtype: | ||
| :class:`StoragePolicyAssignment` | ||
| """ | ||
| assignment = user.get_storage_policy_assignment() | ||
| if assignment.id == self.object_id: | ||
| return assignment | ||
|
|
||
| if assignment.assigned_to['type'] == 'enterprise': | ||
| return self.create_assignment(user) | ||
|
|
||
| update_object = { | ||
| 'storage_policy': { | ||
| 'type': self.object_type, | ||
| 'id': self.object_id, | ||
| }, | ||
| } | ||
| return assignment.update_info(update_object) | ||
|
|
||
| def create_assignment(self, user): | ||
| """ | ||
| Assign a storage policy to a :class:`User`. | ||
|
|
||
| :param user: | ||
| The :class:'User` to assign the storage policy to. | ||
| :type: | ||
| :class:`User` | ||
| :returns: | ||
| Information about the :class:`StoragePolicyAssignment` object | ||
| :rtype: | ||
| :class:`StoragePolicyAssignment` | ||
| """ | ||
| url = self._session.get_url('storage_policy_assignments') | ||
| body = { | ||
| 'storage_policy': { | ||
| 'type': 'storage_policy', | ||
| 'id': self.object_id, | ||
| }, | ||
| 'assigned_to': { | ||
| 'type': user.object_type, | ||
| 'id': user.object_id, | ||
| } | ||
| } | ||
| response = self._session.post(url, data=json.dumps(body)).json() | ||
mattwiller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return self.translator.translate( | ||
| session=self._session, | ||
| response_object=response, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # coding:utf-8 | ||
| from __future__ import unicode_literals, absolute_import | ||
| from .base_object import BaseObject | ||
|
|
||
|
|
||
| class StoragePolicyAssignment(BaseObject): | ||
| """Represents the storage policy assignment""" | ||
|
|
||
| _item_type = 'storage_policy_assignment' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| Storage Policy | ||
| ============== | ||
|
|
||
| Allows the enterprise admin to manage the Storage Policies for users in their | ||
| enterprise. Used for an enterprise to decide storage location for users based on | ||
| where they work/reside. | ||
|
|
||
|
|
||
| Get Storage Policy | ||
| ------------------ | ||
|
|
||
| Calling `storage_policy.get(fields=None)` will return the storage policy object. | ||
|
|
||
| ```python | ||
| storage_policy_id = '1234' | ||
| storage_policy = client.storage_policy(storage_policy_id).get() | ||
| ``` | ||
|
|
||
| List Available Storage Policies | ||
| ------------------------------- | ||
|
|
||
| Calling `client.get_storage_policies()` will return an iterable that will page through all of the storage policies. It is possible to specify maxiumum number of items per response and fields to retrieve by caling `client.get_storage_policies(limit=None, fields=None)`. | ||
|
|
||
| ```python | ||
| storage_policies = client.get_storage_policies(limit=100) | ||
| for storage_policy in storage_policies: | ||
| # Do something | ||
| ``` | ||
|
|
||
| Create Storage Policy Assignment | ||
| -------------------------------- | ||
|
|
||
| To create new storage policy assignment call `storage_policy.create_assignment(user)`. | ||
|
|
||
| ```python | ||
| storage_policy_id = '5678' | ||
| user = client.user('1234') | ||
| storage_policy_assignment = client.storage_policy(storage_policy_id).create_assignment(user) | ||
| ``` | ||
|
|
||
| Note: This method only works if the user does not already have an assignment. If the current state of the user is not known, use the `storage_policy.assign(user)` method instead. | ||
|
|
||
| Assign a Storage Policy to a User | ||
| --------------------------------- | ||
|
|
||
| To assign a storage policy to a user, call the `storage_policy.assign(user)` method with the user to assign the storage policy to. | ||
|
|
||
| ```python | ||
| user = client.user('1234') | ||
| storage_policy_assignment = client.storage_policy('12345').assign(user) | ||
| ``` | ||
|
|
||
| Update Existing Assignment | ||
| -------------------------- | ||
|
|
||
| Updating a storage policy assignment is done by calling `storage_policy.update_info(update_item)`. | ||
|
|
||
| ```python | ||
| updated_storage_policy = {'storage_policy': {'type': 'storage_policy', 'id': '1234'}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to consider creating an override for this method to enable just passing in a StoragePolicy (since that's the only thing that can be updated) |
||
| updated_assignment = client.storage_policy_assignment('ZW50ZXJwcmldfgeV82MDMwMDQ=').update_info(updated_storage_policy) | ||
| ``` | ||
|
|
||
| Get Assignment | ||
| -------------- | ||
|
|
||
| Calling `storage_policy_assignment.get(fields=None)` will return a storage policy assignment object containing information about the assignment. | ||
|
|
||
| ```python | ||
| assignment_id = '1234' | ||
| storage_policy_assignment = client.storage_policy_assignment(assignment_id).get() | ||
| ``` | ||
|
|
||
| Get Assignment for User | ||
| ------------------------- | ||
|
|
||
| Calling `user.get_storage_policy_assignment()` will return the storage policy assigned to the specified user. | ||
|
|
||
| ```python | ||
| user_id = '1111' | ||
| assignment_info = client.user(user_id).get_storage_policy_assignment() | ||
| ``` | ||
|
|
||
| Delete Assignment | ||
| ----------------- | ||
|
|
||
| Calling `storage_policy_assignment.delete()` will remove the storage policy assignment from the user. | ||
|
|
||
| ```python | ||
| assignment_id = '1234' | ||
| client.storage_policy_assignment(assignment_id).delete() | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.