Beispiel #1
0
 def get_context_data(self, **kwargs):
     from tickets.models import Ticket
     from tickets.const import TICKET_DETAIL_URL
     ticket_id = self.request.session.get("auth_ticket_id")
     if not ticket_id:
         ticket = None
     else:
         ticket = Ticket.all().filter(pk=ticket_id).first()
     context = super().get_context_data(**kwargs)
     if ticket:
         timestamp_created = datetime.datetime.timestamp(ticket.date_created)
         ticket_detail_url = TICKET_DETAIL_URL.format(id=ticket_id, type=ticket.type)
         assignees = ticket.current_node.first().ticket_assignees.all()
         assignees_display = ', '.join([str(i.assignee) for i in assignees])
         msg = _("""Wait for <b>{}</b> confirm, You also can copy link to her/him <br/>
               Don't close this page""").format(assignees_display)
     else:
         timestamp_created = 0
         ticket_detail_url = ''
         msg = _("No ticket found")
     context.update({
         "msg": msg,
         "timestamp": timestamp_created,
         "ticket_detail_url": ticket_detail_url
     })
     return context
Beispiel #2
0
    def post(self, request, **kwargs):
        user = request.user
        token = kwargs.get('token')
        action = request.POST.get('action')
        if action not in ['approve', 'reject']:
            msg = _('Illegal approval action')
            return self.redirect_message_response(error=str(msg))

        ticket_info = cache.get(token)
        if not ticket_info:
            return self.redirect_message_response(redirect_url=self.login_url)
        try:
            ticket_id = ticket_info.get('ticket_id')
            ticket = Ticket.all().get(id=ticket_id)
            if not ticket.has_current_assignee(user):
                raise Exception(
                    _("This user is not authorized to approve this ticket"))
            getattr(ticket, action)(user)
        except AlreadyClosed as e:
            self.clear(token)
            return self.redirect_message_response(error=str(e),
                                                  redirect_url=self.login_url)
        except Exception as e:
            return self.redirect_message_response(error=str(e),
                                                  redirect_url=self.login_url)

        self.clear(token)
        return self.redirect_message_response(message=_("Success"),
                                              redirect_url=self.login_url)
Beispiel #3
0
 def get_ticket(self):
     from tickets.models import Ticket
     ticket_id = self.request.session.get("auth_ticket_id")
     logger.debug('Login confirm ticket id: {}'.format(ticket_id))
     if not ticket_id:
         ticket = None
     else:
         ticket = Ticket.all().filter(id=ticket_id).first()
     return ticket
Beispiel #4
0
 def ticket(self):
     if getattr(self, 'swagger_fake_view', False):
         return None
     ticket_id = self.request.query_params.get('ticket_id')
     ticket = Ticket.all().filter(pk=ticket_id).first()
     if not ticket:
         raise JMSException(
             'Not found Ticket object about `id={}`'.format(ticket_id))
     return ticket