# HG changeset patch # User Bernhard Reiter # Date 1357159728 -3600 # Node ID 1f2d64ed0b43eb7629662c3d0dc4d43c0ba75ba4 # Parent 9dc50be521eeb3cd26ec02f931d883dfeadb7a9e Added issue2550731 patch by John, adapting it. Also change the email status. diff -r 9dc50be521ee -r 1f2d64ed0b43 roundup/cgi/client.py --- a/roundup/cgi/client.py Fri Dec 28 15:33:57 2012 +0530 +++ b/roundup/cgi/client.py Wed Jan 02 21:48:48 2013 +0100 @@ -792,12 +792,15 @@ # open the database or only set the user if not hasattr(self, 'db'): self.db = self.instance.open(username) + self.db.txSource = "cgi" else: if self.instance.optimize: self.db.setCurrentUser(username) + self.db.txSource = "cgi" else: self.db.close() self.db = self.instance.open(username) + self.db.txSource = "cgi" # The old session API refers to the closed database; # we can no longer use it. self.session_api = Session(self) diff -r 9dc50be521ee -r 1f2d64ed0b43 roundup/instance.py --- a/roundup/instance.py Fri Dec 28 15:33:57 2012 +0530 +++ b/roundup/instance.py Wed Jan 02 21:48:48 2013 +0100 @@ -121,6 +121,8 @@ extension(self) detectors = self.get_extensions('detectors') db = env['db'] + db.txSource = "unset" + # apply the detectors for detector in detectors: detector(db) diff -r 9dc50be521ee -r 1f2d64ed0b43 roundup/mailgw.py --- a/roundup/mailgw.py Fri Dec 28 15:33:57 2012 +0530 +++ b/roundup/mailgw.py Wed Jan 02 21:48:48 2013 +0100 @@ -1026,6 +1026,9 @@ This tracker has been configured to require all email be PGP signed or encrypted.""") + # signature has been verified + self.db.txSource = "email-sig-openpgp" + def get_content_and_attachments(self): ''' get the attachments and first text part from the message ''' @@ -1537,6 +1540,9 @@ ''' # get database handle for handling one email self.db = self.instance.open ('admin') + + self.db.txSource = "email" + try: return self._handle_message(message) finally: # HG changeset patch # User Bernhard Reiter # Date 1357160393 -3600 # Node ID 119895bef52f324ad54079ebb0483df3ae44467e # Parent 1f2d64ed0b43eb7629662c3d0dc4d43c0ba75ba4 issue2550731: Changed name of the variable and the states it can reach. Name: txSource -> tx_Source States: None, "cli", "web", "email", "email-sig-openpgp" diff -r 1f2d64ed0b43 -r 119895bef52f roundup/admin.py --- a/roundup/admin.py Wed Jan 02 21:48:48 2013 +0100 +++ b/roundup/admin.py Wed Jan 02 21:59:53 2013 +0100 @@ -1475,6 +1475,8 @@ if not self.db: self.db = tracker.open('admin') + self.db.tx_Source = 'cli' + # do the command ret = 0 try: diff -r 1f2d64ed0b43 -r 119895bef52f roundup/cgi/client.py --- a/roundup/cgi/client.py Wed Jan 02 21:48:48 2013 +0100 +++ b/roundup/cgi/client.py Wed Jan 02 21:59:53 2013 +0100 @@ -792,15 +792,15 @@ # open the database or only set the user if not hasattr(self, 'db'): self.db = self.instance.open(username) - self.db.txSource = "cgi" + self.db.tx_Source = "web" else: if self.instance.optimize: self.db.setCurrentUser(username) - self.db.txSource = "cgi" + self.db.tx_Source = "web" else: self.db.close() self.db = self.instance.open(username) - self.db.txSource = "cgi" + self.db.tx_Source = "web" # The old session API refers to the closed database; # we can no longer use it. self.session_api = Session(self) diff -r 1f2d64ed0b43 -r 119895bef52f roundup/instance.py --- a/roundup/instance.py Wed Jan 02 21:48:48 2013 +0100 +++ b/roundup/instance.py Wed Jan 02 21:59:53 2013 +0100 @@ -121,7 +121,7 @@ extension(self) detectors = self.get_extensions('detectors') db = env['db'] - db.txSource = "unset" + db.tx_Source = None # apply the detectors for detector in detectors: diff -r 1f2d64ed0b43 -r 119895bef52f roundup/mailgw.py --- a/roundup/mailgw.py Wed Jan 02 21:48:48 2013 +0100 +++ b/roundup/mailgw.py Wed Jan 02 21:59:53 2013 +0100 @@ -1027,7 +1027,7 @@ encrypted.""") # signature has been verified - self.db.txSource = "email-sig-openpgp" + self.db.tx_Source = "email-sig-openpgp" def get_content_and_attachments(self): ''' get the attachments and first text part from the message # HG changeset patch # User Bernhard Reiter # Date 1357160556 -3600 # Node ID 766dfe4794ca1a4d0b64a28f71746d624891b087 # Parent 119895bef52f324ad54079ebb0483df3ae44467e issue2550731: forgot one variale change. diff -r 119895bef52f -r 766dfe4794ca roundup/mailgw.py --- a/roundup/mailgw.py Wed Jan 02 21:59:53 2013 +0100 +++ b/roundup/mailgw.py Wed Jan 02 22:02:36 2013 +0100 @@ -1541,7 +1541,7 @@ # get database handle for handling one email self.db = self.instance.open ('admin') - self.db.txSource = "email" + self.db.tx_Source = "email" try: return self._handle_message(message) # HG changeset patch # User Bernhard Reiter # Date 1357161991 -3600 # Node ID 26a138760969ab1508d70ad75d4b48a39e1b9914 # Parent 766dfe4794ca1a4d0b64a28f71746d624891b087 issue2550731: Added example detector, modified for new variable name man status values. diff -r 766dfe4794ca -r 26a138760969 detectors/txSource_detector.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/detectors/txSource_detector.py Wed Jan 02 22:26:31 2013 +0100 @@ -0,0 +1,61 @@ +# +# Example output when the web interface changes item 3 and the email +# (non pgp) interface changes item 4: +# +# txSourceCheckAudit(3) pre db.tx_Source: web +# txSourceCheckAudit(4) pre db.tx_Source: email +# txSourceCheckAudit(3) post db.tx_Source: web +# txSourceCheckAudit(4) post db.tx_Source: email +# txSourceCheckReact(4) pre db.tx_Source: email +# txSourceCheckReact(4) post db.tx_Source: email +# txSourceCheckReact(3) pre db.tx_Source: web +# txSourceCheckReact(3) post db.tx_Source: web +# +# Note that the calls are interleaved, but the proper +# txSource is associated with the same ticket. + +import time as time + +def txSourceCheckAudit(db, cl, nodeid, newvalues): + ''' An auditor to print the value of the source of the + transaction that trigger this change. The sleep call + is used to delay the transaction so that multiple changes will + overlap. The expected output from this detector are 2 lines + with the same value for txSource. Tx source is: + None + cli - reported when using a script/roundup-admin + web - reported when using any web based technique + email - reported when using any email based technique + email-sig-openpgp - reported when email based technique uses an openpgp signed emails + ''' + print "txSourceCheckAudit(%s) pre db.tx_Source: %s"%(nodeid, db.tx_Source) + time.sleep(10) + print "txSourceCheckAudit(%s) post db.tx_Source: %s"%(nodeid, db.tx_Source) + + # example use for real to prevent a change from happening if it's + # submited via email + # + # if db.tx_Source == "email": + # raise Reject, 'Change not allowed via email' + +def txSourceCheckReact(db, cl, nodeid, oldvalues): + ''' An reactor to print the value of the source of the + transaction that trigger this change. The sleep call + is used to delay the transaction so that multiple changes will + overlap. The expected output from this detector are 2 lines + with the same value for txSource. Tx source is: + None + cli - reported when using a script/roundup-admin + web - reported when using any web based technique + email - reported when using any email based technique + email-sig-openpgp - reported when email based technique uses pgp signed emails + ''' + print "txSourceCheckReact(%s) pre db.tx_Source: %s"%(nodeid, db.tx_Source) + time.sleep(10) + print "txSourceCheckReact(%s) post db.tx_Source: %s"%(nodeid, db.tx_Source) + +def init(db): + db.issue.audit('set', txSourceCheckAudit) + db.issue.audit('create', txSourceCheckAudit) + db.issue.react('set', txSourceCheckReact) + db.issue.react('create', txSourceCheckReact)