[facets] on the way to vidargs removal
our roving on the table view, which leads to introduction of this feature,
proved it was not the way to go.
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""security management and error screens"""__docformat__="restructuredtext en"_=unicodefromlogilab.mtconverterimportxml_escapefromcubicweb.selectorsimportyes,none_rset,match_user_groups,authenticated_userfromcubicweb.viewimportAnyRsetView,StartupView,EntityView,Viewfromcubicweb.uilibimporthtml_traceback,rest_traceback,exc_messagefromcubicweb.webimportformwidgetsaswdgsfromcubicweb.web.formfieldsimportguess_fieldfromcubicweb.web.views.schemaimportSecurityViewMixInfromyams.buildobjsimportEntityTypeSUBMIT_MSGID=_('Submit bug report')MAIL_SUBMIT_MSGID=_('Submit bug report by mail')classSecurityManagementView(SecurityViewMixIn,EntityView):"""display security information for a given entity"""__regid__='security'__select__=EntityView.__select__&authenticated_user()title=_('security')defcall(self):self.w(u'<div id="progress">%s</div>'%self._cw._('validating...'))super(SecurityManagementView,self).call()defentity_call(self,entity):self._cw.add_js('cubicweb.edition.js')self._cw.add_css('cubicweb.acl.css')w=self.w_=self._cw._w(u'<h1><span class="etype">%s</span> <a href="%s">%s</a></h1>'%(entity.dc_type().capitalize(),xml_escape(entity.absolute_url()),xml_escape(entity.dc_title())))# first show permissions defined by the schemaself.w('<h2>%s</h2>'%_('Schema\'s permissions definitions'))self.permissions_table(entity.e_schema)self.w('<h2>%s</h2>'%_('Manage security'))# ownership informationifself._cw.vreg.schema.rschema('owned_by').has_perm(self._cw,'add',fromeid=entity.eid):self.owned_by_edit_form(entity)else:self.owned_by_information(entity)defowned_by_edit_form(self,entity):self.w('<h3>%s</h3>'%self._cw._('Ownership'))msg=self._cw._('ownerships have been changed')form=self._cw.vreg['forms'].select('base',self._cw,entity=entity,form_renderer_id='onerowtable',submitmsg=msg,form_buttons=[wdgs.SubmitButton()],domid='ownership%s'%entity.eid,__redirectvid='security',__redirectpath=entity.rest_path())field=guess_field(entity.e_schema,self._cw.vreg.schema.rschema('owned_by'))form.append_field(field)form.render(w=self.w,display_progress_div=False)defowned_by_information(self,entity):ownersrset=entity.related('owned_by')ifownersrset:self.w('<h3>%s</h3>'%self._cw._('Ownership'))self.w(u'<div class="ownerInfo">')self.w(self._cw._('this entity is currently owned by')+' ')self.wview('csv',entity.related('owned_by'),'null')self.w(u'</div>')# else we don't know if this is because entity has no owner or becayse# user as no access to owner users entitiesclassErrorView(AnyRsetView):"""default view when no result has been found"""__select__=yes()__regid__='error'defpage_title(self):"""returns a title according to the result set - used for the title in the HTML header """returnself._cw._('an error occurred')defcall(self):req=self._cw.reset_headers()w=self.wex=req.data.get('ex')#_("unable to find exception information"))excinfo=req.data.get('excinfo')title=self._cw._('an error occurred')w(u'<h2>%s</h2>'%title)if'errmsg'inreq.data:ex=req.data['errmsg']exclass=Noneelse:exclass=ex.__class__.__name__ex=exc_message(ex,req.encoding)ifexcinfoisnotNoneandself._cw.vreg.config['print-traceback']:ifexclassisNone:w(u'<div class="tb">%s</div>'%xml_escape(ex).replace("\n","<br />"))else:w(u'<div class="tb">%s: %s</div>'%(exclass,xml_escape(ex).replace("\n","<br />")))w(u'<hr />')w(u'<div class="tb">%s</div>'%html_traceback(excinfo,ex,''))else:w(u'<div class="tb">%s</div>'%(xml_escape(ex).replace("\n","<br />")))# if excinfo is not None, it's probably not a bugifexcinfoisNone:returnvcconf=self._cw.vreg.config.vc_config()w(u"<div>")eversion=vcconf.get('cubicweb',self._cw._('no version information'))# NOTE: tuple wrapping needed since eversion is itself a tuplew(u"<b>CubicWeb version:</b> %s<br/>\n"%(eversion,))cversions=[]forcubeinself._cw.vreg.config.cubes():cubeversion=vcconf.get(cube,self._cw._('no version information'))w(u"<b>Cube %s version:</b> %s<br/>\n"%(cube,cubeversion))cversions.append((cube,cubeversion))w(u"</div>")# creates a bug submission link if submit-mail is setifself._cw.vreg.config['submit-mail']:form=self._cw.vreg['forms'].select('base',self._cw,rset=None,mainform=False)binfo=text_error_description(ex,excinfo,req,eversion,cversions)form.add_hidden('description',binfo,# we must use a text area to keep line breakswidget=wdgs.TextArea({'class':'hidden'}))form.add_hidden('__bugreporting','1')form.form_buttons=[wdgs.SubmitButton(MAIL_SUBMIT_MSGID)]form.action=req.build_url('reportbug')form.render(w=w)deftext_error_description(ex,excinfo,req,eversion,cubes):binfo=rest_traceback(excinfo,xml_escape(ex))binfo+=u'\n\n:URL: %s\n'%req.url()ifnot'__bugreporting'inreq.form:binfo+=u'\n:form params:\n'binfo+=u'\n'.join(u' * %s = %s'%(k,v)fork,vinreq.form.iteritems())binfo+=u'\n\n:CubicWeb version: %s\n'%(eversion,)forpkg,pkgversionincubes:binfo+=u":Cube %s version: %s\n"%(pkg,pkgversion)binfo+='\n'returnbinfoclassCwStats(View):"""A textual stats output for monitoring tools such as munin """__regid__='processinfo'content_type='text/txt'templatable=False__select__=none_rset()&match_user_groups('users','managers')defcall(self):stats=self._cw.vreg.config.repository(None).stats()results=[]forelementinstats:results.append(u'%s%s'%(element,stats[element]))self.w(u'\n'.join(results))