Skip to content

Commit

Permalink
Some protection to prevent orgs being made branches of themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
flavour committed Oct 3, 2012
1 parent f282c4c commit 5f65b97
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
acbaa3a (2012-10-02 23:36:26)
f282c4c (2012-10-03 11:08:31)
9 changes: 8 additions & 1 deletion models/zzz_1st_run.py
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions modules/eden/org.py
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5f65b97

Please sign in to comment.