Skip to content

Commit 993e6a2

Browse files
committed
Fixed quiet history filter for linked items. Test for same fixed.
The original test didn't cover the case where the linked item in the history/journal wasn't the same type as the item on which the history was generated. This now pulls the history on a user who has been linked to the nosy field of an issue.
1 parent b67cbf3 commit 993e6a2

File tree

2 files changed

+62
-22
lines changed

2 files changed

+62
-22
lines changed

roundup/hyperdb.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,16 +1022,14 @@ def history(self, nodeid, enforceperm=True, skipquiet=True):
10221022
perm = self.db.security.hasPermission
10231023
journal = []
10241024

1025-
debug_logging = logger.isEnabledFor(logging.DEBUG)
1026-
10271025
uid=self.db.getuid() # id of the person requesting the history
10281026

10291027
for j in self.db.getjournal(self.classname, nodeid):
10301028
# hide/remove journal entry if:
10311029
# property is quiet
10321030
# property is not (viewable or editable)
10331031
id, evt_date, user, action, args = j
1034-
if debug_logging:
1032+
if logger.isEnabledFor(logging.DEBUG):
10351033
j_repr = "%s"%(j,)
10361034
else:
10371035
j_repr=''
@@ -1061,47 +1059,58 @@ def history(self, nodeid, enforceperm=True, skipquiet=True):
10611059
continue
10621060
journal.append(j)
10631061
elif action in ['link', 'unlink' ] and type(args) == type(()):
1064-
# hide/remove journal entry if:
1065-
# link property (key) is quiet
1066-
# link property is not (viewable or editable)
1067-
# id/object (linkcl, linkid) that is linked/unlinked is not
1068-
# (viewable or editable)
1062+
# definitions:
1063+
# myself - object whose history is being filtered
1064+
# linkee - object/class whose property is changing to
1065+
# include/remove myself
1066+
# link property - property of the linkee class that is changing
1067+
#
1068+
# Remove the history item if
1069+
# linkee.link property (key) is quiet
1070+
# linkee class.link property is not (viewable or editable)
1071+
# to user
1072+
# [ should linkee object.link property is not
1073+
# (viewable or editable) to user be included?? ]
1074+
# linkee object (linkcl, linkid) is not
1075+
# (viewable or editable) to user
10691076
if len(args) == 3:
1070-
'''
10711077
# e.g. for issue3 blockedby adds link to issue5 with:
10721078
# j = id, evt_date, user, action, args
10731079
# 3|20170528045201.484|5|link|('issue', '5', 'blockedby')
10741080
linkcl, linkid, key = args
10751081
cls = self.db.getclass(linkcl)
10761082
# is the updated property quiet?
1077-
if skipquiet and self.properties[key].quiet:
1078-
logger.debug("skipping quiet property"
1079-
" %s::%s in %s",
1080-
self.classname, key, j_repr)
1083+
if skipquiet and cls.properties[key].quiet:
1084+
logger.debug("skipping quiet property: "
1085+
"%s %sed %s%s",
1086+
j_repr, action, self.classname, nodeid)
10811087
continue
1082-
# property check on item we want history for
1088+
# can user view the property in linkee class
10831089
if enforceperm and not (perm("View",
10841090
uid,
1085-
self.classname,
1091+
linkcl,
10861092
property=key) or perm("Edit",
10871093
uid,
1088-
self.classname,
1094+
linkcl,
10891095
property=key)):
1090-
logger.debug("skipping unaccessible property %s::%s seen by user%s in %s",
1091-
self.classname, key, uid, j_repr)
1096+
logger.debug("skipping unaccessible property: "
1097+
"%s with uid %s %sed %s%s",
1098+
j_repr, uid, action,
1099+
self.classname, nodeid)
10921100
continue
1093-
# check on object linked
1101+
# check access to linkee object
10941102
if enforceperm and not (perm("View",
10951103
uid,
10961104
cls.classname,
10971105
itemid=linkid) or perm("Edit",
10981106
uid,
10991107
cls.classname,
11001108
itemid=linkid)):
1101-
logger.debug("skipping unaccessible target %s%s for user%s in %s",
1102-
cls.classname, linkid, uid, j_repr)
1109+
logger.debug("skipping unaccessible object: "
1110+
"%s uid %s %sed %s%s",
1111+
j_repr, uid, action,
1112+
self.classname, nodeid)
11031113
continue
1104-
'''
11051114
journal.append(j)
11061115
else:
11071116
logger.error("Invalid %s journal entry for %s%s: %s",

test/db_test_base.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,20 @@ def testViewPremJournal(self):
983983
pass
984984

985985
def testQuietJournal(self):
986+
## This is an example of how to enable logging module
987+
## and report the results. It uses testfixtures
988+
## that can be installed via pip.
989+
## Uncomment below 2 lines:
990+
import logging
991+
from testfixtures import LogCapture
992+
## then run every call to roundup functions with:
993+
#with LogCapture('roundup.hyperdb', level=logging.DEBUG) as l:
994+
# result=self.db.user.history('2')
995+
#print l
996+
## change 'roundup.hyperdb' to the logging name you want to capture.
997+
## print l just prints the output. Run using:
998+
## ./run_tests.py --capture=no -k testQuietJournal test/test_anydbm.py
999+
9861000
# FIXME There should be a test via
9871001
# template.py::_HTMLItem::history() and verify the output.
9881002
# not sure how to get there from here. -- rouilj
@@ -1101,6 +1115,23 @@ def testQuietJournal(self):
11011115
self.assertEqual('set', action)
11021116
self.assertEqual(expected, args)
11031117

1118+
result=self.db.user.history('2')
1119+
1120+
# result should look like:
1121+
# [('2', <Date 2017-08-29.01:42:44.283>, '1', 'link',
1122+
# ('issue', '1', 'nosy')),
1123+
# ('2', <Date 2017-08-29.01:42:40.227>, '1', 'create', {})]
1124+
1125+
expected2 = ('issue', '1', 'nosy')
1126+
(id, tx_date, user, action, args) = result[0]
1127+
1128+
self.assertEqual(len(result),2)
1129+
1130+
self.assertEqual('2', id)
1131+
self.assertEqual('1', user)
1132+
self.assertEqual('link', action)
1133+
self.assertEqual(expected2, args)
1134+
11041135
# reset quiet props
11051136
self.db.issue.properties['nosy'].quiet=True
11061137
self.db.issue.properties['deadline'].quiet=True

0 commit comments

Comments
 (0)