Exemple #1
0
    def invoke(self, message, warnings):
        """make a new ticket on receiving email"""


        # local warnings
        _warnings = []

        # get the ticket reporter
        reporter = self._reporter(message)
        # get the description and attachments
        mailBody, attachments = get_body_and_attachments(message)
        mailBody += '\n'


        # get the ticket fields
        fields = self._fields(mailBody, _warnings, reporter=reporter)

        # inset items from email
        ticket = Ticket(self.env)
        for key, value in fields.items():
            ticket.values[key] = value



        # fill in default values
        for field in ticket.fields:
            name = field['name']
            if name not in fields:
                option = 'ticket_field.%s' % name
                if self.env.config.has_option('mail', option):
                    ticket.values[name] = self.env.config.get('mail', option)
                else:
                    try:
                        value = ticket.get_value_or_default(name) or ''
                    except AttributeError: # BBB
                        value = ''
                    if value is not None:
                        ticket.values[name] = value


        # create the ticket
        ticket.insert()

        # add attachments to the ticket
        add_attachments(self.env, ticket, attachments)

        # do whatever post-processing is necessary
        self.post_process(ticket)

        # add local warnings
        if _warnings:
            warning = """A ticket has been created but there is a problem:\n\n%s\n\nPlease edit your ticket by going here: %s""" % ('\n\n'.join([' - %s' % warning for warning in _warnings]), self.env.abs_href('ticket', ticket.id))
            warnings.append(warning)
Exemple #2
0
    def invoke(self, message, warnings):
        """reply to a ticket"""
        ticket = self.ticket
        reporter = self._reporter(message)
        # get the mailBody and attachments
        mailBody, attachments = get_body_and_attachments(message)
        if not mailBody:
            warnings.append("Seems to be a reply to %s but I couldn't find a comment")
            return message

        #go throught work

        ts = TicketSystem(self.env)
        tm = TicketModule(self.env)
        perm = PermissionSystem(self.env)
        # TODO: Deprecate update without time_changed timestamp
        mockReq = self._MockReq(perm.get_user_permissions(reporter), reporter)
        avail_actions = ts.get_available_actions(mockReq, ticket)

        mailBody, inBodyFields, actions = self._get_in_body_fields(mailBody, avail_actions, reporter)
        if inBodyFields or actions :
            # check permissions
            perm = PermissionSystem(self.env)
            #we have properties movement, cheking user permission to do so
            if not perm.check_permission('MAIL2TICKET_PROPERTIES', reporter) : # None -> 'anoymous'
                raise ("%s does not have MAIL2TICKET_PROPERTIES permissions" % (user or 'anonymous'))

        action = None
        if actions :
            action = actions.keys()[0] 
        controllers = list(tm._get_action_controllers(mockReq, ticket, action))
        all_fields = [field['name'] for field in ts.get_ticket_fields()]


        #impact changes find in inBodyFields
        for field in inBodyFields :
            ticket._old[field] = ticket[field]
            ticket.values[field] = inBodyFields[field]
            mockReq.args[field] = inBodyFields[field]
        if action : 
            mockReq.args['action_%s_reassign_owner' % action] = ticket['owner']



        mockReq.args['comment'] = mailBody
        mockReq.args['ts'] = datetime.now()#to_datetime(None, utc)


        mockReq.args['ts'] = str(ticket.time_changed)
        
        changes, problems = tm.get_ticket_changes(mockReq, ticket, action)
        valid = problems and False or tm._validate_ticket(mockReq, ticket)

        tm._apply_ticket_changes(ticket, changes)


        # add attachments to the ticket
        add_attachments(self.env, ticket, attachments)

        ticket.save_changes(reporter, mailBody)
        
        for controller in controllers:
            controller.apply_action_side_effects(mockReq, ticket, action)
            # Call ticket change listeners
        for listener in ts.change_listeners:
            listener.ticket_changed(ticket, mailBody, reporter, ticket._old)

        tn = TicketNotifyEmail(self.env)
        tn.notify(ticket, newticket=0, modtime=ticket.time_changed)