Edgewall Software
Modify

Opened 8 years ago

Closed 6 years ago

#10280 closed defect (fixed)

Attachments page missing ticket number

Reported by: Thijs Triemstra Owned by: Christian Boos
Priority: normal Milestone: 0.12.5
Component: attachment Version: 0.13dev
Severity: normal Keywords: bitesized
Cc: ryano@… Branch:
Release Notes:

More robust processing of attachment URLs for accessing the list of attachments of a resource (i.e. /attachment/<realm>/<id> also works).

API Changes:

Description (last modified by Thijs Triemstra)

When you visit the root of an attachment page (example) a confusing page is displayed with the title 'Ticket # - Attachments' + the project name. This also happens for a ticket with no attachments at all.

I would expect the ticket number to be included and display a list of available attachments.

Attachments (0)

Change History (8)

comment:1 by Thijs Triemstra, 8 years ago

Description: modified (diff)

comment:2 by Christian Boos, 8 years ago

Actually the problem happens when the trailing slash is missing, so:

comment:3 by Remy Blank, 8 years ago

Keywords: bitesized added
Milestone: next-minor-0.12.x

comment:4 by Ryan J Ollos <ryano@…>, 7 years ago

Cc: ryano@… added

comment:5 by Ryan J Ollos <ryan.j.ollos@…>, 6 years ago

This issue has come up in several plugins: th:#10352, th:#9785, th:#9787.

comment:6 by Christian Boos, 6 years ago

Milestone: next-minor-0.12.x0.12.5
Owner: set to Christian Boos

With the following modification, a request to /attachment/ticket/698 becomes the same as one for /attachment/ticket/698/.

  • trac/attachment.py

    diff --git a/trac/attachment.py b/trac/attachment.py
    index 484c93d..cbf143d 100644
    a b class AttachmentModule(Component):  
    435435        filename = None
    436436
    437437        if not parent_realm or not path:
    438             raise HTTPBadRequest(_('Bad request'))
     438            raise HTTPBadRequest(_("Improper attachment request"))
    439439
    440440        parent_realm = Resource(parent_realm)
    441441        action = req.args.get('action', 'view')
    class AttachmentModule(Component):  
    443443            parent_id = path.rstrip('/')
    444444        else:
    445445            segments = path.split('/')
    446             parent_id = '/'.join(segments[:-1])
    447             filename = len(segments) > 1 and segments[-1]
     446            if len(segments) > 1:
     447                parent_id, filename = '/'.join(segments[:-1]), segments[-1]
     448            else:
     449                parent_id, filename = segments[0], ''
    448450
    449451        parent = parent_realm(id=parent_id)

There's one subtelty: /attachment/wiki/TracDev/Proposals/ would show the attachments for the wiki page TracDev/Proposals, whereas /attachment/wiki/TracDev/Proposals would show the attachment named Proposals for the page TracDev. I think that's OK.

comment:7 by Christian Boos, 6 years ago

…and it's perhaps not worth splitting path for joining moments later:

  • trac/attachment.py

    diff --git a/trac/attachment.py b/trac/attachment.py
    index 484c93d..cbace7a 100644
    a b class AttachmentModule(Component):  
    442442        if action == 'new':
    443443            parent_id = path.rstrip('/')
    444444        else:
    445             segments = path.split('/')
    446             parent_id = '/'.join(segments[:-1])
    447             filename = len(segments) > 1 and segments[-1]
     445            last_slash = path.rfind('/')
     446            if last_slash == -1:
     447                parent_id, filename = path, ''
     448            else:
     449                parent_id, filename = path[:last_slash], path[last_slash + 1:]
    448450
    449451        parent = parent_realm(id=parent_id)

comment:8 by Christian Boos, 6 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Last patch applied in r11356.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.