Edgewall Software

Ticket #1459: add_remove_checkbox_for_CC-r6191.patch

File add_remove_checkbox_for_CC-r6191.patch, 5.8 KB (added by cboos, 4 years ago)

If TICKET_EDIT_CC permission is not given, then instead of the input field, there's a Add to Cc: / Remove from Cc: address checkbox.

  • trac/ticket/api.py

     
    275275 
    276276    def get_permission_actions(self): 
    277277        return ['TICKET_APPEND', 'TICKET_CREATE', 'TICKET_CHGPROP', 
    278                 'TICKET_VIEW', 
    279                 ('TICKET_MODIFY', ['TICKET_APPEND', 'TICKET_CHGPROP']),   
     278                'TICKET_VIEW', 'TICKET_EDIT_CC', 
     279                ('TICKET_MODIFY', ['TICKET_APPEND', 'TICKET_CHGPROP', 
     280                                   'TICKET_EDIT_CC']),   
    280281                ('TICKET_ADMIN', ['TICKET_CREATE', 'TICKET_MODIFY',   
    281282                                  'TICKET_VIEW'])] 
    282283 
  • trac/ticket/web_ui.py

     
    538538                                                absurls=absurls), 
    539539                'preserve_newlines': preserve_newlines} 
    540540 
     541    def _toggle_cc(self, req, cc): 
     542        """Return an (action, recipient) tuple corresponding to a change 
     543        of CC status for this user relative to the current `cc_list`.""" 
     544        entries = [] 
     545        email = req.session.get('email', '').strip() 
     546        if email: 
     547            entries.append(email) 
     548        if req.authname != 'anonymous': 
     549            entries.append(req.authname) 
     550        else: 
     551            author = get_reporter_id(req, 'author').strip() 
     552            if author != 'anonymous': 
     553                entries.append(author) 
     554        add = [] 
     555        remove = [] 
     556        cc_list = Chrome(self.env).cc_list(cc) 
     557        for entry in entries: 
     558            if entry in cc_list: 
     559                remove.append(entry) 
     560            else: 
     561                add.append(entry) 
     562        print repr((entries, cc_list, add, remove)) 
     563        action = entry = '' 
     564        if remove: 
     565            action, entry = ('remove', remove[0]) 
     566        elif add: 
     567            action, entry = ('add', add[0]) 
     568        return (action, entry, cc_list) 
     569         
    541570    def _populate(self, req, ticket): 
    542571        ticket.populate(dict([(k[6:],v) for k,v in req.args.iteritems() 
    543572                              if k.startswith('field_')])) 
    544573 
     574        # special case for updating the Cc: field 
     575        if 'cc_update' in req.args: 
     576            cc_action, cc_entry, cc_list = self._toggle_cc(req, ticket['cc']) 
     577            if cc_action == 'remove': 
     578                cc_list.remove(cc_entry) 
     579            elif cc_action == 'add': 
     580                cc_list.append(cc_entry) 
     581            print repr((cc_entry, cc_list, ', '.join(cc_list))) 
     582            ticket['cc'] = ', '.join(cc_list) 
     583 
    545584    def _get_history(self, req, ticket): 
    546585        history = [] 
    547586        for change in self.rendered_changelog_entries(req, ticket): 
     
    9821021                field['rendered'] = render_resource_link(self.env, context, 
    9831022                                                         milestone, 'compact') 
    9841023            elif name == 'cc': 
    985                 emails = Chrome(self.env).format_emails(context, ticket[name]) 
     1024                emails = Chrome(self.env).format_emails(context, ticket[name])  
    9861025                field['rendered'] = emails 
     1026                if ticket.exists and \ 
     1027                        'TICKET_EDIT_CC' not in req.perm(ticket.resource): 
     1028                    cc = ticket._old.get('cc', ticket['cc']) 
     1029                    cc_action, cc_entry, cc_list = self._toggle_cc(req, cc) 
     1030                    field['edit_label'] = { 
     1031                            'add': _("Add to Cc"), 
     1032                            'remove': _("Remove from Cc"), 
     1033                            '': _("Add/Remove from Cc")}[cc_action] 
     1034                    field['cc_entry'] = cc_entry or _("the <Author>") 
     1035                    field['cc_update'] = 'cc_update' in req.args or None 
    9871036 
    9881037            # per type settings 
    9891038            if type_ in ('radio', 'select'): 
  • trac/ticket/templates/ticket.html

     
    309309              <py:for each="idx, field in enumerate(row)"> 
    310310                <th class="col${idx + 1}" py:if="idx == 0 or not fullrow"> 
    311311                  <label for="field-${field.name}" py:if="field" 
    312                          py:strip="field.type == 'radio'">${field.label or field.name}:</label> 
     312                         py:strip="field.type == 'radio'">${field.edit_label or field.label or field.name}:</label> 
    313313                </th> 
    314314                <td class="col${idx + 1}" py:if="idx == 0 or not fullrow" 
    315315                    colspan="${fullrow and 3 or None}"> 
     
    340340                             checked="${ticket[field.name] == option or None}" /> 
    341341                      ${option} 
    342342                    </label> 
    343                     <input py:otherwise="" type="text" id="field-${field.name}" 
    344                            name="field_${field.name}" value="${ticket[field.name]}" /> 
     343                    <py:otherwise><!--! Text input fields --> 
     344                      <py:choose> 
     345                        <span py:when="field.cc_entry"><!--! Special case for Cc: field --> 
     346                          <em>${field.cc_entry}</em> 
     347                          <input type="checkbox" id="field-cc" name="cc_update" checked="${field.cc_update}" /> 
     348                        </span> 
     349                        <!--! All the other text input fields, including Cc: when TICKET_EDIT_CC is allowed --> 
     350                        <input py:otherwise="" type="text" id="field-${field.name}" 
     351                          name="field_${field.name}" value="${ticket[field.name]}" /> 
     352                      </py:choose> 
     353                    </py:otherwise> 
    345354                  </py:choose> 
    346355                </td> 
    347356              </py:for>