-
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
Storage Policies v2 #327
Conversation
|
Hi @carycheng, thanks for the pull request. Before we can merge it, we need you to sign our Contributor License Agreement. You can do so electronically here: http://opensource.box.com/cla Once you have signed, just add a comment to this pull request saying, "CLA signed". Thanks! |
boxsdk/client/client.py
Outdated
| return_full_pages=False, | ||
| ) | ||
|
|
||
| def storage_policy_assignments(self, resolved_for_type, resolved_for_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need this method? It looks like this is going to be on User instead of Client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should probably be removed or renamed now that the user.get_storage_policy_assignment() method has been added
boxsdk/object/storage_policy.py
Outdated
| :param assignee: | ||
| The `user` or `enterprise` to assign the storage policy to | ||
| :type: | ||
| :class:User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing backticks around User
|
|
||
| _item_type = 'storage_policy_assignment' | ||
|
|
||
| def get_url(self, *args): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to override this method; the default pluralization (adding an s to the end of the type) works in this case.
boxsdk/object/user.py
Outdated
|
|
||
| _item_type = 'user' | ||
|
|
||
| def storage_policy_assignments(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method name should be updated; this doesn't return multiple objects. Maybe get_storage_policy_assignment()?
boxsdk/object/user.py
Outdated
| :returns: | ||
| An iterator of the entries in the storage policy assignment | ||
| :rtype: | ||
| :class:`BoxObjectCollection` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value information needs to be updated
boxsdk/object/user.py
Outdated
| return self.translator.translate('storage_policy_assignment')( | ||
| session=self._session, | ||
| object_id=response['entries'][0]['id'], | ||
| response_object=response['entries'][0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider just grabbing response['entries'][0] once and using it on this line and the one above
docs/storage_policy.md
Outdated
| ```python | ||
| storage_policy_id = '5678' | ||
| user = client.user('1234') | ||
| storage_policy_assignment = client.storage_policy(storage_policyid).assign(user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storage_policyid should be storage_policy_id
docs/storage_policy.md
Outdated
| storage_policy_assignment_id = '1234' | ||
| new_storage_policy_id = '5678' | ||
| updated_item = {'type': 'storage_policy', 'id': new_storage_policy_id} | ||
| updated_storage_policy_assignment = client.storage_policy_assignment(storage_policy_assignment).update_info(updated_item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this example do what you expect? It looks to me like this would try to reassign type and id on the assignment object itself, not the storage_policy subobject. Could you double-check?
|
Left some comments and feedback. Also, remember to add the new object types to object/init.py |
docs/storage_policy.md
Outdated
| new_storage_policy_id = '5678' | ||
| updated_item = {'type': 'storage_policy', 'id': new_storage_policy_id} | ||
| updated_storage_policy_assignment = client.storage_policy_assignment(storage_policy_assignment).update_info(updated_item) | ||
| new__storage_policy_id = '5678' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable has an extra underscore after "new", and is also never used in this example
docs/storage_policy.md
Outdated
| storage_policy_assignment_id = '1234' | ||
| new__storage_policy_id = '5678' | ||
| new_storage_policy = client.storage_policy('5678') | ||
| updated_storage_policy_assignment = client.storage_policy_assignment(storage_policy_assignment).update_info(new_storage_policy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example doesn't work; storage_policy_assignment should be storage_policy_assignment_id. Also, does passing a StoragePolicy object to update_info() really work? It doesn't seem like that would do the right thing.
docs/storage_policy.md
Outdated
| Updating a storage policy assignment is done by calling `storage_policy.update_info(update_item)`. | ||
|
|
||
| ```python | ||
| storage_policy_assignment_id = '1234' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the sample assignment IDs to look like a real assignment ID?
docs/storage_policy.md
Outdated
| Get Assignment for User | ||
| ------------------------- | ||
|
|
||
| Calling `user.get_storage_policy_assignment(fields=None)` will return a storage policy assignment object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explanation could use some beefing up; we might want to explain which assignments could be returned etc.
boxsdk/client/client.py
Outdated
| return_full_pages=False, | ||
| ) | ||
|
|
||
| def storage_policy_assignments(self, resolved_for_type, resolved_for_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should probably be removed or renamed now that the user.get_storage_policy_assignment() method has been added
boxsdk/client/client.py
Outdated
| """ | ||
| return self.translator.translate('storage_policy_assignment')(session=self._session, object_id=assignment_id) | ||
|
|
||
| def storage_policies(self, limit=None, marker=None, fields=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along the lines of our previous conversation, we should consider renaming this to something like get_storage_policies()
| new__storage_policy_id = '5678' | ||
| new_storage_policy = client.storage_policy('5678') | ||
| updated_storage_policy_assignment = client.storage_policy_assignment(storage_policy_assignment).update_info(new_storage_policy) | ||
| updated_storage_policy = {'storage_policy': {'type': 'storage_policy', 'id': '1234'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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)
boxsdk/client/client.py
Outdated
| :type fields: | ||
| `Iterable` of `unicode` | ||
| :returns: | ||
| An iterator of the entries in the storage policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description could be a little clearer; this returns the storage policies available for the current enterprise
boxsdk/object/user.py
Outdated
| } | ||
| box_response = self._session.get(url, params=additional_params) | ||
| response = box_response.json()['entries'][0] | ||
| return self.translator.translate('storage_policy_assignment')( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use response['type'] rather than hardcoding the string
docs/storage_policy.md
Outdated
|
|
||
| ```python | ||
| assignment_id = '1234' | ||
| policy_assignment = client.storage_policy_assignment(assignment_id).delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example needs to be updated; delete() doesn't return anything
|
|
||
|
|
||
| def test_assign(test_storage_policy, mock_user, mock_box_session): | ||
| expected_url = mock_box_session.get_url('storage_policy_assignments') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected URL should be hardcoded
…on-sdk into storage_policies_v2
Pull Request Test Coverage Report for Build 1240
💛 - Coveralls |
…correct translated objects
No description provided.