14 |
14 |
15 from cubicweb.view import StartupView |
15 from cubicweb.view import StartupView |
16 from cubicweb.selectors import match_user_groups, implements |
16 from cubicweb.selectors import match_user_groups, implements |
17 from cubicweb.common.uilib import ureport_as_html |
17 from cubicweb.common.uilib import ureport_as_html |
18 from cubicweb.web import ajax_replace_url, uicfg, httpcache |
18 from cubicweb.web import ajax_replace_url, uicfg, httpcache |
19 from cubicweb.web.views import tabs |
19 from cubicweb.web.views import tabs, management, schema |
20 from cubicweb.web.views.management import SecurityViewMixIn |
|
21 |
20 |
22 class ManageView(StartupView): |
21 class ManageView(StartupView): |
23 id = 'manage' |
22 id = 'manage' |
24 title = _('manage') |
23 title = _('manage') |
25 http_cache_manager = httpcache.EtagHTTPCacheManager |
24 http_cache_manager = httpcache.EtagHTTPCacheManager |
29 for eschema in cls.schema.entities(): |
28 for eschema in cls.schema.entities(): |
30 if eschema.schema_entity(): |
29 if eschema.schema_entity(): |
31 uicfg.indexview_etype_section.setdefault(eschema, 'schema') |
30 uicfg.indexview_etype_section.setdefault(eschema, 'schema') |
32 elif eschema.is_subobject(strict=True): |
31 elif eschema.is_subobject(strict=True): |
33 uicfg.indexview_etype_section.setdefault(eschema, 'subobject') |
32 uicfg.indexview_etype_section.setdefault(eschema, 'subobject') |
34 elif eschema.meta: |
|
35 uicfg.indexview_etype_section.setdefault(eschema, 'system') |
|
36 else: |
33 else: |
37 uicfg.indexview_etype_section.setdefault(eschema, 'application') |
34 uicfg.indexview_etype_section.setdefault(eschema, 'application') |
38 |
35 |
39 def display_folders(self): |
36 def display_folders(self): |
40 return False |
37 return False |
203 rset = self.req.execute('Any X,M,F ORDERBY N WHERE X is CWEType, X name N, ' |
200 rset = self.req.execute('Any X,M,F ORDERBY N WHERE X is CWEType, X name N, ' |
204 'X meta M, X final F') |
201 'X meta M, X final F') |
205 self.wview('editable-table', rset, displayfilter=True) |
202 self.wview('editable-table', rset, displayfilter=True) |
206 |
203 |
207 |
204 |
208 class ManagerSchemaPermissionsView(StartupView, SecurityViewMixIn): |
205 class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn): |
209 id = 'schema_security' |
206 id = 'schema_security' |
210 __select__ = StartupView.__select__ & match_user_groups('managers') |
207 __select__ = StartupView.__select__ & match_user_groups('managers') |
211 |
208 |
212 def call(self, display_relations=True, |
209 def call(self, display_relations=True, |
213 skiprels=('is', 'is_instance_of', 'identity', 'owned_by', 'created_by')): |
210 skiprels=('is', 'is_instance_of', 'identity', 'owned_by', 'created_by')): |
219 # compute entities |
216 # compute entities |
220 entities = [eschema for eschema in schema.entities() |
217 entities = [eschema for eschema in schema.entities() |
221 if not eschema.is_final()] |
218 if not eschema.is_final()] |
222 if not formparams['withmeta']: |
219 if not formparams['withmeta']: |
223 entities = [eschema for eschema in entities |
220 entities = [eschema for eschema in entities |
224 if not eschema.meta] |
221 if not eschema.schema_entity()] |
225 # compute relations |
222 # compute relations |
226 relations = [] |
223 relations = [] |
227 if display_relations: |
224 if display_relations: |
228 relations = [rschema for rschema in schema.relations() |
225 relations = [rschema for rschema in schema.relations() |
229 if not (rschema.is_final() or rschema.type in skiprels)] |
226 if not (rschema.is_final() or rschema.type in skiprels)] |
230 if not formparams['withmeta']: |
227 if not formparams['withmeta']: |
231 relations = [rschema for rschema in relations |
228 relations = [rschema for rschema in relations |
232 if not rschema.meta] |
229 if not rschema.schema_relation()] |
233 # index |
230 # index |
234 self.w(u'<div id="schema_security"><a id="index" href="index"/>') |
231 self.w(u'<div id="schema_security"><a id="index" href="index"/>') |
235 self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize()) |
232 self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize()) |
236 self.w(u'<h4>%s</h4>' % _('Entities').capitalize()) |
233 self.w(u'<h4>%s</h4>' % _('Entities').capitalize()) |
237 ents = [] |
234 ents = [] |
258 self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize()) |
255 self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize()) |
259 for eschema in sorted(entities): |
256 for eschema in sorted(entities): |
260 self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type)) |
257 self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type)) |
261 self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type))) |
258 self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type))) |
262 url = html_escape(self.build_url('schema', **formparams) + '#index') |
259 url = html_escape(self.build_url('schema', **formparams) + '#index') |
263 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url, self.req.external_resource('UP_ICON'), _('up'))) |
260 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
|
261 url, self.req.external_resource('UP_ICON'), _('up'))) |
264 self.w(u'</h3>') |
262 self.w(u'</h3>') |
265 self.w(u'<div style="margin: 0px 1.5em">') |
263 self.w(u'<div style="margin: 0px 1.5em">') |
266 self.schema_definition(eschema, link=False) |
264 self.schema_definition(eschema, link=False) |
267 |
|
268 # display entity attributes only if they have some permissions modified |
265 # display entity attributes only if they have some permissions modified |
269 modified_attrs = [] |
266 modified_attrs = [] |
270 for attr, etype in eschema.attribute_definitions(): |
267 for attr, etype in eschema.attribute_definitions(): |
271 if self.has_schema_modified_permissions(attr, attr.ACTIONS): |
268 if self.has_schema_modified_permissions(attr, attr.ACTIONS): |
272 modified_attrs.append(attr) |
269 modified_attrs.append(attr) |
275 self.w(u'</div>') |
272 self.w(u'</div>') |
276 self.w(u'<div style="margin: 0px 6em">') |
273 self.w(u'<div style="margin: 0px 6em">') |
277 for attr in modified_attrs: |
274 for attr in modified_attrs: |
278 self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type))) |
275 self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type))) |
279 self.schema_definition(attr, link=False) |
276 self.schema_definition(attr, link=False) |
280 self.w(u'</div>') |
277 self.w(u'</div>') |
281 else: |
|
282 self.w(u'</div>') |
|
283 |
|
284 |
278 |
285 def display_relations(self, relations, formparams): |
279 def display_relations(self, relations, formparams): |
286 _ = self.req._ |
280 _ = self.req._ |
287 self.w(u'<a id="relations" href="relations"/>') |
281 self.w(u'<a id="relations" href="relations"/>') |
288 self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize()) |
282 self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize()) |
289 for rschema in sorted(relations): |
283 for rschema in sorted(relations): |
290 self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type)) |
284 self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type)) |
291 self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type))) |
285 self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type))) |
292 url = html_escape(self.build_url('schema', **formparams) + '#index') |
286 url = html_escape(self.build_url('schema', **formparams) + '#index') |
293 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (url, self.req.external_resource('UP_ICON'), _('up'))) |
287 self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % ( |
|
288 url, self.req.external_resource('UP_ICON'), _('up'))) |
294 self.w(u'</h3>') |
289 self.w(u'</h3>') |
295 self.w(u'<div style="margin: 0px 1.5em">') |
290 self.w(u'<div style="margin: 0px 1.5em">') |
296 subjects = [str(subj) for subj in rschema.subjects()] |
291 subjects = [str(subj) for subj in rschema.subjects()] |
297 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('subject_plural:'), |
292 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
298 ', '.join( [str(subj) for subj in rschema.subjects()]), |
293 _('subject_plural:'), |
299 ', '.join( [_(str(subj)) for subj in rschema.subjects()]))) |
294 ', '.join(str(subj) for subj in rschema.subjects()), |
300 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (_('object_plural:'), |
295 ', '.join(_(str(subj)) for subj in rschema.subjects()))) |
301 ', '.join( [str(obj) for obj in rschema.objects()]), |
296 self.w(u'<div><strong>%s</strong> %s (%s)</div>' % ( |
302 ', '.join( [_(str(obj)) for obj in rschema.objects()]))) |
297 _('object_plural:'), |
|
298 ', '.join(str(obj) for obj in rschema.objects()), |
|
299 ', '.join(_(str(obj)) for obj in rschema.objects()))) |
303 self.schema_definition(rschema, link=False) |
300 self.schema_definition(rschema, link=False) |
304 self.w(u'</div>') |
301 self.w(u'</div>') |
305 |
302 |
306 |
303 |
307 class SchemaUreportsView(StartupView): |
304 class SchemaUreportsView(StartupView): |
308 id = 'schematext' |
305 id = 'schematext' |
309 |
306 |
310 def call(self): |
307 def call(self): |
311 from cubicweb.schemaviewer import SchemaViewer |
308 from cubicweb.schemaviewer import SchemaViewer |
312 skipmeta = int(self.req.form.get('skipmeta', True)) |
309 if int(self.req.form.get('skipmeta', True)): |
313 schema = self.schema |
310 skip = schema.SKIP_TYPES |
|
311 else: |
|
312 skip = () |
314 viewer = SchemaViewer(self.req) |
313 viewer = SchemaViewer(self.req) |
315 layout = viewer.visit_schema(schema, display_relations=True, |
314 layout = viewer.visit_schema(self.schema, display_relations=True, |
316 skiprels=('is', 'is_instance_of', 'identity', |
315 skiptypes=skip) |
317 'owned_by', 'created_by'), |
|
318 skipmeta=skipmeta) |
|
319 self.w(ureport_as_html(layout)) |
316 self.w(ureport_as_html(layout)) |
320 |
317 |
321 |
318 |