| | 157 | |
|---|
| | 158 | |
|---|
| | 159 | class TicketWorkflowOpOwnerPrevious(TicketWorkflowOpBase): |
|---|
| | 160 | """Sets the owner to the previous owner |
|---|
| | 161 | |
|---|
| | 162 | Don't forget to add the `TicketWorkflowOpOwnerPrevious` to the workflow |
|---|
| | 163 | option in [ticket]. |
|---|
| | 164 | If there is no workflow option, the line will look like this: |
|---|
| | 165 | |
|---|
| | 166 | workflow = ConfigurableTicketWorkflow,TicketWorkflowOpOwnerPrevious |
|---|
| | 167 | """ |
|---|
| | 168 | |
|---|
| | 169 | _op_name = 'set_owner_to_previous' |
|---|
| | 170 | |
|---|
| | 171 | # ITicketActionController methods |
|---|
| | 172 | |
|---|
| | 173 | def render_ticket_action_control(self, req, ticket, action): |
|---|
| | 174 | """Returns the action control""" |
|---|
| | 175 | actions = ConfigurableTicketWorkflow(self.env).actions |
|---|
| | 176 | label = actions[action]['name'] |
|---|
| | 177 | new_owner = self._new_owner(ticket) |
|---|
| | 178 | if new_owner: |
|---|
| | 179 | hint = 'The owner will change to %s' % new_owner |
|---|
| | 180 | else: |
|---|
| | 181 | hint = 'The owner will be deleted.' |
|---|
| | 182 | control = tag('') |
|---|
| | 183 | return (label, control, hint) |
|---|
| | 184 | |
|---|
| | 185 | def get_ticket_changes(self, req, ticket, action): |
|---|
| | 186 | """Returns the change of owner.""" |
|---|
| | 187 | return {'owner': self._new_owner(ticket)} |
|---|
| | 188 | |
|---|
| | 189 | def _new_owner(self, ticket): |
|---|
| | 190 | """Determines the new owner""" |
|---|
| | 191 | db = self.env.get_db_cnx() |
|---|
| | 192 | cursor = db.cursor() |
|---|
| | 193 | cursor.execute("SELECT oldvalue FROM ticket_change WHERE ticket=%s " \ |
|---|
| | 194 | "AND field='owner' ORDER BY -time", (ticket.id, )) |
|---|
| | 195 | row = cursor.fetchone() |
|---|
| | 196 | if row: |
|---|
| | 197 | owner = row[0] |
|---|
| | 198 | else: # The owner has never changed. |
|---|
| | 199 | owner = '' |
|---|
| | 200 | return owner |
|---|