Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions cs3client/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,37 +275,35 @@ def get_received_share(
return res.share

def update_received_share(
self, auth_token: tuple, received_share: cs3scr.ReceivedShare, state: str = "SHARE_STATE_ACCEPTED"
self, auth_token: tuple, opaque_id: str, state: str = "SHARE_STATE_ACCEPTED"
) -> cs3scr.ReceivedShare:
"""
Update the state of a received share (SHARE_STATE_ACCEPTED, SHARE_STATE_ACCEPTED, SHARE_STATE_REJECTED).

:param auth_token: tuple in the form ('x-access-token', <token>) (see auth.get_token/auth.check_token)
:param recieved_share: ReceivedShare object.
:param opaque_id: Opaque share id. (REQUIRED).
:param state: Share state to update to, defaults to SHARE_STATE_ACCEPTED, (REQUIRED).
:return: Updated ReceivedShare object.
:raises: NotFoundException (Share not found)
:raises: AuthenticationException (Operation not permitted)
:raises: UnknownException (Unknown error)
"""
resource = Resource(
opaque_id=received_share.share.resource_id.opaque_id,
storage_id=received_share.share.resource_id.storage_id,
)
req = cs3scapi.UpdateReceivedShareRequest(
share=cs3scr.ReceivedShare(
share=received_share.share,
share=cs3scr.Share(
id=cs3scr.ShareId(opaque_id=opaque_id),
),
state=cs3scr.ShareState.Value(state),
mount_point=resource.ref,
),
update_mask=field_masks.FieldMask(paths=["state"]),
)

res = self._gateway.UpdateReceivedShare(request=req, metadata=[auth_token])
self._status_code_handler.handle_errors(
res.status, "update received share", f'opaque_id="{received_share.share.id.opaque_id}"'
res.status, "update received share", f'opaque_id="{opaque_id}"'
)
self._log.debug(
f'msg="Invoked UpdateReceivedShare" opaque_id="{received_share.share.id.opaque_id}" new_state="{state}" '
f'msg="Invoked UpdateReceivedShare" opaque_id="{opaque_id}" new_state="{state}" '
f'trace="{res.status.trace}"'
)
return res.share
Expand Down
6 changes: 2 additions & 4 deletions tests/test_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ def test_update_received_share(
share_instance, status_code, status_message, expected_exception, expected_result # noqa: F811 (not a redefinition)
):
resource_id = cs3spr.ResourceId(storage_id="storage_id", opaque_id="opaque_id")
share = cs3scr.Share(resource_id=resource_id)
received_share = cs3scr.ReceivedShare(share=share)

mock_response = Mock()
mock_response.status.code = status_code
Expand All @@ -289,9 +287,9 @@ def test_update_received_share(
with patch.object(share_instance._gateway, "UpdateReceivedShare", return_value=mock_response):
if expected_exception:
with pytest.raises(expected_exception):
share_instance.update_received_share(auth_token, received_share=received_share)
share_instance.update_received_share(auth_token, opaque_id=resource_id.opaque_id, state="SHARE_STATE_ACCEPTED")
else:
result = share_instance.update_received_share(auth_token, received_share=received_share)
result = share_instance.update_received_share(auth_token, opaque_id=resource_id.opaque_id, state="SHARE_STATE_ACCEPTED")
assert result == expected_result


Expand Down
Loading