'Handle visualization sharing.'

@web.expose
@web.require_login('share    Galaxy    visualizations')
def sharing(self, trans, id, **kwargs):

    session = trans.sa_session
    visualization = self.get_visualization(trans, id, check_ownership=True)
    if ('make_accessible_via_link' in kwargs):
        self._make_item_accessible(trans.sa_session, visualization)
    elif ('make_accessible_and_publish' in kwargs):
        self._make_item_accessible(trans.sa_session, visualization)
        visualization.published = True
    elif ('publish' in kwargs):
        visualization.published = True
    elif ('disable_link_access' in kwargs):
        visualization.importable = False
    elif ('unpublish' in kwargs):
        visualization.published = False
    elif ('disable_link_access_and_unpublish' in kwargs):
        visualization.importable = visualization.published = False
    elif ('unshare_user' in kwargs):
        user = session.query(model.User).get(self.decode_id(kwargs['unshare_user']))
        if (not user):
            error('User    not    found    for    provided    id')
        association = session.query(model.VisualizationUserShareAssociation).filter_by(user=user, visualization=visualization).one()
        session.delete(association)
    session.flush()
    return trans.fill_template('/sharing_base.mako', item=visualization, controller_list='visualizations', use_panels=True)
