Opened 13 months ago

Closed 6 months ago

[PATCH] Operations to 'set field to self' and 'clear field(s)' requested

Reported by: Owned by: Jon Ashley Jon Ashley normal AdvancedTicketWorkflowPlugin normal 1.0

Description

In my local setup, I use this plugin to automatically set fields called 'evaluator', 'approver', 'implementer' and 'reviewer' to the name of the current user when the user transitions the ticket into the states 'evaluated', 'approved', 'implemented' and 'reviewed' respectively. I then use the KeepInterfaceSimplePlugin to enforce rules that prevent the user changing these fields manually and that prevent the evaluator and approver being the same user, or the implementer and reviewer being the same user.

I also use this plugin to clear the 'evaluator', 'approver', 'implementer' and 'reviewer' fields when the ticket is rolled back to an earlier state.

To do that, I have applied the attached patch which adds the operations set_field_to_self and set_fields_to_blank.

Changed 13 months ago by Jon Ashley

Patch to add new operations as described

comment:1 Changed 13 months ago by Ryan J Ollos

Owner: set to Jon Ashley new → assigned

comment:2 Changed 13 months ago by Ryan J Ollos

Thanks, I will test out the patch very soon.

comment:3 follow-up:  4 Changed 13 months ago by Jun Omae

I think the following in the patch should use named arguments for gettext.

        hint = _("The '%s' field will be set to '%s'." % (
self._field_name(action, ticket),
req.authname
))

        hint = _("The '%(field)s' field will be set to '%(username)s'.",
field=self._field_name(action, ticket),


The following can not be translated to non-English.

        hint = _("The %s%s%s field%s will be cleared."  % (
', '.join(fields[:-1]),
len(fields) > 1 and ' and ' or '',
fields[-1],
len(fields) > 1 and 's' or ''
))


comment:4 in reply to:  3 Changed 13 months ago by Jun Omae

The following can not be translated to non-English.

        hint = _("The %s%s%s field%s will be cleared."  % (
', '.join(fields[:-1]),
len(fields) > 1 and ' and ' or '',
fields[-1],
len(fields) > 1 and 's' or ''
))

        hint = ngettext("The %(fields)s field will be cleared.",
"The %(fields)s fields will be cleared.", len(fields),
fields=', '.join(fields))


Another thing: I think TicketWorkflowOpFieldsBlank._field_names could use config.getlist() rather than .split(',').

     def _field_names(self, action, ticket):
"""Determines the fields to set to blank """
-        fields_string = self.config.get('ticket-workflow',
-                                        action + '.' + self._op_name).strip()
-        return [x.strip() for x in fields_string.split(',')]
+        return self.config.getlist('ticket-workflow',
+                                   action + '.' + self._op_name)


comment:5 Changed 10 months ago by Jon Ashley

In 16901:

Patch applied, with changes as suggested in review.
re #13237

comment:6 Changed 10 months ago by Ryan J Ollos

Sorry for the late comment. For clarity, I would have named the operations set_field_to_author and clear_fields. The term "author" is used throughout Trac to refer to the user making the change.

comment:7 Changed 10 months ago by Jon Ashley

In 16904:

Name operations (and the associated components) for consistency with standard Trac terminology.
re #13237

comment:9 Changed 6 months ago by Ryan J Ollos

Resolution: → fixed assigned → closed

Modify Ticket

Change Properties