Mercurial > p > roundup > code
changeset 5112:8901cc4ef0e0
- issue1714899: Feature Request: Optional Change Note. Added a new
quiet=True/False option for all property types. When quiet=True
changes to the property will not be displayed in the::
confirmation banner (shown in green) when a change is made
property change section of change note (nosy emails)
web history display for an item.
Note that this may confuse users if used on a property that is
meant to be changed by a user. It is most useful on administrative
properties that are changed by an auditor as part of a user
generated change. Original patch by Daniel Diniz (ajaksu2)
discussed also at:
http://psf.upfronthosting.co.za/roundup/meta/issue249
Support for setting quiet when calling the class specifiers:
E.G. prop=String(quiet=True) rather than::
prop=String()
prop.quiet=True
support for anydb backend, added tests, doc updates, support for
ignoring quiet setting using showall=True in call to history()
function in templates by John Rouillard.
In addition to documenting quiet, I also documented required and
default_value additions to the hyperdb property classes. Only place I
could find is design.txt.
Note tests for history in web interface are not done. It was manually
checked but there are no automated tests. The template for setup is in
db_test_base.py::testQuietJournal but it has no asserts. I need
access to template.py::_HTMLItem::history() and I don't know how to do
that. test_templates.py isn't helping me any at all and I want to get
this patch in because it handles nicely an issue I have in the design
of my own tracker. The issue is:
The properties of an issue are displayed in framesets/subframes. The
user can roll up the frameset leaving only the title bar. When the
user saves the changes, the current state of the framesets
(collapsed/uncollapsed) is saved to a property in the user's
object. However there is no reason the user should see that this is
updated since it's an administrative detail.
Similarly, you could count the number of times an issue is reopened or
reassigned. Updates to properties that are an indirect result of a
user's change should not be displayed to the user as they can be
confusing and distracting.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 30 Jun 2016 20:38:23 -0400 |
| parents | 1c94afabb2cb |
| children | cf112b90fa8d |
| files | CHANGES.txt doc/design.txt roundup/backends/back_anydbm.py roundup/backends/rdbms_common.py roundup/cgi/templating.py roundup/hyperdb.py roundup/roundupdb.py test/db_test_base.py |
| diffstat | 8 files changed, 217 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Thu Jun 30 12:38:23 2016 +1000 +++ b/CHANGES.txt Thu Jun 30 20:38:23 2016 -0400 @@ -87,6 +87,25 @@ 3) setting it to a fixed address (like noreply@some.place) Done by John Rouillard from proposal by Peter Funk (pefu) in discussion with Tom Ekberg (tekberg). See doc/upgrading.txt. +- issue1714899: Feature Request: Optional Change Note. Added a new + quiet=True/False option for all property types. When quiet=True + changes to the property will not be displayed in the:: + confirmation banner (shown in green) when a change is made + property change section of change note (nosy emails) + web history display for an item. + Note that this may confuse users if used on a property that is + meant to be changed by a user. It is most useful on administrative + properties that are changed by an auditor as part of a user + generated change. Original patch by Daniel Diniz (ajaksu2) + discussed also at: + http://psf.upfronthosting.co.za/roundup/meta/issue249 + Support for setting quiet when calling the class specifiers: + E.G. prop=String(quiet=True) rather than:: + prop=String() + prop.quiet=True + support for anydb backend, added tests, doc updates, support for + ignoring quiet setting using showall=True in call to history() + function in templates by John Rouillard. Fixed:
--- a/doc/design.txt Thu Jun 30 12:38:23 2016 +1000 +++ b/doc/design.txt Thu Jun 30 20:38:23 2016 -0400 @@ -254,8 +254,44 @@ TODO: replace the Interface Specifications with links to the pydoc The hyperdb module provides property objects to designate the different -kinds of properties. These objects are used when specifying what -properties belong in classes:: +kinds of properties. + +All property objects support the following settings: + +quiet=False: + if set to True, changes to the property will not be shown to the + user. This can be used for adminstrative properties that are + automatically updated when a user makes some other change. This + reduces confusion by the user and clutter in the display. + The property change will not be shown in: + + - the change confirmation message when a change is entered in the web interface + - the property change section of the change note email ("nosy email") + - the web history shown at the bottom of an item page + +required=False: + if set to True, the property name is returned when calling + get_required_props(self, propnames = []). Any additional props + specified in propnames is merged with the required props. + +default_value=None or [] depending on object type: + this sets the default value if none is specified. The default + value can be retrieved by calling the get_default_value() + method on the property object. + +E.G. assuming title is part of an Issue:: + + title=String(required=True, default_value="not set",quiet=True) + +will create a property called ``title`` that will be included in the +get_required_props() output. Calling +db.issue.properties['title'].get_default_value() will return "not set". +Changes to the property will not be displayed in emailed change notes, +the history at the end of the item pages in the web interface and will +be suppressed in the confirmation notice (displayed as a green banner) +shown on changes. + +These objects are used when specifying what properties belong in classes:: class String: def __init__(self, indexme='no'): @@ -1652,6 +1688,7 @@ Changes to this document ------------------------ +- Added docs for quiet, default_value and required arguments for properties. - Added Boolean, Integer and Number types - Added section Hyperdatabase Implementations - "Item" has been renamed to "Issue" to account for the more specific
--- a/roundup/backends/back_anydbm.py Thu Jun 30 12:38:23 2016 +1000 +++ b/roundup/backends/back_anydbm.py Thu Jun 30 20:38:23 2016 -0400 @@ -1199,6 +1199,9 @@ # if the journal value is to be different, store it in here journalvalues = {} + # omit quiet properties from history/changelog + quiet_props = [] + # list() propvalues 'cos it might be modified by the loop for propname, value in list(propvalues.items()): # check to make sure we're not duplicating an existing key @@ -1374,6 +1377,10 @@ node[propname] = value + # record quiet properties to omit from history/changelog + if prop.quiet: + quiet_props.append(propname) + # nothing to do? if not propvalues: return propvalues @@ -1388,6 +1395,11 @@ if self.do_journal: self.db.addjournal(self.classname, nodeid, 'set', journalvalues) + # remove quiet properties from output + for propname in quiet_props: + if propname in propvalues: + del propvalues[propname] + return propvalues def retire(self, nodeid):
--- a/roundup/backends/rdbms_common.py Thu Jun 30 12:38:23 2016 +1000 +++ b/roundup/backends/rdbms_common.py Thu Jun 30 20:38:23 2016 -0400 @@ -1783,6 +1783,9 @@ # for the Database layer to do its stuff multilink_changes = {} + # omit quiet properties from history/changelog + quiet_props = [] + for propname, value in list(propvalues.items()): # check to make sure we're not duplicating an existing key if propname == self.key and node[propname] != value: @@ -1958,6 +1961,10 @@ except ValueError: raise TypeError('new property "%s" not boolean'%propname) + # record quiet properties to omit from history/changelog + if prop.quiet: + quiet_props.append(propname) + # nothing to do? if not propvalues: return propvalues @@ -1977,6 +1984,11 @@ if self.do_journal: self.db.addjournal(self.classname, nodeid, ''"set", journalvalues) + # remove quiet properties from output + for propname in quiet_props: + if propname in propvalues: + del propvalues[propname] + return propvalues def retire(self, nodeid):
--- a/roundup/cgi/templating.py Thu Jun 30 12:38:23 2016 +1000 +++ b/roundup/cgi/templating.py Thu Jun 30 20:38:23 2016 -0400 @@ -870,7 +870,13 @@ return [] def history(self, direction='descending', dre=re.compile('^\d+$'), - limit=None): + limit=None, showall=False ): + """Create an html view of the journal for the item. + + Display property changes for all properties that does not have quiet set. + If showall=True then all properties regardless of quiet setting will be + shown. + """ if not self.is_view_ok(): return self._('[hidden]') @@ -965,7 +971,10 @@ except NoTemplate: hrefable = 0 - if isinstance(prop, hyperdb.Multilink) and args[k]: + if (not showall) and prop.quiet: + # Omit quiet properties from history/changelog + continue + elif isinstance(prop, hyperdb.Multilink) and args[k]: ml = [] for linkid in args[k]: if isinstance(linkid, type(())):
--- a/roundup/hyperdb.py Thu Jun 30 12:38:23 2016 +1000 +++ b/roundup/hyperdb.py Thu Jun 30 20:38:23 2016 -0400 @@ -35,9 +35,10 @@ # class _Type(object): """A roundup property type.""" - def __init__(self, required=False, default_value = None): + def __init__(self, required=False, default_value = None, quiet=False): self.required = required self.__default_value = default_value + self.quiet = quiet def __repr__(self): ' more useful for dumps ' return '<%s.%s>'%(self.__class__.__module__, self.__class__.__name__) @@ -54,8 +55,8 @@ class String(_Type): """An object designating a String property.""" - def __init__(self, indexme='no', required=False, default_value = ""): - super(String, self).__init__(required, default_value) + def __init__(self, indexme='no', required=False, default_value = "", quiet=False): + super(String, self).__init__(required, default_value, quiet) self.indexme = indexme == 'yes' def from_raw(self, value, propname='', **kw): """fix the CRLF/CR -> LF stuff""" @@ -73,8 +74,8 @@ class Password(_Type): """An object designating a Password property.""" - def __init__(self, scheme=None, required=False, default_value = None): - super(Password, self).__init__(required, default_value) + def __init__(self, scheme=None, required=False, default_value = None, quiet=False): + super(Password, self).__init__(required, default_value, quiet) self.scheme = scheme def from_raw(self, value, **kw): @@ -93,9 +94,10 @@ class Date(_Type): """An object designating a Date property.""" - def __init__(self, offset=None, required=False, default_value = None): + def __init__(self, offset=None, required=False, default_value = None, quiet=False): super(Date, self).__init__(required = required, - default_value = default_value) + default_value = default_value, + quiet=quiet) self._offset = offset def offset(self, db): if self._offset is not None: @@ -135,7 +137,7 @@ to a node in a specified class.""" def __init__(self, classname, do_journal='yes', try_id_parsing='yes', required=False, default_value=None, - msg_header_property = None): + msg_header_property = None, quiet=False): """ Default is to journal link and unlink events. When try_id_parsing is false, we don't allow IDs in input fields (the key of the Link or Multilink property must be @@ -154,7 +156,7 @@ property will generated message headers of the form: 'X-Roundup-issue-assigned_to: joe_user'. """ - super(_Pointer, self).__init__(required, default_value) + super(_Pointer, self).__init__(required, default_value, quiet) self.classname = classname self.do_journal = do_journal == 'yes' self.try_id_parsing = try_id_parsing == 'yes' @@ -196,12 +198,12 @@ 'link' and 'unlink' events placed in their journal """ - def __init__(self, classname, do_journal = 'yes', required = False): + def __init__(self, classname, do_journal = 'yes', required = False, quiet=False): super(Multilink, self).__init__(classname, do_journal, required = required, - default_value = []) + default_value = [], quiet=quiet) def from_raw(self, value, db, klass, propname, itemid, **kw): if not value:
--- a/roundup/roundupdb.py Thu Jun 30 12:38:23 2016 +1000 +++ b/roundup/roundupdb.py Thu Jun 30 20:38:23 2016 -0400 @@ -703,6 +703,9 @@ prop_items = props.items() prop_items.sort() for propname, prop in prop_items: + # Omit quiet properties from history/changelog + if prop.quiet: + continue value = cl.get(issueid, propname, None) # skip boring entries if not value: @@ -775,6 +778,9 @@ changed_items.sort() for propname, oldvalue in changed_items: prop = props[propname] + # Omit quiet properties from history/changelog + if prop.quiet: + continue value = cl.get(issueid, propname, None) if isinstance(prop, hyperdb.Link): link = self.db.classes[prop.classname]
--- a/test/db_test_base.py Thu Jun 30 12:38:23 2016 +1000 +++ b/test/db_test_base.py Thu Jun 30 20:38:23 2016 -0400 @@ -80,16 +80,20 @@ status.setkey("name") priority = module.Class(db, "priority", name=String(), order=String()) priority.setkey("name") - user = module.Class(db, "user", username=String(), password=Password(), - assignable=Boolean(), age=Number(), roles=String(), address=String(), - rating=Integer(), supervisor=Link('user'),realname=String()) + user = module.Class(db, "user", username=String(), password=Password(quiet=True), + assignable=Boolean(quiet=True), age=Number(quiet=True), roles=String(), address=String(), + rating=Integer(quiet=True), supervisor=Link('user'),realname=String(quiet=True)) user.setkey("username") file = module.FileClass(db, "file", name=String(), type=String(), comment=String(indexme="yes"), fooz=Password()) file_nidx = module.FileClass(db, "file_nidx", content=String(indexme='no')) + + # initialize quiet mode a second way without using Multilink("user", quiet=True) + mynosy = Multilink("user") + mynosy.quiet = True issue = module.IssueClass(db, "issue", title=String(indexme="yes"), - status=Link("status"), nosy=Multilink("user"), deadline=Date(), - foo=Interval(), files=Multilink("file"), assignedto=Link('user'), + status=Link("status"), nosy=mynosy, deadline=Date(quiet=True), + foo=Interval(quiet=True, default_value=date.Interval('-1w')), files=Multilink("file"), assignedto=Link('user', quiet=True), priority=Link('priority'), spam=Multilink('msg'), feedback=Link('msg')) stuff = module.Class(db, "stuff", stuff=String()) @@ -878,6 +882,102 @@ self.assertEqual(test.call_b, 1) self.assertEqual(test.call_c, 2) + def testDefault_Value(self): + new_issue=self.db.issue.create(title="title", deadline=date.Date('2016-6-30.22:39')) + + # John Rouillard claims this should return the default value of 1 week for foo, + # but the hyperdb doesn't assign the default value for missing properties in the + # db on creation. + result=self.db.issue.get(new_issue, 'foo') + # When the defaultis automatically set by the hyperdb, change this to + # match the Interval test below. + self.assertEqual(result, None) + + # but verify that the default value is retreivable + result=self.db.issue.properties['foo'].get_default_value() + self.assertEqual(result, date.Interval('-7d')) + + def testQuietProperty(self): + # make sure that the quiet properties: "assignable" and "age" are not + # returned as part of the proplist + new_user=self.db.user.create(username="pete", age=10, assignable=False) + new_issue=self.db.issue.create(title="title", deadline=date.Date('2016-6-30.22:39')) + # change all quiet params. Verify they aren't returned in object. + # between this and the issue class every type represented in hyperdb + # should be initalized with a quiet parameter. + result=self.db.user.set(new_user, username="new", age=20, supervisor='3', assignable=True, + password=password.Password("3456"), rating=4, realname="newname") + self.assertEqual(result, {'supervisor': '3', 'username': "new"}) + result=self.db.user.get(new_user, 'age') + self.assertEqual(result, 20) + + # change all quiet params. Verify they aren't returned in object. + result=self.db.issue.set(new_issue, title="title2", deadline=date.Date('2016-7-13.22:39'), + assignedto="2", nosy=["3", "2"]) + self.assertEqual(result, {'title': 'title2'}) + + # also test that we can make a property noisy + self.db.user.properties['age'].quiet=False + result=self.db.user.set(new_user, username="old", age=30, supervisor='2', assignable=False) + self.assertEqual(result, {'age': 30, 'supervisor': '2', 'username': "old"}) + self.db.user.properties['age'].quiet=True + + def testQuietChangenote(self): + # create user 3 for later use + self.db.user.create(username="pete", age=10, assignable=False) + + new_issue=self.db.issue.create(title="title", deadline=date.Date('2016-6-30.22:39')) + + # change all quiet params. Verify they aren't returned in CreateNote. + result=self.db.issue.set(new_issue, title="title2", deadline=date.Date('2016-6-30.22:39'), + assignedto="2", nosy=["3", "2"]) + result=self.db.issue.generateCreateNote(new_issue) + self.assertEqual(result, '\n----------\ntitle: title2') + + # also test that we can make a property noisy + self.db.issue.properties['nosy'].quiet=False + self.db.issue.properties['deadline'].quiet=False + result=self.db.issue.set(new_issue, title="title2", deadline=date.Date('2016-7-13.22:39'), + assignedto="2", nosy=["1", "2"]) + result=self.db.issue.generateCreateNote(new_issue) + self.assertEqual(result, '\n----------\ndeadline: 2016-07-13.22:39:00\nnosy: admin, fred\ntitle: title2') + self.db.issue.properties['nosy'].quiet=True + self.db.issue.properties['deadline'].quiet=True + + def testQuietJournal(self): + # FIXME this doesn't work. I need to call + # template.py::_HTMLItem::history() and verify the output. + # not sure how to get there from here. -- rouilj + # make sure that the quiet properties: "assignable" and "age" are not + # returned as part of the journal + # so comment out tests here but leave framework for later. + new_user=self.db.user.create(username="pete", age=10, assignable=False) + new_issue=self.db.issue.create(title="title", deadline=date.Date('2016-6-30.22:39')) + + # change all quiet params. Verify they aren't returned in journal. + # between this and the issue class every type represented in hyperdb + # should be initalized with a quiet parameter. + result=self.db.user.set(new_user, username="new", age=20, supervisor='3', assignable=True, + password=password.Password("3456"), rating=4, realname="newname") + result=self.db.user.history(new_user) + #self.assertEqual(result, 20) + + # change all quiet params. Verify they aren't returned in object. + result=self.db.issue.set(new_issue, title="title2", deadline=date.Date('2016-6-30.22:39'), + assignedto="2", nosy=["3", "2"]) + result=self.db.issue.generateCreateNote(new_issue) + #self.assertEqual(result, '\n----------\ntitle: title2') + + # also test that we can make a property noisy + self.db.issue.properties['nosy'].quiet=False + self.db.issue.properties['deadline'].quiet=False + result=self.db.issue.set(new_issue, title="title2", deadline=date.Date('2016-7-13.22:39'), + assignedto="2", nosy=["1", "2"]) + result=self.db.issue.generateCreateNote(new_issue) + #self.assertEqual(result, '\n----------\ndeadline: 2016-07-13.22:39:00\nnosy: admin, fred\ntitle: title2') + self.db.issue.properties['nosy'].quiet=True + self.db.issue.properties['deadline'].quiet=True + def testJournals(self): muid = self.db.user.create(username="mary") self.db.user.create(username="pete")
