Skip to content

Commit 2e85bec

Browse files
author
Unknown
committed
Three sets of changes:
1) Make sure that a user doesn't create a query with the same name as an existing query that the user owns. 2) When submitting a new named query, display the name of the query on the index page. 3) Allow optional arguments to indexargs_url by setting their value to None. This will show the argument only if there is a valid value. To match these, changed the template for all search templates so if an error is thrown due to #1 the user stays on the search page so they can fix the issue. Note that I did not add automated tests for these because I couldn't find existing tests for these code paths that I could adapt. I don't understand how the existing Action tests work and there is no doc for them.
1 parent be7e43a commit 2e85bec

File tree

9 files changed

+86
-3
lines changed

9 files changed

+86
-3
lines changed

CHANGES.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,25 @@ Fixed:
378378
- issue2550932 - html_calendar produces templating errors for bad date
379379
strings. Fixed to ignore bad date and highlight todays date in the
380380
calendar popup.
381+
- Query handling requires that query names for a user are unique.
382+
Different users are allowed to use the same query name. Under some
383+
circumstances a user could generate a second query with the same
384+
name. The SearchAction function has been corrected to report this
385+
error. Also the index.search.html template in the classic tracker
386+
and corresponding templates in the other example trackers
387+
has been modified to include:
388+
<input type="hidden" name="@template" value="index|search"/>
389+
so an error from SearchAction will display an error message and keep
390+
the user on the search page so they can correct the error. See
391+
``doc/upgrading.txt``. (John Rouillard)
392+
- When a new named search is created, the index page that is displayed
393+
doesn't show the name. This has been fixed by setting the @dispname
394+
to the query's name. (John Rouillard)
395+
- Passing args into indexargs_url(..,{'@queryname': request/dispname
396+
or None, 'Title': 'some' }) where the value of the arg is None
397+
will not add the arg to the url. In the example above @queryname
398+
will only be in the url if dispname is set in the request.
399+
(John Rouillard)
381400

382401
2016-01-11: 1.5.1
383402

doc/upgrading.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,24 @@ parameter. This is expected to be the preferred form in the future.
396396
You do not need to use the ``ctx`` parameter in the function if you do
397397
not need it.
398398

399+
Improve query editing
400+
---------------------
401+
402+
The query editing interface will now report an error if the user
403+
creates a new query that they are already using. By default the query
404+
editing page (issue.search.html) displays the index page when the
405+
search is triggered. Since the user expects to see the results of the
406+
query, this is usually the right thing. But now that the code properly
407+
checks for duplicate search names, the user should stay on the search
408+
page if there is an error. To add this to your existing
409+
index.search.html page, add the following line after the hidden field
410+
@old-queryname:
411+
412+
<input type="hidden" name="@template" value="index|search"/>
413+
414+
With this addition, the index template is displayed if there is no
415+
error, and the user stays on the search template if there is an error.
416+
399417
Migrating from 1.5.0 to 1.5.1
400418
=============================
401419

roundup/cgi/actions.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ def handle(self):
299299
key = self.db.query.getkey()
300300
if key:
301301
# edit the old way, only one query per name
302+
# Note that use of queryname as key will automatically
303+
# raise an error if there are duplicate names.
302304
try:
303305
qid = self.db.query.lookup(old_queryname)
304306
if not self.hasPermission('Edit', 'query', itemid=qid):
@@ -313,9 +315,29 @@ def handle(self):
313315
qid = self.db.query.create(name=queryname,
314316
klass=self.classname, url=url)
315317
else:
318+
uid = self.db.getuid()
319+
320+
# if the queryname is being changed from the old
321+
# (original) value, make sure new queryname is not
322+
# already in use by user.
323+
# if in use, return to edit/search screen and let
324+
# user change it.
325+
326+
if old_queryname != queryname:
327+
# we have a name change
328+
qids = self.db.query.filter(None, {'name': queryname,
329+
'creator': uid})
330+
for qid in qids:
331+
# require an exact name match
332+
if queryname != self.db.query.get(qid, 'name'):
333+
continue
334+
# whoops we found a duplicate; report error and return
335+
message=_("You already own a query named '%s'. Please choose another name.")%(queryname)
336+
self.client.add_error_message(message)
337+
return
338+
316339
# edit the new way, query name not a key any more
317340
# see if we match an existing private query
318-
uid = self.db.getuid()
319341
qids = self.db.query.filter(None, {'name': old_queryname,
320342
'private_for': uid})
321343
if not qids:
@@ -351,6 +373,16 @@ def handle(self):
351373
# commit the query change to the database
352374
self.db.commit()
353375

376+
# This redirects to the index page. Add the @dispname
377+
# url param to the request so that the query name
378+
# is displayed.
379+
req.form.list.append(
380+
cgi.MiniFieldStorage(
381+
"@dispname", queryname
382+
)
383+
)
384+
385+
354386
def fakeFilterVars(self):
355387
"""Add a faked :filter form variable for each filtering prop."""
356388
cls = self.db.classes[self.classname]

roundup/cgi/templating.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,12 +2780,21 @@ def add(k, v):
27802780

27812781
def indexargs_url(self, url, args):
27822782
""" Embed the current index args in a URL
2783+
2784+
If the value of an arg (in args dict) is None,
2785+
the argument is excluded from the url. If you want
2786+
an empty value use an empty string '' as the value.
2787+
Use this in templates to conditionally
2788+
include an arg if it is set to a value. E.G.
2789+
{..., '@queryname': request.dispname or None, ...}
2790+
will include @queryname in the url if there is a
2791+
dispname otherwise the parameter will be omitted
2792+
from the url.
27832793
"""
27842794
q = urllib.quote
27852795
sc = self.special_char
27862796
l = ['%s=%s'%(k,isinstance(v, basestring) and q(v) or v)
2787-
for k,v in args.items()]
2788-
2797+
for k,v in args.items() if v != None ]
27892798
# pull out the special values (prefixed by @ or :)
27902799
specials = {}
27912800
for key in args.keys():

share/roundup/templates/classic/html/issue.search.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
<td tal:define="value request/form/@queryname/value | nothing">
204204
<input name="@queryname" tal:attributes="value value">
205205
<input type="hidden" name="@old-queryname" tal:attributes="value value">
206+
<input type="hidden" name="@template" value="index|search">
206207
</td>
207208
</tr>
208209

share/roundup/templates/devel/html/bug.search.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
<td tal:define="value request/form/@queryname/value | nothing">
281281
<input name="@queryname" tal:attributes="value value"/>
282282
<input type="hidden" name="@old-queryname" tal:attributes="value value"/>
283+
<input type="hidden" name="@template" value="index|search"/>
283284
</td>
284285
</tr>
285286

share/roundup/templates/devel/html/task.search.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
<td tal:define="value request/form/@queryname/value | nothing">
281281
<input name="@queryname" tal:attributes="value value"/>
282282
<input type="hidden" name="@old-queryname" tal:attributes="value value"/>
283+
<input type="hidden" name="@template" value="index|search"/>
283284
</td>
284285
</tr>
285286

share/roundup/templates/responsive/html/bug.search.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
<td tal:define="value request/form/@queryname/value | nothing">
281281
<input name="@queryname" tal:attributes="value value"/>
282282
<input type="hidden" name="@old-queryname" tal:attributes="value value"/>
283+
<input type="hidden" name="@template" value="index|search"/>
283284
</td>
284285
</tr>
285286

share/roundup/templates/responsive/html/task.search.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
<td tal:define="value request/form/@queryname/value | nothing">
242242
<input name="@queryname" tal:attributes="value value"/>
243243
<input type="hidden" name="@old-queryname" tal:attributes="value value"/>
244+
<input type="hidden" name="@template" value="index|search"/>
244245
</td>
245246
</tr>
246247

0 commit comments

Comments
 (0)