    def get(self, user_name, server_name=None):
        """List all shares for a given owner"""

        # TODO: optimize this query
        # we need Share and only the _names_ of users/groups,
        # no any other relationships
        query = self._init_share_query()
        if server_name is not None:
            spawner = self._lookup_spawner(user_name, server_name)
            query = query.filter_by(spawner_id=spawner.id)
        else:
            # lookup owner by id
            row = (
                self.db.query(orm.User.id)
                .where(orm.User.name == user_name)
                .one_or_none()
            )
            if row is None:
                raise web.HTTPError(404)
            owner_id = row[0]
            query = query.filter_by(owner_id=owner_id)
        self.finish(json.dumps(self._share_list_model(query)))
List all shares for a given owner
jupyterhub/apihandlers/shares.py