[Mpuls-commits] r5911 - base/trunk/mpulsweb/lib

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 16 10:29:54 CET 2012


Author: ludwig
Date: 2012-03-16 10:29:54 +0100 (Fri, 16 Mar 2012)
New Revision: 5911

Modified:
   base/trunk/mpulsweb/lib/base.py
   base/trunk/mpulsweb/lib/dialogs.py
Log:
Issue 2940: Move load_case again into BaseController._loadCase
load_case was only used by the BaseController and two decorators.
Fixes the problem with the missing self.



Modified: base/trunk/mpulsweb/lib/base.py
===================================================================
--- base/trunk/mpulsweb/lib/base.py	2012-03-16 08:34:52 UTC (rev 5910)
+++ base/trunk/mpulsweb/lib/base.py	2012-03-16 09:29:54 UTC (rev 5911)
@@ -107,70 +107,67 @@
                            cache_type=cache_type, cache_expire=cache_expire)
 render = render_mako
 
-def load_case(id, uncommitted=None, read_only=False):
-    """Load and return the case object for the case with the given id.
+class BaseController(WSGIController):
 
-    The parameter uncommitted, if given and not None, should be a
-    dictionary usable as the uncommitted parameter of the loadById
-    method of the case factory.
+    def __init__(self):
+        self.db = None
+        self.page_cache = None
 
-    If the parameter read_only is false (the default), the case must
-    be editable by the current user as determined by the case's
-    user_may_edit method. If the case is not editable in this sense,
-    the method calls the showError method. Also, showError is called
-    if the case is not readable by the current user as determined by
-    the case's user_may_read method.
+    def _loadCase(self, id, uncommitted=None, read_only=False):
+        """Load and return the case object for the case with the given id.
 
-    Note that the default value of the read_only parameter means
-    that by default the _loadCase assumes that cases are loaded in
-    order to modify them and will raise an exception if the user is
-    not allowed to do that. The default value was chosen to err on
-    the side of caution. From a security point of view it's better
-    to deny an action that should have been allowed, than to allow
-    an action that ought to have been denied.
-    """
-    case = g.case_factory.loadById(id, uncommitted=uncommitted)
+        The parameter uncommitted, if given and not None, should be a
+        dictionary usable as the uncommitted parameter of the loadById
+        method of the case factory.
 
-    user = session["USER_AUTHORIZED"]
-    if not case.user_may_read(user):
-        self.showError()
-    if not read_only and not case.user_may_edit(user):
-        self.showError()
+        If the parameter read_only is false (the default), the case must
+        be editable by the current user as determined by the case's
+        user_may_edit method. If the case is not editable in this sense,
+        the method calls the showError method. Also, showError is called
+        if the case is not readable by the current user as determined by
+        the case's user_may_read method.
 
-    session_case = case.getSessionCase()
-    if session.has_key('case'):
-        old_caseid = session.get('case').id
-    else: old_caseid = None
+        Note that the default value of the read_only parameter means
+        that by default the _loadCase assumes that cases are loaded in
+        order to modify them and will raise an exception if the user is
+        not allowed to do that. The default value was chosen to err on
+        the side of caution. From a security point of view it's better
+        to deny an action that should have been allowed, than to allow
+        an action that ought to have been denied.
+        """
+        case = g.case_factory.loadById(id, uncommitted=uncommitted)
 
-    # New session code
-    session['case'] = session_case
+        user = session["USER_AUTHORIZED"]
+        if not case.user_may_read(user):
+            self.showError()
+        if not read_only and not case.user_may_edit(user):
+            self.showError()
 
-    # Only reset navigation if case is switched
-    if str(old_caseid) != str(id) or not  \
-      session.has_key('navigation.tree') \
-      or session.has_key('navigation.tree.recreate'):
-        if session.has_key('navigation.tree.recreate'):
-            del session['navigation.tree.recreate']
-        open_folders = []
-        navigation = get_navigation(id)
-        session['render_mode'] = 'ro'
-        session['navigation.tree'] = navigation
-        session['navigation.openfolders'] = open_folders
-        session['navigation.selectedpage'] = None 
-        # Also reset uncommited fields, because a new case is loaded.
-        session['uncommited_fields'] = {}
-    session.save()
-    return case
+        session_case = case.getSessionCase()
+        if session.has_key('case'):
+            old_caseid = session.get('case').id
+        else: old_caseid = None
 
-class BaseController(WSGIController):
+        # New session code
+        session['case'] = session_case
 
-    def __init__(self):
-        self.db = None
-        self.page_cache = None
+        # Only reset navigation if case is switched
+        if str(old_caseid) != str(id) or not  \
+          session.has_key('navigation.tree') \
+          or session.has_key('navigation.tree.recreate'):
+            if session.has_key('navigation.tree.recreate'):
+                del session['navigation.tree.recreate']
+            open_folders = []
+            navigation = get_navigation(id)
+            session['render_mode'] = 'ro'
+            session['navigation.tree'] = navigation
+            session['navigation.openfolders'] = open_folders
+            session['navigation.selectedpage'] = None 
+            # Also reset uncommited fields, because a new case is loaded.
+            session['uncommited_fields'] = {}
+        session.save()
+        return case
 
-    def _loadCase(self, id, uncommitted=None, read_only=False):
-        return load_case(id, uncommitted, read_only)
-
     def _load_current_case(self, read_only=False):
         """Load and return the case object for the session's current case.
 

Modified: base/trunk/mpulsweb/lib/dialogs.py
===================================================================
--- base/trunk/mpulsweb/lib/dialogs.py	2012-03-16 08:34:52 UTC (rev 5910)
+++ base/trunk/mpulsweb/lib/dialogs.py	2012-03-16 09:29:54 UTC (rev 5911)
@@ -8,7 +8,7 @@
 from pylons import request, tmpl_context as c, app_globals as g
 from mpulsweb.lib.translation import _
 
-from mpulsweb.lib.base import render, session, load_case
+from mpulsweb.lib.base import render, session
 from mpulsweb.lib.helpers import url
 from mpulsweb.model.appointment import CaseAppointmentFactory
 
@@ -51,7 +51,8 @@
                 c.targeturl = url(controller="case", action=context,
                                   id=case_id, confirmed=1)
 
-            case = load_case(case_id)
+            case = self._loadCase(case_id)
+
             statement = case.getPrivacyStatement()
             # Check if there is a "Einverstaendniserklaerung" None if it is
             # not either signed or declined
@@ -94,7 +95,7 @@
                 c.targeturl = url(controller="case", action=context,
                                   id=case_id, confirmed=1)
 
-            case = load_case(case_id)
+            case = self._loadCase(case_id)
             meta = case.getMeta()
             statement = case.getPrivacyStatement()
             # Only check if there is a "Syncpermission" if the Privacy



More information about the Mpuls-commits mailing list