Modify

Opened 5 months ago

Last modified 7 weeks ago

#13237 assigned enhancement

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

Reported by: Jon Ashley Owned by: Jon Ashley
Priority: normal Component: AdvancedTicketWorkflowPlugin
Severity: normal Keywords:
Cc: Trac Release: 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.

Attachments (1)

controller.py.patch (3.2 KB) - added by Jon Ashley 5 months ago.
Patch to add new operations as described

Download all attachments as: .zip

Change History (8)

Changed 5 months ago by Jon Ashley

Attachment: controller.py.patch added

Patch to add new operations as described

comment:1 Changed 5 months ago by Ryan J Ollos

Owner: set to Jon Ashley
Status: newassigned

comment:2 Changed 5 months ago by Ryan J Ollos

Thanks, I will test out the patch very soon.

comment:3 Changed 5 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),
                 username=req.authname)

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 5 months ago by Jun Omae

Replying to 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 7 weeks ago by Jon Ashley

In 16901:

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

comment:6 Changed 7 weeks 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 7 weeks ago by Jon Ashley

In 16904:

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as assigned The owner will remain Jon Ashley.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.