* trac/attachment.py
(AttachmentModule._do_save):
Use util.get_authentic_id() instead of just req.args.get().
(AttachmentModule._render_form):
Add fieldname argument to util.get_reporter_id() call.
* trac/ticket/web_ui.py:
(NewticketModule.process_request): No effective behaviour change, but use
code more consistent in style with similar operations elsewhere.
(NewticketModule._do_create): Use util.get_authentic_id(). Logic is
unchanged except for the addition of authentic-making the username,
but the code is simplified.
(TicketModule.process_request): Simplify code, with inconsequential
logic changes.
(TicketModule._do_save):
Use util.get_authentic_id() instead of just req.args.get().
* trac/util.py (get_reporter_id):
Always return req.authname if the request is authenticated.
Add capability to fetch a value from a form field if one was specified.
(get_authentic_id): New function - return req.authname if the request is
authenticated, otherwise call get_reporter_id and mangle the return
value to indicate its unauthenticated nature.
* trac/wiki/web_ui.py: Import util.get_authentic_id.
(WikiModule._do_save):
Use util.get_authentic_id() instead of just req.args.get().
(WikiModule._render_editor): Logic unchanged. Code simplified by making
use of the new behaviour of get_reporter_id.
* templates/attachment.cs, templates/newticket.cs, templates/ticket.cs,
templates/wiki.cs: Only show "Your email or username:" field if not
authenticated.
diff -ru trac-0.9.5.orig/templates/attachment.cs trac-0.9.5/templates/attachment.cs
|
old
|
new
|
|
| 14 | 14 | </div> |
| 15 | 15 | <fieldset> |
| 16 | 16 | <legend>Attachment Info</legend> |
| 17 | | <div class="field"> |
| 18 | | <label>Your email or username:<br /> |
| 19 | | <input type="text" name="author" size="30" value="<?cs |
| 20 | | var:attachment.author?>" /></label> |
| 21 | | </div> |
| | 17 | <?cs if:trac.authname == "anonymous" ?> |
| | 18 | <div class="field"> |
| | 19 | <label>Your email or username:<br /> |
| | 20 | <input type="text" name="author" size="30" value="<?cs |
| | 21 | var:attachment.author?>" /></label> |
| | 22 | </div> |
| | 23 | <?cs /if ?> |
| 22 | 24 | <div class="field"> |
| 23 | 25 | <label>Description of the file (optional):<br /> |
| 24 | 26 | <input type="text" name="description" size="60" /></label> |
diff -ru trac-0.9.5.orig/templates/newticket.cs trac-0.9.5/templates/newticket.cs
|
old
|
new
|
|
| 11 | 11 | <?cs include:"site_newticket.cs" ?> |
| 12 | 12 | <form id="newticket" method="post" action="<?cs |
| 13 | 13 | var:trac.href.newticket ?>#preview"> |
| 14 | | <div class="field"> |
| 15 | | <label for="reporter">Your email or username:</label><br /> |
| 16 | | <input type="text" id="reporter" name="reporter" size="40" value="<?cs |
| 17 | | var:newticket.reporter ?>" /><br /> |
| 18 | | </div> |
| | 14 | <?cs if:trac.authname == "anonymous" ?> |
| | 15 | <div class="field"> |
| | 16 | <label for="reporter">Your email or username:</label><br /> |
| | 17 | <input type="text" id="reporter" name="reporter" size="40" value="<?cs |
| | 18 | var:newticket.reporter ?>" /><br /> |
| | 19 | </div> |
| | 20 | <?cs /if ?> |
| 19 | 21 | <div class="field"> |
| 20 | 22 | <label for="summary">Short summary:</label><br /> |
| 21 | 23 | <input id="summary" type="text" name="summary" size="80" value="<?cs |
diff -ru trac-0.9.5.orig/templates/ticket.cs trac-0.9.5/templates/ticket.cs
|
old
|
new
|
|
| 126 | 126 | <hr /> |
| 127 | 127 | <h3><a name="edit" onfocus="document.getElementById('comment').focus()">Add/Change #<?cs |
| 128 | 128 | var:ticket.id ?> (<?cs var:ticket.summary ?>)</a></h3> |
| 129 | | <div class="field"> |
| 130 | | <label for="author">Your email or username:</label><br /> |
| 131 | | <input type="text" id="author" name="author" size="40" |
| 132 | | value="<?cs var:ticket.reporter_id ?>" /><br /> |
| 133 | | </div> |
| | 129 | <?cs if:trac.authname == "anonymous" ?> |
| | 130 | <div class="field"> |
| | 131 | <label for="author">Your email or username:</label><br /> |
| | 132 | <input type="text" id="author" name="author" size="40" |
| | 133 | value="<?cs var:ticket.reporter_id ?>" /><br /> |
| | 134 | </div> |
| | 135 | <?cs /if ?> |
| 134 | 136 | <div class="field"> |
| 135 | 137 | <fieldset class="iefix"> |
| 136 | 138 | <label for="comment">Comment (you may use <a tabindex="42" href="<?cs |
diff -ru trac-0.9.5.orig/templates/wiki.cs trac-0.9.5/templates/wiki.cs
|
old
|
new
|
|
| 235 | 235 | </div> |
| 236 | 236 | <fieldset id="changeinfo"> |
| 237 | 237 | <legend>Change information</legend> |
| 238 | | <div class="field"> |
| 239 | | <label>Your email or username:<br /> |
| 240 | | <input id="author" type="text" name="author" size="30" value="<?cs |
| 241 | | var:wiki.author ?>" /></label> |
| 242 | | </div> |
| | 238 | <?cs if:trac.authname == "anonymous" ?> |
| | 239 | <div class="field"> |
| | 240 | <label>Your email or username:<br /> |
| | 241 | <input id="author" type="text" name="author" size="30" value="<?cs |
| | 242 | var:wiki.author ?>" /></label> |
| | 243 | </div> |
| | 244 | <?cs /if ?> |
| 243 | 245 | <div class="field"> |
| 244 | 246 | <label>Comment about this change (optional):<br /> |
| 245 | 247 | <input id="comment" type="text" name="comment" size="60" value="<?cs |
diff -ru trac-0.9.5.orig/trac/attachment.py trac-0.9.5/trac/attachment.py
|
old
|
new
|
|
| 318 | 318 | 'utf-8')).encode('utf-8') |
| 319 | 319 | |
| 320 | 320 | attachment.description = req.args.get('description', '') |
| 321 | | attachment.author = req.args.get('author', '') |
| | 321 | attachment.author = util.get_authentic_id(req, 'author') |
| 322 | 322 | attachment.ipnr = req.remote_addr |
| 323 | 323 | if req.args.get('replace'): |
| 324 | 324 | try: |
| … |
… |
|
| 376 | 376 | text, link = self._get_parent_link(attachment) |
| 377 | 377 | req.hdf['attachment'] = { |
| 378 | 378 | 'mode': 'new', |
| 379 | | 'author': util.get_reporter_id(req), |
| | 379 | 'author': util.get_reporter_id(req, 'author'), |
| 380 | 380 | 'parent': {'type': attachment.parent_type, |
| 381 | 381 | 'id': attachment.parent_id, 'name': text, 'href': link} |
| 382 | 382 | } |
diff -ru trac-0.9.5.orig/trac/ticket/web_ui.py trac-0.9.5/trac/ticket/web_ui.py
|
old
|
new
|
|
| 84 | 84 | |
| 85 | 85 | ticket = Ticket(self.env, db=db) |
| 86 | 86 | ticket.populate(req.args) |
| 87 | | ticket.values.setdefault('reporter', util.get_reporter_id(req)) |
| | 87 | ticket.values['reporter'] = util.get_reporter_id(req, 'reporter') |
| 88 | 88 | |
| 89 | 89 | if ticket.values.has_key('description'): |
| 90 | 90 | description = wiki_to_html(ticket['description'], self.env, req, db) |
| … |
… |
|
| 133 | 133 | raise TracError('Tickets must contain a summary.') |
| 134 | 134 | |
| 135 | 135 | ticket = Ticket(self.env, db=db) |
| 136 | | ticket.values.setdefault('reporter', util.get_reporter_id(req)) |
| 137 | 136 | ticket.populate(req.args) |
| | 137 | ticket.values['reporter'] = util.get_authentic_id(req, 'reporter') |
| 138 | 138 | ticket.insert(db=db) |
| 139 | 139 | db.commit() |
| 140 | 140 | |
| … |
… |
|
| 182 | 182 | id = int(req.args.get('id')) |
| 183 | 183 | |
| 184 | 184 | ticket = Ticket(self.env, id, db=db) |
| 185 | | reporter_id = util.get_reporter_id(req) |
| 186 | 185 | |
| 187 | 186 | if req.method == 'POST': |
| 188 | 187 | if not req.args.has_key('preview'): |
| … |
… |
|
| 195 | 194 | req.hdf['ticket.reassign_owner'] = req.args.get('reassign_owner') \ |
| 196 | 195 | or req.authname |
| 197 | 196 | req.hdf['ticket.resolve_resolution'] = req.args.get('resolve_resolution') |
| 198 | | reporter_id = req.args.get('author') |
| 199 | 197 | comment = req.args.get('comment') |
| 200 | 198 | if comment: |
| 201 | 199 | req.hdf['ticket.comment'] = comment |
| … |
… |
|
| 208 | 206 | # Store a timestamp in order to detect "mid air collisions" |
| 209 | 207 | req.hdf['ticket.ts'] = ticket.time_changed |
| 210 | 208 | |
| 211 | | self._insert_ticket_data(req, db, ticket, reporter_id) |
| | 209 | self._insert_ticket_data(req, db, ticket, |
| | 210 | util.get_reporter_id(req, 'author')) |
| 212 | 211 | |
| 213 | 212 | # If the ticket is being shown in the context of a query, add |
| 214 | 213 | # links to help navigate in the query result set |
| … |
… |
|
| 343 | 342 | ticket['resolution'] = '' |
| 344 | 343 | |
| 345 | 344 | now = int(time.time()) |
| 346 | | ticket.save_changes(req.args.get('author', req.authname), |
| | 345 | ticket.save_changes(util.get_authentic_id(req, 'author'), |
| 347 | 346 | req.args.get('comment'), when=now, db=db) |
| 348 | 347 | db.commit() |
| 349 | 348 | |
diff -ru trac-0.9.5.orig/trac/util.py trac-0.9.5/trac/util.py
|
old
|
new
|
|
| 381 | 381 | raise Exception('Failed to create unique name: ' + path) |
| 382 | 382 | path = '%s.%d%s' % (parts[0], idx, parts[1]) |
| 383 | 383 | |
| 384 | | def get_reporter_id(req): |
| 385 | | name = req.session.get('name', None) |
| 386 | | email = req.session.get('email', None) |
| 387 | | |
| | 384 | def get_reporter_id(req, argname): |
| 388 | 385 | if req.authname != 'anonymous': |
| 389 | 386 | return req.authname |
| 390 | | elif name and email: |
| | 387 | |
| | 388 | r = req.args.get(argname) |
| | 389 | if r: |
| | 390 | return r |
| | 391 | name = req.session.get('name', None) |
| | 392 | email = req.session.get('email', None) |
| | 393 | if name and email: |
| 391 | 394 | return '%s <%s>' % (name, email) |
| 392 | 395 | elif not name and email: |
| 393 | 396 | return email |
| 394 | 397 | else: |
| 395 | 398 | return req.authname |
| 396 | 399 | |
| | 400 | def get_authentic_id(req, argname): |
| | 401 | if req.authname != 'anonymous': |
| | 402 | return req.authname |
| | 403 | r = get_reporter_id(req, argname) |
| | 404 | if r == 'anonymous': |
| | 405 | return r |
| | 406 | return r + ' [unauthenticated]' |
| | 407 | |
| 397 | 408 | # Date/time utilities |
| 398 | 409 | |
| 399 | 410 | def format_datetime(t=None, format='%x %X', gmt=False): |
diff -ru trac-0.9.5.orig/trac/wiki/web_ui.py trac-0.9.5/trac/wiki/web_ui.py
|
old
|
new
|
|
| 26 | 26 | from trac.Search import ISearchSource, query_to_sql, shorten_result |
| 27 | 27 | from trac.Timeline import ITimelineEventProvider |
| 28 | 28 | from trac.util import enum, format_datetime, get_reporter_id, \ |
| | 29 | get_authentic_id, \ |
| 29 | 30 | pretty_timedelta, shorten_line, Markup |
| 30 | 31 | from trac.versioncontrol.diff import get_diff_options, hdf_diff |
| 31 | 32 | from trac.web.chrome import add_link, add_stylesheet, INavigationContributor |
| … |
… |
|
| 183 | 184 | # WIKI_ADMIN |
| 184 | 185 | page.readonly = int(req.args.has_key('readonly')) |
| 185 | 186 | |
| 186 | | page.save(req.args.get('author'), req.args.get('comment'), |
| | 187 | page.save(get_authentic_id(req, 'author'), req.args.get('comment'), |
| 187 | 188 | req.remote_addr) |
| 188 | 189 | req.redirect(self.env.href.wiki(page.name)) |
| 189 | 190 | |
| … |
… |
|
| 283 | 284 | if preview: |
| 284 | 285 | page.readonly = req.args.has_key('readonly') |
| 285 | 286 | |
| 286 | | author = req.args.get('author', get_reporter_id(req)) |
| | 287 | author = get_reporter_id(req, 'author') |
| 287 | 288 | comment = req.args.get('comment', '') |
| 288 | 289 | editrows = req.args.get('editrows') |
| 289 | 290 | if editrows: |