[Mpuls-commits] r2969 - in jmd/trunk: . jmdweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 10 12:11:16 CEST 2010


Author: bh
Date: 2010-06-10 12:11:12 +0200 (Thu, 10 Jun 2010)
New Revision: 2969

Added:
   jmd/trunk/jmdweb/model/struktur.py
Modified:
   jmd/trunk/ChangeLog
Log:
* jmdweb/model/struktur.py: New.  Model part of the struktur user
management


Modified: jmd/trunk/ChangeLog
===================================================================
--- jmd/trunk/ChangeLog	2010-06-10 10:09:32 UTC (rev 2968)
+++ jmd/trunk/ChangeLog	2010-06-10 10:11:12 UTC (rev 2969)
@@ -1,3 +1,8 @@
+2010-06-10  Bernhard Herzog  <bh at intevation.de>
+
+	* jmdweb/model/struktur.py: New.  Model part of the struktur user
+	management
+
 2010-06-09  Roland Geider <roland.geider at intevation.de>
 
         * Changes: Created first version of changes file

Added: jmd/trunk/jmdweb/model/struktur.py
===================================================================
--- jmd/trunk/jmdweb/model/struktur.py	2010-06-10 10:09:32 UTC (rev 2968)
+++ jmd/trunk/jmdweb/model/struktur.py	2010-06-10 10:11:12 UTC (rev 2969)
@@ -0,0 +1,116 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright 2007, 2008, 2010 Intevation GmbH, Germany, <info at intevation.de>
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
+# Web-Anwendungs-Server fuer Kompetenzagenturen).
+#
+# mpuls WASKA is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Affero General Public
+# License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
+#
+# mpuls WASKA has been developed on behalf of the
+# Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
+# within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
+# European Social Fund resources.
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+
+from pylons import config, session
+
+from mpulsweb.lib.db import DB
+from mpulsweb.lib.security import get_db_parameters, getDbName
+from mpulsweb.model.user import UserListObject, parse_dblogin
+
+
+def get_db():
+    current_user = session['USER_AUTHORIZED']
+    return DB(**get_db_parameters(getDbName(),
+                                  current_user.login,
+                                  current_user.password,
+                                  config.get('jmd.structuredb.host'),
+                                  config.get('jmd.structuredb.port'),
+                                  config.get('jmd.structuredb.database'),
+                                  config.get('jmd.structuredb.user')))
+
+
+def get_struktur_users():
+    """Return a list with the ids of the users with access to the struktur part.
+    """
+    all_users = UserListObject()
+    user_map = dict((user.login, user.id) for user in all_users.getUserList())
+
+    struktur_db = get_db()
+    con = cur = None
+    try:
+        con = struktur_db.getConnection()
+        cur = con.cursor()
+        cur.execute("SELECT login FROM jmd_struktur_nutzer_view")
+        user_ids = []
+        while True:
+            row = cur.fetchone()
+            if not row:
+                break
+            user_id = user_map.get(parse_dblogin(row[0])[0])
+            if user_id is not None:
+                user_ids.append(user_id)
+    finally:
+        struktur_db.recycleConnection(con, cur)
+    return user_ids
+
+
+def set_struktur_users(user_ids):
+    """Define the group of users who may access the struktur part.
+
+    All users in user_ids and only those users, are given permission to
+    access the struktur data."""
+    user_ids = set(user_ids)
+    all_users = UserListObject()
+
+    struktur_db = get_db()
+    con = cur = None
+    try:
+        try:
+            con = struktur_db.getConnection()
+            cur = con.cursor()
+            cur.execute("SELECT jmd_clear_struktur_nutzer_group()")
+            for user in all_users.getUserList():
+                if user.id in user_ids:
+                    cur.execute("SELECT"
+                                " jmd_add_struktur_nutzer(%s, %s, %s, %s)",
+                                (user.getAgency(), user.getLogin(),
+                                 user.first_name, user.last_name))
+            con.commit()
+        except:
+            con.rollback()
+            raise
+    finally:
+        struktur_db.recycleConnection(con, cur)
+
+
+def is_struktur_user():
+    """Return whether the current user may access the struktur part."""
+    struktur_db = get_db()
+    con = cur = None
+    try:
+        con = struktur_db.getConnection()
+        cur = con.cursor()
+        cur.execute("SELECT jmd_check_struktur_permission()")
+        user_ids = []
+        row = cur.fetchone()
+        if not row:
+            return False
+        return row[0]
+    finally:
+        struktur_db.recycleConnection(con, cur)
+    return user_ids


Property changes on: jmd/trunk/jmdweb/model/struktur.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the Mpuls-commits mailing list