def require_collection_playable(handler):
 def test_can_play(self, collection_id, **kwargs):
  'Check if the current user can play the collection.'
  actor = rights_manager.Actor(self.user_id)
  can_play = actor.can_play(feconf.ACTIVITY_TYPE_COLLECTION, collection_id)
  can_view = actor.can_view(feconf.ACTIVITY_TYPE_COLLECTION, collection_id)
  if (can_play and can_view):
   return handler(self, collection_id, **kwargs)
  else:
   raise self.PageNotFoundException
 return test_can_play

def require_collection_playable ( handler ) : def test_can_play ( self , collection_id , ** kwargs ) : actor = rights_manager . Actor ( self . user_id ) can_play = actor . can_play ( feconf . ACTIVITY_TYPE_COLLECTION , collection_id ) can_view = actor . can_view ( feconf . ACTIVITY_TYPE_COLLECTION , collection_id ) if ( can_play and can_view ) : return handler ( self , collection_id , ** kwargs ) else : raise self . PageNotFoundException return test_can_play
decorator that checks if the user can play the given collection .