Revision 75c8d4a7
- Ajout d'un message d'erreur en cas de permissions insuffisantes pour afficher la page de métrologie d'un hôte (Fixes #740);
- Correction de la verification des permissions pour simplifier les requêtes SQL.
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@7302 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/controllers/rpc.py | ||
---|---|---|
16 | 16 |
from pylons.i18n import ugettext as _, lazy_ugettext as l_ |
17 | 17 |
from webob.exc import HTTPPreconditionFailed |
18 | 18 |
from tg import expose, request, redirect, tmpl_context, \ |
19 |
config, validate, flash
|
|
19 |
config, validate, flash, exceptions as http_exc
|
|
20 | 20 |
from tg.decorators import paginate |
21 |
|
|
21 | 22 |
from repoze.what.predicates import not_anonymous, has_permission, \ |
22 | 23 |
in_group, Any, All |
23 | 24 |
from formencode import validators, schema |
... | ... | |
336 | 337 |
|
337 | 338 |
if start is None: |
338 | 339 |
start = int(time.time()) - int(duration) |
339 |
|
|
340 |
start = int(start) |
|
340 |
else: |
|
341 |
start = int(start)
|
|
341 | 342 |
duration = int(duration) |
342 | 343 |
|
343 | 344 |
user = get_current_user() |
... | ... | |
345 | 346 |
return dict(host=host, start=start, duration=duration, |
346 | 347 |
presets=self.presets, graphs=[]) |
347 | 348 |
|
348 |
# Récupération de la liste des noms des graphes, |
|
349 |
# avec vérification des permissions de l'utilisateur. |
|
349 |
# Vérification des permissions de l'utilisateur sur l'hôte. |
|
350 |
is_manager = in_group('managers').is_met(request.environ) |
|
351 |
if not is_manager: |
|
352 |
# Récupération des groupes auxquels l'utilisateur a accès. |
|
353 |
supitemgroups = [sig[0] for sig in user.supitemgroups() if sig[1]] |
|
354 |
# Si aucun des groupes de l'hôte ne fait partie |
|
355 |
# de cette liste, on affiche une erreur 403. |
|
356 |
h = Host.by_host_name(host) |
|
357 |
if len(set(h.groups).intersection(set(supitemgroups))) < 1: |
|
358 |
message = _('Access denied to host "%s"') % host |
|
359 |
LOGGER.warning(message) |
|
360 |
raise http_exc.HTTPForbidden(message) |
|
361 |
|
|
362 |
# Récupération de la liste des noms des graphes associés à l'hôte. |
|
350 | 363 |
graphs = DBSession.query( |
351 | 364 |
Graph.name |
352 | 365 |
).distinct( |
... | ... | |
356 | 369 |
(PerfDataSource, PerfDataSource.idperfdatasource == |
357 | 370 |
GRAPH_PERFDATASOURCE_TABLE.c.idperfdatasource), |
358 | 371 |
(Host, Host.idhost == PerfDataSource.idhost), |
359 |
(SUPITEM_GROUP_TABLE, SUPITEM_GROUP_TABLE.c.idsupitem == \ |
|
360 |
Host.idhost), |
|
361 | 372 |
).filter(Host.name == host) |
362 | 373 |
|
363 |
# Les managers ont accès à tout. |
|
364 |
# Les autres ont un accès restreint. |
|
365 |
is_manager = in_group('managers').is_met(request.environ) |
|
366 |
if not is_manager: |
|
367 |
supitemgroups = [sig[0] for sig in user.supitemgroups() if sig[1]] |
|
368 |
graphs = graphs.join( |
|
369 |
(GroupHierarchy, GroupHierarchy.idchild == \ |
|
370 |
SUPITEM_GROUP_TABLE.c.idgroup) |
|
371 |
).filter(GroupHierarchy.idparent.in_(supitemgroups)) |
|
372 |
|
|
373 | 374 |
graphs = graphs.all() |
375 |
|
|
374 | 376 |
return dict(host=host, start=start, duration=duration, |
375 | 377 |
presets=self.presets, graphs=graphs) |
376 | 378 |
|
Also available in: Unified diff