Edgewall Software

Ticket #3068: milestone_attachments_r3304.patch

File milestone_attachments_r3304.patch, 6.8 kB (added by cboos, 2 years ago)

Add the possibility to have attachments for the Milestone

  • htdocs/css/trac.css

     
    319319.attachment #preview { margin-top: 1em } 
    320320 
    321321/* Styles for the list of attachments. */ 
    322 #attachments { border: 1px outset #996; padding: 1em } 
     322#list-of-attachments { clear: both; } 
     323#attachments { border: 1px outset #996;  padding: 1em } 
    323324#attachments .attachments { margin-left: 2em; padding: 0 } 
    324325#attachments dt { display: list-item; list-style: square; } 
    325326#attachments dd { font-style: italic; margin-left: 0; padding-left: 0; } 
  • trac/attachment.py

     
    256256    # IRequestHandler methods 
    257257 
    258258    def match_request(self, req): 
    259         match = re.match(r'^/attachment/(ticket|wiki)(?:[/:](.*))?$', 
     259        match = re.match(r'^/attachment/([^/]+)(?:[/:](.*))?$', 
    260260                         req.path_info) 
    261261        if match: 
    262262            req.args['type'] = match.group(1) 
     
    268268        path = req.args.get('path') 
    269269        if not parent_type or not path: 
    270270            raise HTTPBadRequest('Bad request') 
    271         if not parent_type in ['ticket', 'wiki']: 
    272             raise HTTPBadRequest('Unknown attachment type') 
     271        #if not parent_type in ['ticket', 'wiki']: 
     272        #    raise HTTPBadRequest('Unknown attachment type') 
    273273 
    274274        action = req.args.get('action', 'view') 
    275275        if action == 'new': 
     
    308308        parent_link = req.href(parent_type, parent_id) 
    309309        if parent_type == 'ticket': 
    310310            parent_text = 'Ticket #' + parent_id 
     311        elif parent_type == 'milestone': 
     312            parent_text = 'Milestone ' + parent_id 
    311313        else: # 'wiki' 
    312314            parent_text = parent_id 
    313315        req.hdf['attachment.parent'] = { 
     
    327329    # Internal methods 
    328330 
    329331    def _do_save(self, req, attachment): 
    330         perm_map = {'ticket': 'TICKET_APPEND', 'wiki': 'WIKI_MODIFY'} 
     332        perm_map = {'ticket': 'TICKET_APPEND', 'wiki': 'WIKI_MODIFY', 
     333                    'milestone': 'MILESTONE_MODIFY'} 
    331334        req.perm.assert_permission(perm_map[attachment.parent_type]) 
    332335 
    333336        if req.args.has_key('cancel'): 
     
    367370                                            attachment.parent_id, filename) 
    368371                if not (old_attachment.author and req.authname \ 
    369372                        and old_attachment.author == req.authname): 
    370                     perm_map = {'ticket': 'TICKET_ADMIN', 'wiki': 'WIKI_DELETE'} 
     373                    perm_map = {'ticket': 'TICKET_ADMIN', 'wiki': 'WIKI_DELETE', 
     374                                'milestone': 'MILESTONE_DELETE'} 
    371375                    req.perm.assert_permission(perm_map[old_attachment.parent_type]) 
    372376                old_attachment.delete() 
    373377            except TracError: 
     
    399403                                 'mode': 'delete'} 
    400404 
    401405    def _render_form(self, req, attachment): 
    402         perm_map = {'ticket': 'TICKET_APPEND', 'wiki': 'WIKI_MODIFY'} 
     406        perm_map = {'ticket': 'TICKET_APPEND', 'wiki': 'WIKI_MODIFY', 
     407                    'milestone': 'MILESTONE_MODIFY'} 
    403408        req.perm.assert_permission(perm_map[attachment.parent_type]) 
    404409 
    405410        req.hdf['attachment'] = {'mode': 'new', 
    406411                                 'author': util.get_reporter_id(req)} 
    407412 
    408413    def _render_view(self, req, attachment): 
    409         perm_map = {'ticket': 'TICKET_VIEW', 'wiki': 'WIKI_VIEW'} 
     414        perm_map = {'ticket': 'TICKET_VIEW', 'wiki': 'WIKI_VIEW', 
     415                    'milestone': 'MILESTONE_MODIFY'} 
    410416        req.perm.assert_permission(perm_map[attachment.parent_type]) 
    411417 
    412418        req.check_modified(attachment.time) 
     
    416422        req.hdf['attachment'] = attachment_to_hdf(self.env, req, None, 
    417423                                                  attachment) 
    418424         
    419         perm_map = {'ticket': 'TICKET_ADMIN', 'wiki': 'WIKI_DELETE'} 
     425        perm_map = {'ticket': 'TICKET_ADMIN', 'wiki': 'WIKI_DELETE', 
     426                    'milestone': 'MILESTONE_DELETE'} 
    420427        if req.perm.has_permission(perm_map[attachment.parent_type]): 
    421428            req.hdf['attachment.can_delete'] = 1 
    422429 
  • trac/ticket/roadmap.py

     
    1919from time import localtime, strftime, time 
    2020 
    2121from trac import __version__ 
     22from trac.attachment import attachments_to_hdf 
    2223from trac.core import * 
    2324from trac.perm import IPermissionRequestor 
    2425from trac.util import format_date, format_datetime, parse_date, \ 
     
    445446 
    446447    def _render_view(self, req, db, milestone): 
    447448        req.hdf['title'] = 'Milestone %s' % milestone.name 
    448         req.hdf['milestone.mode'] = 'view' 
    449  
     449        req.hdf['milestone'] = { 
     450            'mode': 'view', 
     451            'attachments': attachments_to_hdf(self.env, req, db, 
     452                                              'milestone', milestone.name), 
     453            } 
     454        if req.perm.has_permission('MILESTONE_MODIFY'): 
     455            req.hdf['milestone.attach_href'] = req.href.attachment('milestone', 
     456                                                                   milestone.name) 
    450457        req.hdf['milestone'] = milestone_to_hdf(self.env, db, req, milestone) 
    451  
    452458        available_groups = [] 
    453459        component_group_available = False 
    454460        for field in TicketSystem(self.env).get_ticket_fields(): 
  • templates/macros.cs

     
    172172/def ?><?cs  
    173173 
    174174def:list_of_attachments(attachments, attach_href) ?> 
     175<div id="list-of-attachments"> 
    175176<h2>Attachments</h2><?cs 
    176177 if:len(attachments) ?><div id="attachments"> 
    177178  <dl class="attachments"><?cs each:attachment = attachments ?> 
     
    189190   <input type="hidden" name="action" value="new" /> 
    190191   <input type="submit" value="Attach File" /> 
    191192  </div></form><?cs 
    192  /if ?><?cs if:len(attachments) ?></div><?cs /if ?><?cs 
     193 /if ?><?cs if:len(attachments) ?></div><?cs /if ?></div><?cs 
    193194/def ?> 
  • templates/milestone.cs

     
    194194   </fieldset> 
    195195  </form> 
    196196  <div class="description"><?cs var:milestone.description ?></div><?cs 
     197  if:milestone.attach_href || len(milestone.attachments) ?><?cs  
     198   call:list_of_attachments(milestone.attachments, milestone.attach_href) ?><?cs 
     199  /if ?><?cs 
    197200  if:trac.acl.MILESTONE_MODIFY || trac.acl.MILESTONE_DELETE ?> 
    198201   <div class="buttons"><?cs 
    199202    if:trac.acl.MILESTONE_MODIFY ?>