'Handle page sharing.'

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

    session = trans.sa_session
    page = trans.sa_session.query(model.Page).get(self.decode_id(id))
    if ('make_accessible_via_link' in kwargs):
        self._make_item_accessible(trans.sa_session, page)
    elif ('make_accessible_and_publish' in kwargs):
        self._make_item_accessible(trans.sa_session, page)
        page.published = True
    elif ('publish' in kwargs):
        page.published = True
    elif ('disable_link_access' in kwargs):
        page.importable = False
    elif ('unpublish' in kwargs):
        page.published = False
    elif ('disable_link_access_and_unpublish' in kwargs):
        page.importable = page.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.PageUserShareAssociation).filter_by(user=user, page=page).one()
        session.delete(association)
    session.flush()
    return trans.fill_template('/sharing_base.mako', item=page, controller_list='pages', use_panels=True)
