Ticket #8884: 8884-workflow-fixes-r8981.patch
| File 8884-workflow-fixes-r8981.patch, 5.9 KB (added by rblank, 2 years ago) |
|---|
-
trac/ticket/model.py
diff --git a/trac/ticket/model.py b/trac/ticket/model.py
a b 35 35 36 36 class Ticket(object): 37 37 38 # Fields that must not be modified directly by the user 39 protected_fields = ('resolution', 'status', 'time', 'changetime') 40 38 41 @staticmethod 39 42 def id_is_valid(num): 40 43 return 0 < int(num) <= 1L << 31 … … 73 76 def _init_defaults(self, db=None): 74 77 for field in self.fields: 75 78 default = None 76 if field['name'] in ['resolution', 'status', 'time', 'changetime']:79 if field['name'] in self.protected_fields: 77 80 # Ignore for new - only change through workflow 78 81 pass 79 82 elif not field.get('custom'): -
trac/ticket/templates/ticket.html
diff --git a/trac/ticket/templates/ticket.html b/trac/ticket/templates/ticket.html
a b 487 487 <a href="#attachments" title="Go to the list of attachments">Attachments</a> ↑ 488 488 </div> 489 489 <div class="buttons"> 490 <input py:if="not ticket.exists" type="hidden" name="field_status" value="new" />491 490 <py:if test="ticket.exists"> 492 491 <input type="hidden" name="ts" value="${timestamp}" /> 493 492 <input type="hidden" name="replyto" value="${replyto}" /> -
trac/ticket/web_ui.py
diff --git a/trac/ticket/web_ui.py b/trac/ticket/web_ui.py
a b 374 374 del req.args['field_owner'] 375 375 376 376 self._populate(req, ticket, plain_fields) 377 ticket.values['status'] = 'new' # Force initial status 377 378 reporter_id = req.args.get(field_reporter) or \ 378 379 get_reporter_id(req, 'author') 379 380 ticket.values['reporter'] = reporter_id … … 506 507 if problems: 507 508 for problem in problems: 508 509 add_warning(req, problem) 509 add_warning(req, 510 tag(tag.p('Please review your configuration, ' 511 'probably starting with'), 512 tag.pre('[trac]\nworkflow = ...\n'), 513 tag.p('in your ', tag.tt('trac.ini'), '.')) 514 ) 510 add_warning(req, 511 tag(tag.p('Please review your configuration, ' 512 'probably starting with'), 513 tag.pre('[trac]\nworkflow = ...\n'), 514 tag.p('in your ', tag.tt('trac.ini'), '.'))) 515 515 516 self._apply_ticket_changes(ticket, field_changes) # Apply changes made by the workflow 516 # Apply changes made by the workflow 517 self._apply_ticket_changes(ticket, field_changes) 517 518 # Unconditionally run the validation so that the user gets 518 519 # information any and all problems. But it's only valid if it 519 520 # validates and there were no problems with the workflow side of … … 658 659 return (action, entry, cc_list) 659 660 660 661 def _populate(self, req, ticket, plain_fields=False): 661 fields = req.args662 662 if not plain_fields: 663 fields = dict([(k[6:], v) for k, v in fields.items()663 fields = dict([(k[6:], v) for k, v in req.args.iteritems() 664 664 if k.startswith('field_')]) 665 else: 666 fields = req.args.copy() 667 # Prevent direct changes to protected fields (status and resolution are 668 # set in the workflow, in get_ticket_changes()) 669 for each in Ticket.protected_fields: 670 fields.pop(each, None) 671 fields.pop('checkbox_' + each, None) # See Ticket.populate() 665 672 ticket.populate(fields) 666 673 # special case for updating the Cc: field 667 674 if 'cc_update' in req.args: … … 1049 1056 1050 1057 # If the ticket has been changed, check the proper permissions 1051 1058 if ticket.exists and ticket._old: 1052 cnt = 0 1053 # EDIT_DESCRIPTION and CHGPROP are independent permissions 1054 if 'description' in ticket._old: 1055 cnt = 1 1056 if 'TICKET_EDIT_DESCRIPTION' not in req.perm(resource): 1057 add_warning(req, _("No permission to edit description.")) 1058 valid = False 1059 if len(ticket._old) > cnt: 1060 errmsg = _("No permission to change ticket fields.") 1061 if 'TICKET_CHGPROP' not in req.perm(resource): 1062 add_warning(req, errmsg) 1063 valid = False 1064 else: # per-field additional checks 1065 if 'reporter' in ticket._old and \ 1066 'TICKET_ADMIN' not in req.perm(resource): 1067 add_warning(req, errmsg) 1068 valid = False 1059 # Status and resolution can be modified by the workflow even 1060 # without having TICKET_CHGPROP 1061 changed = set(ticket._old) - set(['status', 'resolution']) 1062 if 'description' in changed \ 1063 and 'TICKET_EDIT_DESCRIPTION' not in req.perm(resource): 1064 add_warning(req, _("No permission to edit the ticket " 1065 "description.")) 1066 valid = False 1067 changed.discard('description') 1068 if 'reporter' in changed \ 1069 and 'TICKET_ADMIN' not in req.perm(resource): 1070 add_warning(req, _("No permission to change the ticket " 1071 "reporter.")) 1072 valid = False 1073 changed.discard('reporter') 1074 if changed and 'TICKET_CHGPROP' not in req.perm(resource): 1075 add_warning(req, _("No permission to change ticket fields.")) 1076 valid = False 1069 1077 if not valid: 1070 1078 ticket.values.update(ticket._old) 1071 1079
