Revision a9a4679d
Correction dans "process_form_errors" (le préfixing du PATH_INFO était réalisé 2 fois,
une fois à cause de l'utilisation de HTTP_REFERER + un strip sur HTTP_HOST, l'autre à cause du redirect()).
Peut potentiellement corriger un problème de client (29328 sur GForge).
Ajout de validateurs sur la méthode update.
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@2421 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/controllers/root.py | ||
---|---|---|
48 | 48 |
""" |
49 | 49 |
for k in tmpl_context.form_errors: |
50 | 50 |
flash("'%s': %s" % (k, tmpl_context.form_errors[k]), 'error') |
51 |
if request.environ.get('HTTP_REFERER') : |
|
52 |
redirect(request.environ.get('HTTP_REFERER' |
|
53 |
).split(request.environ.get('HTTP_HOST'))[1]) |
|
54 |
else : |
|
55 |
redirect('/') |
|
51 |
redirect(request.environ.get('HTTP_REFERER', '/')) |
|
56 | 52 |
|
57 | 53 |
@validate(validators={ |
58 | 54 |
'page': validators.Int(min=1), |
... | ... | |
453 | 449 |
|
454 | 450 |
@validate(validators={ |
455 | 451 |
"id": validators.Regex(r'^[0-9]+(,[0-9]+)*,?$'), |
456 |
# "trouble_ticket": validators.Regex(r'^[0-9]*$'), |
|
452 |
"last_modification": validators.Number(not_empty=True), |
|
453 |
"trouble_ticket": validators.String(if_missing=''), |
|
457 | 454 |
"ack": validators.OneOf([ |
458 | 455 |
u'NoChange', |
459 | 456 |
u'None', |
460 | 457 |
u'Acknowledged', |
461 | 458 |
u'AAClosed' |
462 |
])}, error_handler=process_form_errors) |
|
459 |
], not_empty=True)}, error_handler=process_form_errors)
|
|
463 | 460 |
@require(Any(not_anonymous(), msg=l_("You need to be authenticated"))) |
464 |
def update(self, **krgv):
|
|
461 |
def update(self, id, last_modification, trouble_ticket, ack):
|
|
465 | 462 |
""" |
466 | 463 |
Mise à jour d'un événement suivant les arguments passés. |
467 | 464 |
Cela peut être un changement de ticket ou un changement de statut. |
468 | 465 |
|
469 |
@param krgv['id']: Le ou les identifiants des événements à traiter
|
|
470 |
@param krgv['last_modification']: La date de la dernière modification
|
|
466 |
@param id: Le ou les identifiants des événements à traiter
|
|
467 |
@param last_modification: La date de la dernière modification
|
|
471 | 468 |
dont l'utilisateur est au courant. |
472 |
@param krgv['tt']: Nouveau numéro du ticket associé.
|
|
473 |
@param krgv['status']: Nouveau status de/des événements.
|
|
469 |
@param trouble_ticket: Nouveau numéro du ticket associé.
|
|
470 |
@param ack: Nouvel état d'acquittement des événements sélectionnés.
|
|
474 | 471 |
|
475 | 472 |
Cette méthode permet de satisfaire les exigences suivantes : |
476 | 473 |
- VIGILO_EXIG_VIGILO_BAC_0020, |
... | ... | |
480 | 477 |
|
481 | 478 |
# On vérifie que des identifiants ont bien été transmis via |
482 | 479 |
# le formulaire, et on informe l'utilisateur le cas échéant. |
483 |
if krgv['id'] is None:
|
|
480 |
if id is None:
|
|
484 | 481 |
flash(_('No event has been selected'), 'warning') |
485 |
raise redirect(request.environ.get('HTTP_REFERER', url('/')))
|
|
482 |
raise redirect(request.environ.get('HTTP_REFERER', '/'))
|
|
486 | 483 |
|
487 | 484 |
# Le filtre permet d'éliminer les chaines vides contenues dans le |
488 | 485 |
# tableau ('a,b,' -> split -> ['a','b',''] -> filter -> ['a','b']). |
489 |
ids = map(int, filter(len, krgv['id'].split(',')))
|
|
486 |
ids = map(int, filter(len, id.split(',')))
|
|
490 | 487 |
|
491 | 488 |
# Si l'utilisateur édite plusieurs événements à la fois, |
492 | 489 |
# il nous faut chacun des identifiants |
... | ... | |
501 | 498 |
|
502 | 499 |
events.generate_request() |
503 | 500 |
idevents = [cause.idcause for cause in events.req] |
501 |
|
|
504 | 502 |
# Si des changements sont survenus depuis que la |
505 | 503 |
# page est affichée, on en informe l'utilisateur. |
506 |
last_modification = get_last_modification_timestamp(idevents, None)
|
|
507 |
if last_modification and datetime.fromtimestamp(\
|
|
508 |
float(krgv['last_modification'])) < last_modification:
|
|
504 |
last_modification = datetime.fromtimestamp(last_modification)
|
|
505 |
cur_last_modification = get_last_modification_timestamp(idevents, None)
|
|
506 |
if cur_last_modification and last_modification < cur_last_modification:
|
|
509 | 507 |
flash(_('Changes have occurred since the page was last displayed, ' |
510 | 508 |
'your changes HAVE NOT been saved.'), 'warning') |
511 |
raise redirect(request.environ.get('HTTP_REFERER', url('/')))
|
|
509 |
raise redirect(request.environ.get('HTTP_REFERER', '/'))
|
|
512 | 510 |
|
513 | 511 |
# Vérification que au moins un des identifiants existe et est éditable |
514 | 512 |
if not events.num_rows(): |
... | ... | |
523 | 521 |
else: |
524 | 522 |
event = req[0] |
525 | 523 |
|
526 |
if krgv['trouble_ticket'] != '' :
|
|
524 |
if trouble_ticket:
|
|
527 | 525 |
history = EventHistory( |
528 | 526 |
type_action="Ticket change", |
529 | 527 |
idevent=event.idcause, |
530 |
value=krgv['trouble_ticket'],
|
|
528 |
value=unicode(trouble_ticket),
|
|
531 | 529 |
text="Changed trouble ticket from '%s' to '%s'" % ( |
532 |
event.trouble_ticket, krgv['trouble_ticket']
|
|
530 |
event.trouble_ticket, trouble_ticket
|
|
533 | 531 |
), |
534 | 532 |
username=username, |
535 | 533 |
timestamp=datetime.now(), |
536 | 534 |
) |
537 | 535 |
DBSession.add(history) |
538 |
event.trouble_ticket = krgv['trouble_ticket']
|
|
536 |
event.trouble_ticket = trouble_ticket
|
|
539 | 537 |
|
540 |
if krgv['ack'] != 'NoChange' :
|
|
538 |
if ack != 'NoChange':
|
|
541 | 539 |
history = EventHistory( |
542 | 540 |
type_action="Acknowledgement change state", |
543 | 541 |
idevent=event.idcause, |
544 |
value=krgv['ack'],
|
|
542 |
value=unicode(ack),
|
|
545 | 543 |
text="Changed acknowledgement status " |
546 | 544 |
"from '%s' to '%s'" % ( |
547 |
event.status, krgv['ack']
|
|
545 |
event.status, ack
|
|
548 | 546 |
), |
549 | 547 |
username=username, |
550 | 548 |
timestamp=datetime.now(), |
551 | 549 |
) |
552 | 550 |
DBSession.add(history) |
553 |
event.status = krgv['ack']
|
|
551 |
event.status = ack
|
|
554 | 552 |
|
555 | 553 |
DBSession.flush() |
556 | 554 |
flash(_('Updated successfully')) |
557 |
redirect(request.environ.get('HTTP_REFERER', url('/')))
|
|
555 |
redirect(request.environ.get('HTTP_REFERER', '/'))
|
|
558 | 556 |
|
559 | 557 |
@validate(validators={ |
560 | 558 |
"plugin_name": validators.OneOf([i[0] for i \ |
Also available in: Unified diff