Search code examples
trac

Assign new ticket to logged in user


In Trac is possible to set the "owner" for a new ticket to the logged in user ? I've tried with different value for default_owner in trac.ini but no luck


Solution

  • From trac.edgewall.org authoritative documentation in Trac tickets (wiki):

    default_owner: Name of the default owner. If set to the text "< default >" (the default value), the component owner is used.

    So this is cannot help you for sure. There are a few more approaches left, depending on you Genshi template knowledge, Python skills etc. Your requirement is not hard to fulfill, but you cannot get it with stock Trac. You'll need to modify the (new) ticket template or add a relatively small plugin (tested with Trac-1.1.1):

    import re
    from trac.core import Component, implements
    from trac.ticket.api import ITicketManipulator
    
    class DefaultTicketOwnerManipulator(Component):
    """Set ticket owner to logged in user, if available."""
    
        implements(ITicketManipulator)
    
        def prepare_ticket(self, req, ticket, fields, actions):
            pass
    
        def validate_ticket(self, req, ticket):
            if not ticket['owner'] and req.authname:
                ticket['owner'] = req.authname
                # Optionally report-back manipulation, so require a second POST.
                # return [(None, "Owner set to self (%s)" % req.authname)]
            return []
    

    Hint: Use commented-out 'return' in pre-last line to not alter owner silently right on save, good for test too.