Revision 2b740fc8
Correction du bug #100 (multi-édition et forçage d'état).
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@3537 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/controllers/root.py | ||
---|---|---|
547 | 547 |
flash(_('No event has been selected'), 'warning') |
548 | 548 |
raise redirect(request.environ.get('HTTP_REFERER', '/')) |
549 | 549 |
|
550 |
# Le filtre permet d'éliminer les chaines vides contenues dans le |
|
551 |
# tableau ('a,b,' -> split -> ['a','b',''] -> filter -> ['a','b']). |
|
552 |
ids = map(int, filter(len, id.split(','))) |
|
553 |
|
|
554 |
# Si l'utilisateur édite plusieurs événements à la fois, |
|
555 |
# il nous faut chacun des identifiants |
|
550 |
# On récupère la liste de tous les identifiants des événements |
|
551 |
# à mettre à jour. |
|
552 |
ids = map(int, id.strip(',').split(',')) |
|
556 | 553 |
|
557 | 554 |
user = get_current_user() |
558 | 555 |
events = VigiboardRequest(user) |
... | ... | |
578 | 575 |
if not events.num_rows(): |
579 | 576 |
flash(_('No access to this event'), 'error') |
580 | 577 |
redirect('/') |
581 |
|
|
582 |
# Modification des événements et création d'un historique |
|
583 |
# pour chacun d'eux. |
|
584 |
for req in events.req: |
|
585 |
event = req |
|
586 | 578 |
|
579 |
if ack == u'Forced': |
|
580 |
condition = Any( |
|
581 |
in_group('managers'), |
|
582 |
has_permission('vigiboard-admin'), |
|
583 |
msg=l_("You don't have administrative access " |
|
584 |
"to VigiBoard")) |
|
585 |
try: |
|
586 |
condition.check_authorization(request.environ) |
|
587 |
except NotAuthorizedError, e: |
|
588 |
reason = unicode(e) |
|
589 |
flash(reason, 'error') |
|
590 |
raise redirect(request.environ.get('HTTP_REFERER', '/')) |
|
591 |
|
|
592 |
# Modification des événements et création d'un historique |
|
593 |
# chaque fois que cela est nécessaire. |
|
594 |
for event in events.req: |
|
587 | 595 |
if trouble_ticket and trouble_ticket != event.trouble_ticket: |
588 | 596 |
history = EventHistory( |
589 | 597 |
type_action="Ticket change", |
590 | 598 |
idevent=event.idcause, |
591 | 599 |
value=unicode(trouble_ticket), |
592 |
text="Changed trouble ticket from '%s' to '%s'" % ( |
|
593 |
event.trouble_ticket, trouble_ticket |
|
594 |
), |
|
600 |
text="Changed trouble ticket from '%(from)s' " |
|
601 |
"to '%(to)s'" % { |
|
602 |
'from': event.trouble_ticket, |
|
603 |
'to': trouble_ticket, |
|
604 |
}, |
|
595 | 605 |
username=user.user_name, |
596 | 606 |
timestamp=datetime.now(), |
597 | 607 |
) |
... | ... | |
600 | 610 |
|
601 | 611 |
# Changement du statut d'acquittement. |
602 | 612 |
if ack != u'NoChange': |
613 |
changed_ack = ack |
|
603 | 614 |
# Pour forcer l'acquittement d'un événement, |
604 | 615 |
# il faut en plus avoir la permission |
605 | 616 |
# "vigiboard-admin". |
606 | 617 |
if ack == u'Forced': |
607 |
condition = Any( |
|
608 |
in_group('managers'), |
|
609 |
has_permission('vigiboard-admin'), |
|
610 |
msg=l_("You don't have administrative access " |
|
611 |
"to VigiBoard")) |
|
612 |
try: |
|
613 |
condition.check_authorization(request.environ) |
|
614 |
except NotAuthorizedError, e: |
|
615 |
reason = unicode(e) |
|
616 |
flash(reason, 'error') |
|
617 |
raise redirect(request.environ.get('HTTP_REFERER', '/')) |
|
618 |
else: |
|
619 |
ack = u'AAClosed' |
|
620 |
# On met systématiquement l'état à "OK", même s'il |
|
621 |
# s'agit d'un hôte. Techniquement, c'est incorrect, |
|
622 |
# mais comme on fait ça pour masquer l'événement... |
|
623 |
event.cause.current_state = \ |
|
624 |
StateName.statename_to_value(u'OK') |
|
618 |
changed_ack = u'AAClosed' |
|
619 |
# On met systématiquement l'état à "OK", même s'il |
|
620 |
# s'agit d'un hôte. Techniquement, c'est incorrect, |
|
621 |
# mais comme on fait ça pour masquer l'événement... |
|
622 |
event.cause.current_state = \ |
|
623 |
StateName.statename_to_value(u'OK') |
|
624 |
|
|
625 |
history = EventHistory( |
|
626 |
type_action="Forced change state", |
|
627 |
idevent=event.idcause, |
|
628 |
value=u'OK', |
|
629 |
text="Forced state to 'OK'", |
|
630 |
username=user.user_name, |
|
631 |
timestamp=datetime.now(), |
|
632 |
) |
|
633 |
DBSession.add(history) |
|
625 | 634 |
|
626 | 635 |
history = EventHistory( |
627 | 636 |
type_action="Acknowledgement change state", |
... | ... | |
629 | 638 |
value=ack, |
630 | 639 |
text="Changed acknowledgement status " |
631 | 640 |
"from '%s' to '%s'" % ( |
632 |
event.status, ack |
|
641 |
event.status, changed_ack
|
|
633 | 642 |
), |
634 | 643 |
username=user.user_name, |
635 | 644 |
timestamp=datetime.now(), |
636 | 645 |
) |
637 | 646 |
DBSession.add(history) |
638 |
event.status = ack |
|
647 |
event.status = changed_ack
|
|
639 | 648 |
|
640 | 649 |
DBSession.flush() |
641 | 650 |
flash(_('Updated successfully')) |
... | ... | |
725 | 734 |
session['theme'] = theme |
726 | 735 |
session.save() |
727 | 736 |
return dict() |
728 |
|
|
737 |
|
|
729 | 738 |
def get_last_modification_timestamp(event_id_list, |
730 | 739 |
value_if_none=datetime.now()): |
731 | 740 |
""" |
Also available in: Unified diff