')
+ self.w(self.req._('this entity is currently owned by') + ' ')
+ self.wview('csv', entity.related('owned_by'), 'null')
+ self.w(u'
')
+ # else we don't know if this is because entity has no owner or becayse
+ # user as no access to owner users entities
+
+ def require_permission_information(self, entity, reqpermschema):
+ if entity.require_permission:
+ w = self.w
+ _ = self.req._
+ if reqpermschema.has_perm(self.req, 'delete', fromeid=entity.eid):
+ delurl = self.build_url('edit', __redirectvid='security',
+ __redirectpath=entity.rest_path())
+ delurl = delurl.replace('%', '%%')
+ # don't give __delete value to build_url else it will be urlquoted
+ # and this will replace %s by %25s
+ delurl += '&__delete=%s:require_permission:%%s' % entity.eid
+ dellinktempl = u'[-] ' % (
+ html_escape(delurl), _('delete this permission'))
+ else:
+ dellinktempl = None
+ w(u'
')
+ w(u'
%s
%s
' % (_("permission"),
+ _('granted to groups')))
+ for eperm in entity.require_permission:
+ w(u'
')
+ w(u'\n')
+
+ def button_ok(self):
+ return (u''
+ % self.req._(stdmsgs.BUTTON_OK))
+
+
+class ErrorView(AnyRsetView):
+ """default view when no result has been found"""
+ __selectors__ = (yes_selector,)
+ id = 'error'
+
+ def page_title(self):
+ """returns a title according to the result set - used for the
+ title in the HTML header
+ """
+ return self.req._('an error occured')
+
+ def call(self):
+ req = self.req.reset_headers()
+ _ = req._
+ ex = req.data.get('ex')#_("unable to find exception information"))
+ excinfo = req.data.get('excinfo')
+ title = _('an error occured')
+ self.w(u'
%s
' % title)
+ if 'errmsg' in req.data:
+ ex = req.data['errmsg']
+ else:
+ ex = exc_message(ex, req.encoding)
+ if excinfo is not None and self.config['print-traceback']:
+ exclass = ex.__class__.__name__
+ self.w(u'
' % (html_escape(ex).replace("\n"," ")))
+ # if excinfo is not None, it's probably not a bug
+ if excinfo is None:
+ return
+ vcconf = self.config.vc_config()
+ self.w(u"
")
+ eversion = vcconf.get('cubicweb', _('no version information'))
+ # NOTE: tuple wrapping needed since eversion is itself a tuple
+ self.w(u"CubicWeb version: %s \n" % (eversion,))
+ for pkg in self.config.cubes():
+ pkgversion = vcconf.get(pkg, _('no version information'))
+ self.w(u"Package %s version: %s \n" % (pkg, pkgversion))
+ self.w(u"
")
+ # creates a bug submission link if SUBMIT_URL is set
+ submiturl = self.config['submit-url']
+ if submiturl:
+ binfo = text_error_description(ex, excinfo, req, eversion,
+ [(pkg, vcconf.get(pkg, _('no version information')))
+ for pkg in self.config.cubes()])
+ self.w(u'\n')
+ submitmail = self.config['submit-mail']
+ if submitmail:
+ binfo = text_error_description(ex, excinfo, req, eversion,
+ [(pkg, vcconf.get(pkg, _('no version information')))
+ for pkg in self.config.cubes()])
+ self.w(u'\n')
+
+
+def exc_message(ex, encoding):
+ try:
+ return unicode(ex)
+ except:
+ try:
+ return unicode(str(ex), encoding, 'replace')
+ except:
+ return unicode(repr(ex), encoding, 'replace')
+
+def text_error_description(ex, excinfo, req, eversion, cubes):
+ binfo = rest_traceback(excinfo, html_escape(ex))
+ binfo += u'\n\n:URL: %s\n' % req.url()
+ if not '__bugreporting' in req.form:
+ binfo += u'\n:form params:\n'
+ binfo += u'\n'.join(u' * %s = %s' % (k, v) for k, v in req.form.iteritems())
+ binfo += u'\n\n:CubicWeb version: %s\n' % (eversion,)
+ for pkg, pkgversion in cubes:
+ binfo += u":Package %s version: %s\n" % (pkg, pkgversion)
+ binfo += '\n'
+ return binfo
+
+# some string we want to be internationalizable for nicer display of eproperty
+# groups
+_('navigation')
+_('ui')
+_('actions')
+_('boxes')
+_('components')
+_('contentnavigation')
+
+class SystemEpropertiesForm(FormMixIn, StartupView):
+ controller = 'edit'
+ id = 'systemepropertiesform'
+ title = _('site configuration')
+ require_groups = ('managers',)
+ category = 'startupview'
+
+ def linkable(self):
+ return True
+
+ def url(self):
+ """return the url associated with this view. We can omit rql here"""
+ return self.build_url('view', vid=self.id)
+
+ def call(self, **kwargs):
+ """The default view representing the application's index"""
+ self.req.add_js('cubicweb.edition.js')
+ self.req.add_css('cubicweb.preferences.css')
+ vreg = self.vreg
+ values = self.defined_keys
+ groupedopts = {}
+ mainopts = {}
+ # "self.id=='systemepropertiesform'" to skip site wide properties on
+ # user's preference but not site's configuration
+ for key in vreg.user_property_keys(self.id=='systemepropertiesform'):
+ parts = key.split('.')
+ if parts[0] in vreg:
+ # appobject configuration
+ reg, oid, propid = parts
+ groupedopts.setdefault(reg, {}).setdefault(oid, []).append(key)
+ else:
+ mainopts.setdefault(parts[0], []).append(key)
+ # precompute form to consume error message
+ for group, keys in mainopts.items():
+ mainopts[group] = self.form(keys, False)
+ for group, objects in groupedopts.items():
+ for oid, keys in objects.items():
+ groupedopts[group][oid] = self.form(keys, True)
+
+ w = self.w
+ req = self.req
+ _ = req._
+ w(u'
%s
\n' % _(self.title))
+ w(self.error_message())
+ for label, group, form in sorted((_(g), g, f)
+ for g, f in mainopts.iteritems()):
+ w(u'
' % (error and 'error' or ''))
+ w(error)
+ self.form_row_hiddens(w, entity, key)
+ w(wdg.edit_render(entity))
+ w(u'
\n')
+ w(u'
%s
' % wdg.render_help(entity))
+ return entity
+
+ def form_row_hiddens(self, w, entity, key):
+ eid = entity.eid
+ w(u'' % eid)
+ w(u'' % eid_param('__type', eid))
+ w(u'' % (eid_param('pkey', eid), key))
+ w(u'' % (eid_param('edits-pkey', eid), ''))
+
+
+class EpropertiesForm(SystemEpropertiesForm):
+ id = 'epropertiesform'
+ title = _('preferences')
+ require_groups = ('users', 'managers') # we don't want guests to be able to come here
+ __selectors__ = chainfirst(norset_selector,
+ chainall(onelinerset_selector, accept_rset_selector)),
+ accepts = ('EUser',)
+
+ @classmethod
+ def accept_rset(cls, req, rset, row, col):
+ if row is None:
+ row = 0
+ score = super(EpropertiesForm, cls).accept_rset(req, rset, row, col)
+ # check current user is the rset user or he is in the managers group
+ if score and (req.user.eid == rset[row][col or 0]
+ or req.user.matching_groups('managers')):
+ return score
+ return 0
+
+ @property
+ def user(self):
+ if self.rset is None:
+ return self.req.user
+ return self.rset.get_entity(self.row or 0, self.col or 0)
+
+ @property
+ @cached
+ def eprops_rset(self):
+ return self.req.execute('Any P,K,V WHERE P is EProperty, P pkey K, P value V,'
+ 'P for_user U, U eid %(x)s', {'x': self.user.eid})
+
+ def form_row_hiddens(self, w, entity, key):
+ super(EpropertiesForm, self).form_row_hiddens(w, entity, key)
+ # if user is in the managers group and the property is being created,
+ # we have to set for_user explicitly
+ if not entity.has_eid() and self.user.matching_groups('managers'):
+ eid = entity.eid
+ w(u''
+ % (eid_param('edits-for_user', eid), INTERNAL_FIELD_VALUE))
+ w(u''
+ % (eid_param('for_user', eid), self.user.eid))
+
+
+
+
+class ProcessInformationView(StartupView):
+ id = 'info'
+ title = _('server information')
+ require_groups = ('managers',)
+
+ def call(self, **kwargs):
+ """display server information"""
+ vcconf = self.config.vc_config()
+ req = self.req
+ _ = req._
+ # display main information
+ self.w(u'
%s
' % _('Application'))
+ self.w(u'
')
+ self.w(u'
%s
%s
' % (
+ 'CubicWeb', vcconf.get('cubicweb', _('no version information'))))
+ for pkg in self.config.cubes():
+ pkgversion = vcconf.get(pkg, _('no version information'))
+ self.w(u'
')
+ self.w(u' ')
+ # environment and request and server information
+ try:
+ # need to remove our adapter and then modpython-apache wrapper...
+ env = req._areq._req.subprocess_env
+ except AttributeError:
+ return
+ self.w(u'
%s
' % _('Environment'))
+ self.w(u'
')
+ for attr in env.keys():
+ self.w(u'
%s
%s
'
+ % (attr, html_escape(env[attr])))
+ self.w(u'
')
+ self.w(u'
%s
' % _('Request'))
+ self.w(u'
')
+ for attr in ('filename', 'form', 'hostname', 'main', 'method',
+ 'path_info', 'protocol',
+ 'search_state', 'the_request', 'unparsed_uri', 'uri'):
+ val = getattr(req, attr)
+ self.w(u'
%s
%s
'
+ % (attr, html_escape(val)))
+ self.w(u'
')
+ server = req.server
+ self.w(u'
%s
' % _('Server'))
+ self.w(u'
')
+ for attr in dir(server):
+ val = getattr(server, attr)
+ if attr.startswith('_') or callable(val):
+ continue
+ self.w(u'