• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

Revisionc4c83ee90206155f82fe559a457392c6c1e581dc (tree)
Zeit2012-07-11 13:27:52
AutorDave Brondsema <dbrondsema@geek...>
CommiterDave Brondsema

Log Message

[#4272] refactor paged_* methods to remove unrelated column vars and make app & user explicit params

Ändern Zusammenfassung

Diff

--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -577,14 +577,14 @@ class Ticket(VersionedArtifact, ActivityObject):
577577 custom_fields=self.custom_fields)
578578
579579 @classmethod
580- def paged_query(cls, query, limit=None, page=0, sort=None, columns=None, **kw):
580+ def paged_query(cls, app_config, user, query, limit=None, page=0, sort=None, **kw):
581581 """
582582 Query tickets, filtering for 'read' permission, sorting and paginating the result.
583583
584584 See also paged_search which does a solr search
585585 """
586586 limit, page, start = g.handle_paging(limit, page, default=25)
587- q = cls.query.find(dict(query, app_config_id=c.app.config._id))
587+ q = cls.query.find(dict(query, app_config_id=app_config._id))
588588 q = q.sort('ticket_num')
589589 if sort:
590590 field, direction = sort.split()
@@ -599,29 +599,17 @@ class Ticket(VersionedArtifact, ActivityObject):
599599 tickets = []
600600 count = q.count()
601601 for t in q:
602- if security.has_access(t, 'read'):
602+ if security.has_access(t, 'read', user, app_config.project):
603603 tickets.append(t)
604604 else:
605605 count = count -1
606- sortable_custom_fields=c.app.globals.sortable_custom_fields_shown_in_search()
607- if not columns:
608- columns = [dict(name='ticket_num', sort_name='ticket_num', label='Ticket Number', active=True),
609- dict(name='summary', sort_name='summary', label='Summary', active=True),
610- dict(name='_milestone', sort_name='custom_fields._milestone', label='Milestone', active=True),
611- dict(name='status', sort_name='status', label='Status', active=True),
612- dict(name='assigned_to', sort_name='assigned_to_username', label='Owner', active=True)]
613- for field in sortable_custom_fields:
614- columns.append(
615- dict(name=field['name'], sort_name=field['name'], label=field['label'], active=True))
616606 return dict(
617607 tickets=tickets,
618- sortable_custom_fields=sortable_custom_fields,
619- columns=columns,
620608 count=count, q=json.dumps(query), limit=limit, page=page, sort=sort,
621609 **kw)
622610
623611 @classmethod
624- def paged_search(cls, q, limit=None, page=0, sort=None, columns=None, **kw):
612+ def paged_search(cls, app_config, user, q, limit=None, page=0, sort=None, **kw):
625613 """Query tickets from Solr, filtering for 'read' permission, sorting and paginating the result.
626614
627615 See also paged_query which does a mongo search.
@@ -664,7 +652,7 @@ class Ticket(VersionedArtifact, ActivityObject):
664652 # ticket_numbers is in sorted order
665653 ticket_numbers = [match['ticket_num_i'] for match in matches.docs]
666654 # but query, unfortunately, returns results in arbitrary order
667- query = cls.query.find(dict(app_config_id=c.app.config._id, ticket_num={'$in':ticket_numbers}))
655+ query = cls.query.find(dict(app_config_id=app_config._id, ticket_num={'$in':ticket_numbers}))
668656 # so stick all the results in a dictionary...
669657 ticket_for_num = {}
670658 for t in query:
@@ -673,22 +661,11 @@ class Ticket(VersionedArtifact, ActivityObject):
673661 tickets = []
674662 for tn in ticket_numbers:
675663 if tn in ticket_for_num:
676- if security.has_access(ticket_for_num[tn], 'read'):
664+ if security.has_access(ticket_for_num[tn], 'read', user, app_config.project):
677665 tickets.append(ticket_for_num[tn])
678666 else:
679667 count = count -1
680- sortable_custom_fields=c.app.globals.sortable_custom_fields_shown_in_search()
681- if not columns:
682- columns = [dict(name='ticket_num', sort_name='ticket_num_i', label='Ticket Number', active=True),
683- dict(name='summary', sort_name='snippet_s', label='Summary', active=True),
684- dict(name='_milestone', sort_name='_milestone_s', label='Milestone', active=True),
685- dict(name='status', sort_name='status_s', label='Status', active=True),
686- dict(name='assigned_to', sort_name='assigned_to_s', label='Owner', active=True)]
687- for field in sortable_custom_fields:
688- columns.append(dict(name=field['name'], sort_name=field['sortable_name'], label=field['label'], active=True))
689668 return dict(tickets=tickets,
690- sortable_custom_fields=sortable_custom_fields,
691- columns=columns,
692669 count=count, q=q, limit=limit, page=page, sort=sort,
693670 solr_error=solr_error, **kw)
694671
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -306,6 +306,33 @@ class ForgeTrackerApp(Application):
306306 def bins(self):
307307 return TM.Bin.query.find(dict(app_config_id=self.config._id)).sort('summary').all()
308308
309+
310+
311+
312+
313+### Controllers ###
314+
315+def mongo_columns():
316+ columns = [dict(name='ticket_num', sort_name='ticket_num', label='Ticket Number', active=True),
317+ dict(name='summary', sort_name='summary', label='Summary', active=True),
318+ dict(name='_milestone', sort_name='custom_fields._milestone', label='Milestone', active=True),
319+ dict(name='status', sort_name='status', label='Status', active=True),
320+ dict(name='assigned_to', sort_name='assigned_to_username', label='Owner', active=True)]
321+ for field in c.app.globals.sortable_custom_fields_shown_in_search():
322+ columns.append(
323+ dict(name=field['name'], sort_name=field['name'], label=field['label'], active=True))
324+ return columns
325+
326+def solr_columns():
327+ columns = [dict(name='ticket_num', sort_name='ticket_num_i', label='Ticket Number', active=True),
328+ dict(name='summary', sort_name='snippet_s', label='Summary', active=True),
329+ dict(name='_milestone', sort_name='_milestone_s', label='Milestone', active=True),
330+ dict(name='status', sort_name='status_s', label='Status', active=True),
331+ dict(name='assigned_to', sort_name='assigned_to_s', label='Owner', active=True)]
332+ for field in c.app.globals.sortable_custom_fields_shown_in_search():
333+ columns.append(dict(name=field['name'], sort_name=field['sortable_name'], label=field['label'], active=True))
334+ return columns
335+
309336 class RootController(BaseController):
310337
311338 def __init__(self):
@@ -336,10 +363,12 @@ class RootController(BaseController):
336363 @expose('jinja:forgetracker:templates/tracker/index.html')
337364 def index(self, limit=25, columns=None, page=0, sort='ticket_num desc', **kw):
338365 kw.pop('q', None) # it's just our original query mangled and sent back to us
339- result = TM.Ticket.paged_query(c.app.globals.not_closed_mongo_query,
366+ result = TM.Ticket.paged_query(c.app.config, c.user,
367+ c.app.globals.not_closed_mongo_query,
340368 sort=sort, limit=int(limit),
341- columns=columns, page=page, **kw)
342- c.subscribe_form = W.subscribe_form
369+ page=page, **kw)
370+ result['columns'] = columns or mongo_columns()
371+ result['sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
343372 result['subscribed'] = M.Mailbox.subscribed()
344373 result['allow_edit'] = has_access(c.app, 'update')()
345374 result['help_msg'] = c.app.config.options.get('TicketHelpSearch')
@@ -349,6 +378,7 @@ class RootController(BaseController):
349378 sort_split = sort.split(' ')
350379 solr_col = _mongo_col_to_solr_col(sort_split[0])
351380 result['url_sort'] = '%s %s' % (solr_col, sort_split[1])
381+ c.subscribe_form = W.subscribe_form
352382 c.ticket_search_results = W.ticket_search_results
353383 return result
354384
@@ -437,7 +467,9 @@ class RootController(BaseController):
437467 bin = TM.Bin.query.find(dict(app_config_id=c.app.config._id,terms=q)).first()
438468 if project:
439469 redirect(c.project.url() + 'search?' + urlencode(dict(q=q, history=kw.get('history'))))
440- result = TM.Ticket.paged_search(q, page=page, sort=sort, columns=columns, **kw)
470+ result = TM.Ticket.paged_search(c.app.config, c.user, q, page=page, sort=sort, **kw)
471+ result['columns'] = columns or solr_columns()
472+ result['sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
441473 result['allow_edit'] = has_access(c.app, 'update')()
442474 result['bin'] = bin
443475 result['help_msg'] = c.app.config.options.get('TicketHelpSearch')
@@ -448,10 +480,10 @@ class RootController(BaseController):
448480 @h.vardec
449481 @expose()
450482 @validate(validators=search_validators)
451- def search_feed(self, q=None, query=None, project=None, columns=None, page=0, sort=None, **kw):
483+ def search_feed(self, q=None, query=None, project=None, page=0, sort=None, **kw):
452484 if query and not q:
453485 q = query
454- result = TM.Ticket.paged_search(q, page=page, sort=sort, columns=columns, **kw)
486+ result = TM.Ticket.paged_search(c.app.config, c.user, q, page=page, sort=sort, **kw)
455487 response.headers['Content-Type'] = ''
456488 response.content_type = 'application/xml'
457489 d = dict(title='Ticket search results', link=h.absurl(c.app.url), description='You searched for %s' % q, language=u'en')
@@ -554,9 +586,11 @@ class RootController(BaseController):
554586 sort=validators.UnicodeString(if_empty='ticket_num_i asc')))
555587 def edit(self, q=None, limit=None, page=None, sort=None, **kw):
556588 require_access(c.app, 'update')
557- result = TM.Ticket.paged_search(q, sort=sort, limit=limit, page=page, **kw)
589+ result = TM.Ticket.paged_search(c.app.config, c.user, q, sort=sort, limit=limit, page=page, **kw)
558590 # if c.app.globals.milestone_names is None:
559591 # c.app.globals.milestone_names = ''
592+ result['columns'] = solr_columns()
593+ result['sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
560594 result['globals'] = c.app.globals
561595 result['cancel_href'] = url(
562596 c.app.url + 'search/',
@@ -1319,11 +1353,9 @@ class RootRestController(BaseController):
13191353
13201354 @expose('json:')
13211355 def search(self, q=None, limit=100, page=0, sort=None, **kw):
1322- results = TM.Ticket.paged_search(q, limit, page, sort)
1356+ results = TM.Ticket.paged_search(c.app.config, c.user, q, limit, page, sort)
13231357 results['tickets'] = [dict(ticket_num=t.ticket_num, summary=t.summary)
13241358 for t in results['tickets']]
1325- results.pop('sortable_custom_fields', None)
1326- results.pop('columns', None)
13271359 return results
13281360
13291361 @expose()
@@ -1386,8 +1418,10 @@ class MilestoneController(BaseController):
13861418 sort=validators.UnicodeString(if_empty=None)))
13871419 def index(self, q=None, columns=None, page=0, query=None, sort=None, **kw):
13881420 require(has_access(c.app, 'read'))
1389- result = TM.Ticket.paged_query(
1390- self.mongo_query, page=page, sort=sort, columns=columns, **kw)
1421+ result = TM.Ticket.paged_query(c.app.config, c.user,
1422+ self.mongo_query, page=page, sort=sort, **kw)
1423+ result['columns'] = columns or mongo_columns()
1424+ result['sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
13911425 result['allow_edit'] = has_access(c.app, 'update')()
13921426 result['help_msg'] = c.app.config.options.get('TicketHelpSearch')
13931427 progress = c.app.globals.milestone_count(self.progress_key)
@@ -1415,8 +1449,10 @@ class MilestoneController(BaseController):
14151449 sort=validators.UnicodeString(if_empty='ticket_num_i asc')))
14161450 def edit(self, q=None, limit=None, page=None, sort=None, columns=None, **kw):
14171451 require_access(c.app, 'update')
1418- result = TM.Ticket.paged_query(
1419- self.mongo_query, page=page, sort=sort, columns=columns, **kw)
1452+ result = TM.Ticket.paged_query(c.app.config, c.user,
1453+ self.mongo_query, page=page, sort=sort, **kw)
1454+ result['columns'] = columns or mongo_columns()
1455+ result['sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
14201456 # if c.app.globals.milestone_names is None:
14211457 # c.app.globals.milestone_names = ''
14221458 result.pop('q')