Skip to content

Conversation

@carycheng
Copy link

No description provided.

@boxcla
Copy link

boxcla commented Aug 21, 2018

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!

@carycheng carycheng changed the title front porting storage policies Storage Policies v2 Aug 21, 2018
return_full_pages=False,
)

def storage_policy_assignments(self, resolved_for_type, resolved_for_id):
Copy link
Contributor

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

Copy link
Contributor

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

:param assignee:
The `user` or `enterprise` to assign the storage policy to
:type:
:class:User
Copy link
Contributor

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):
Copy link
Contributor

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.


_item_type = 'user'

def storage_policy_assignments(self):
Copy link
Contributor

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()?

:returns:
An iterator of the entries in the storage policy assignment
:rtype:
:class:`BoxObjectCollection`
Copy link
Contributor

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

return self.translator.translate('storage_policy_assignment')(
session=self._session,
object_id=response['entries'][0]['id'],
response_object=response['entries'][0],
Copy link
Contributor

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

```python
storage_policy_id = '5678'
user = client.user('1234')
storage_policy_assignment = client.storage_policy(storage_policyid).assign(user)
Copy link
Contributor

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

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)
Copy link
Contributor

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?

@mattwiller
Copy link
Contributor

Left some comments and feedback. Also, remember to add the new object types to object/init.py

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'
Copy link
Contributor

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

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)
Copy link
Contributor

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.

Updating a storage policy assignment is done by calling `storage_policy.update_info(update_item)`.

```python
storage_policy_assignment_id = '1234'
Copy link
Contributor

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?

Get Assignment for User
-------------------------

Calling `user.get_storage_policy_assignment(fields=None)` will return a storage policy assignment object
Copy link
Contributor

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.

return_full_pages=False,
)

def storage_policy_assignments(self, resolved_for_type, resolved_for_id):
Copy link
Contributor

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

"""
return self.translator.translate('storage_policy_assignment')(session=self._session, object_id=assignment_id)

def storage_policies(self, limit=None, marker=None, fields=None):
Copy link
Contributor

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'}}
Copy link
Contributor

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)

:type fields:
`Iterable` of `unicode`
:returns:
An iterator of the entries in the storage policy
Copy link
Contributor

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

}
box_response = self._session.get(url, params=additional_params)
response = box_response.json()['entries'][0]
return self.translator.translate('storage_policy_assignment')(
Copy link
Contributor

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


```python
assignment_id = '1234'
policy_assignment = client.storage_policy_assignment(assignment_id).delete()
Copy link
Contributor

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')
Copy link
Contributor

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

@coveralls
Copy link

coveralls commented Oct 25, 2018

Pull Request Test Coverage Report for Build 1240

  • 36 of 36 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 95.472%

Totals Coverage Status
Change from base Build 1238: 0.07%
Covered Lines: 2298
Relevant Lines: 2407

💛 - Coveralls

@carycheng carycheng merged commit 68d8b89 into master Oct 26, 2018
@carycheng carycheng deleted the storage_policies_v2 branch October 26, 2018 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants