Skip to content

Commit 007b38f

Browse files
author
Richard Jones
committed
merge OLD changes from HEAD
1 parent e2e0b15 commit 007b38f

File tree

1 file changed

+53
-18
lines changed

1 file changed

+53
-18
lines changed

roundup/cgi/templating.py

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,16 @@ def list(self, sort_on=None):
560560
'''
561561
# get the list and sort it nicely
562562
l = self._klass.list()
563-
sortfunc = make_sort_function(self._db, self.classname, sort_on)
563+
sortfunc = make_sort_function(self._db, self._classname, sort_on)
564564
l.sort(sortfunc)
565565

566-
l = [HTMLItem(self._client, self.classname, x) for x in l]
566+
# check perms
567+
check = self._client.db.security.hasPermission
568+
userid = self._client.userid
569+
570+
l = [HTMLItem(self._client, self._classname, id) for id in l
571+
if check('View', userid, self._classname, itemid=id)]
572+
567573
return l
568574

569575
def csv(self):
@@ -604,8 +610,13 @@ def filter(self, request=None, filterspec={}, sort=(None,None),
604610
filterspec = request.filterspec
605611
sort = request.sort
606612
group = request.group
613+
614+
check = self._db.security.hasPermission
615+
userid = self._client.userid
616+
607617
l = [HTMLItem(self._client, self.classname, x)
608-
for x in self._klass.filter(None, filterspec, sort, group)]
618+
for id in self._klass.filter(None, filterspec, sort, group)
619+
if check('View', userid, self.classname, itemid=id)]
609620
return l
610621

611622
def classhelp(self, properties=None, label=''"(list)", width='500',
@@ -1676,6 +1687,27 @@ def menu(self, size=None, height=None, showid=0, additional=[],
16761687
return '\n'.join(l)
16771688
# def checklist(self, ...)
16781689

1690+
class MultilinkIterator:
1691+
def __init__(self, classname, client, values):
1692+
self.classname = classname
1693+
self.client = client
1694+
self.values = values
1695+
self.id = -1
1696+
def next(self):
1697+
'''Return the next item, but skip inaccessible items.'''
1698+
check = self.client.db.security.hasPermission
1699+
userid = self.client.userid
1700+
while 1:
1701+
self.id += 1
1702+
if self.id >= len(self.values):
1703+
raise StopIteration
1704+
value = self.values[self.id]
1705+
if check('View', userid, self.classname, itemid=value):
1706+
return HTMLItem(self.client, self.classname, value)
1707+
def __iter__(self):
1708+
return self
1709+
1710+
16791711
class MultilinkHTMLProperty(HTMLProperty):
16801712
''' Multilink HTMLProperty
16811713
@@ -1698,16 +1730,22 @@ def __getattr__(self, attr):
16981730
''' no extended attribute accesses make sense here '''
16991731
raise AttributeError, attr
17001732

1701-
def __getitem__(self, num):
1733+
def __iter__(self):
17021734
''' iterate and return a new HTMLItem
17031735
'''
1704-
#print 'Multi.getitem', (self, num)
1705-
value = self._value[num]
1706-
return HTMLItem(self._client, self._prop.classname, value)
1736+
return MultilinkIterator(self._prop.classname, self._client,
1737+
self._value)
1738+
1739+
def reverse(self):
1740+
''' return the list in reverse order
1741+
'''
1742+
l = self._value[:]
1743+
l.reverse()
1744+
return MultilinkIterator(self._prop.classname, self._client, l)
17071745

17081746
def sorted(self, property):
17091747
''' Return this multilink sorted by the given property '''
1710-
value = list(self._value[num])
1748+
value = list(self.__iter__())
17111749
value.sort(lambda a,b:cmp(a[property], b[property]))
17121750
return value
17131751

@@ -1721,14 +1759,6 @@ def isset(self):
17211759
'''Is my _value not []?'''
17221760
return self._value != []
17231761

1724-
def reverse(self):
1725-
''' return the list in reverse order
1726-
'''
1727-
l = self._value[:]
1728-
l.reverse()
1729-
return [HTMLItem(self._client, self._prop.classname, value)
1730-
for value in l]
1731-
17321762
def plain(self, escape=0):
17331763
''' Render a "plain" representation of the property
17341764
'''
@@ -1766,7 +1796,7 @@ def field(self, size=30, showid=0):
17661796

17671797
def menu(self, size=None, height=None, showid=0, additional=[],
17681798
sort_on=None, **conditions):
1769-
''' Render a form select list for this property
1799+
''' Render a form <select> list for this property.
17701800
17711801
"size" is used to limit the length of the list labels
17721802
"height" is used to set the <select> tag's "size" attribute
@@ -2183,7 +2213,12 @@ def batch(self):
21832213
re.findall(r'\b\w{2,25}\b', self.search_text), klass)
21842214
else:
21852215
matches = None
2186-
l = klass.filter(matches, filterspec, sort, group)
2216+
2217+
# filter for visibility
2218+
check = self._client.db.security.hasPermission
2219+
userid = self._client.userid
2220+
l = [id for id in klass.filter(matches, filterspec, sort, group)
2221+
if check('View', userid, self.classname, itemid=id)]
21872222

21882223
# return the batch object, using IDs only
21892224
return Batch(self.client, l, self.pagesize, self.startwith,

0 commit comments

Comments
 (0)