Skip to content

Commit

Permalink
API, sharable: serialize users_shared_with
Browse files Browse the repository at this point in the history
- Changes sharable serializers so that, when requested with
`keys=users_shared_with`, they return a list of encoded user ids for
each user that the item has been shared with
- Adds tests in test_HistoryManager
  • Loading branch information
carlfeberhard committed May 10, 2016
1 parent 74e6d8b commit d76d92d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/galaxy/managers/sharable.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def add_serializers( self ):

self.serializers.update({
'user_id' : self.serialize_id,
'username_and_slug' : self.serialize_username_and_slug
'username_and_slug' : self.serialize_username_and_slug,
'users_shared_with' : self.serialize_users_shared_with
})
# these use the default serializer but must still be white-listed
self.serializable_keyset.update([
Expand All @@ -357,9 +358,12 @@ def serialize_username_and_slug( self, item, key, **context ):

# the only ones that needs any fns:
# user/user_id
# user_shares?
# username_and_slug?

def serialize_users_shared_with( self, item, key, **context ):
share_assocs = self.manager.get_share_assocs( item )
return [ self.serialize_id( share, 'user_id' ) for share in share_assocs ]


class SharableModelDeserializer( base.ModelDeserializer,
taggable.TaggableDeserializerMixin, annotatable.AnnotatableDeserializerMixin, ratable.RatableDeserializerMixin ):
Expand Down
8 changes: 8 additions & 0 deletions test/unit/managers/test_HistoryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ def test_sharable( self ):
serialized = self.history_serializer.serialize( history1, sharable_attrs )
self.assertKeys( serialized, sharable_attrs )

self.log( 'should return user_id for user with whom it\'s been shared' )
non_owner = self.user_manager.create( **user3_data )
self.history_manager.share_with( history1, non_owner )
serialized = self.history_serializer.serialize( history1, [ 'users_shared_with' ] )
self.assertKeys( serialized, [ 'users_shared_with' ] )
self.assertIsInstance( serialized[ 'users_shared_with' ], list )
self.assertEqual( serialized[ 'users_shared_with' ][0], self.app.security.encode_id( non_owner.id ) )

def test_purgable( self ):
user2 = self.user_manager.create( **user2_data )
history1 = self.history_manager.create( name='history1', user=user2 )
Expand Down

0 comments on commit d76d92d

Please sign in to comment.