From 5f65b979272bcddeaa700c7f044e67d231d03992 Mon Sep 17 00:00:00 2001 From: Fran Boon Date: Wed, 3 Oct 2012 11:08:31 +0100 Subject: [PATCH] Some protection to prevent orgs being made branches of themselves --- VERSION | 2 +- models/zzz_1st_run.py | 9 ++++++++- modules/eden/org.py | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 911b0d77ad..68033a4e65 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -acbaa3a (2012-10-02 23:36:26) \ No newline at end of file +f282c4c (2012-10-03 11:08:31) \ No newline at end of file diff --git a/models/zzz_1st_run.py b/models/zzz_1st_run.py index f1812dd4a6..68692a1acc 100644 --- a/models/zzz_1st_run.py +++ b/models/zzz_1st_run.py @@ -353,7 +353,14 @@ try: print >> sys.stderr, errorLine except: - print >> sys.stderr, s3base.s3_unicode(errorLine) + s3_unicode = s3base.s3_unicode + _errorLine = "" + for i in range(0, len(errorLine)): + try: + _errorLine += s3_unicode(errorline[i]) + except: + pass + print >> sys.stderr, _errorLine # Restore table protection s3mgr.PROTECTED = protected diff --git a/modules/eden/org.py b/modules/eden/org.py index 2dd8e43258..2c1bd6488d 100644 --- a/modules/eden/org.py +++ b/modules/eden/org.py @@ -667,6 +667,7 @@ def model(self): configure(tablename, deduplicate=self.org_branch_duplicate, onaccept=self.org_branch_onaccept, + onvalidation=self.org_branch_onvalidation, ondelete=self.org_branch_ondelete, ) @@ -1018,6 +1019,21 @@ def org_branch_duplicate(item): item.id = duplicate.id item.method = item.METHOD.UPDATE + # ------------------------------------------------------------------------- + @staticmethod + def org_branch_onvalidation(form): + """ + Prevent an Organisation from being a Branch of itself + """ + + # @ToDo: This ctaches manual creation but need to catch Imports somehow + vars = form.request_vars + if vars and \ + int(vars.branch_id) == int(vars.organisation_id): + error = current.T("Cannot make an Organisation a branch of itself!") + form.errors["branch_id"] = error + current.response.error = error + # ------------------------------------------------------------------------- @staticmethod def org_branch_onaccept(form):