[Mpuls-commits] r1280 - wasko/branches/2.0/waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 5 15:53:16 CET 2010


Author: torsten
Date: 2010-02-05 15:53:13 +0100 (Fri, 05 Feb 2010)
New Revision: 1280

Removed:
   wasko/branches/2.0/waskaweb/model/user.py
Log:
Deleted. Was moved to base


Deleted: wasko/branches/2.0/waskaweb/model/user.py
===================================================================
--- wasko/branches/2.0/waskaweb/model/user.py	2010-02-05 14:51:51 UTC (rev 1279)
+++ wasko/branches/2.0/waskaweb/model/user.py	2010-02-05 14:53:13 UTC (rev 1280)
@@ -1,600 +0,0 @@
-# Copyright 2007, 2008 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.
-
-import sys
-import datetime
-
-from pylons import session
-
-import mpulsweb.lib.helpers as h
-from mpulsweb.lib.security import getDbName
-from mpulsweb.lib.db import db
-
-
-MARK_NEWS_AS_READ_SQL = """SELECT markNewsAsRead(%(user_id)s, %(news_id)s)"""
-FETCH_USER_LIST_SQL = """\
-SELECT id, vorname, nachname, rolle, login, gid
-FROM ka_benutzer_tbl_view
-ORDER BY nachname
-"""
-FETCH_USERGROUP_LIST_SQL = """\
-SELECT id, name FROM ka_benutzergruppe_tbl_view ORDER BY name"""
-FETCH_USERGROUP_DATA_SQL = """\
-SELECT id, name FROM ka_benutzergruppe_tbl_view WHERE id = %(id)s"""
-FETCH_USER_DATA_SQL = """\
-SELECT
-    id,
-    vorname,
-    nachname,
-    telefon,
-    aktiviert,
-    passwort_aendern,
-    login,
-    raumnummer,
-    filiale,
-    usesysid,
-    vertreter,
-    rolle,
-    gid,
-    last_login
-FROM ka_benutzer_tbl_view
-WHERE id = %s"""
-FETCH_USER_SYS_ID_SQL = """SELECT usesysid FROM pg_user WHERE usename = '%s'"""
-STORE_USERGROUP_DATA_SQL = """\
-UPDATE ka_benutzergruppe_tbl_view SET name = %(name)s WHERE id = %(id)s"""
-CREATE_USERGROUP_DATA_SQL = """SELECT create_benutzergruppe_ds(%(name)s)"""
-DELETE_USERGROUP_DATA_SQL = """SELECT delete_benutzergruppe_ds(%(id)s)"""
-ADD_USER_TO_GROUP = """SELECT create_nm_benutzer_gruppe_ds(%(bid)s, %(gid)s)"""
-DELETE_USER_FROM_GROUP = """\
-SELECT delete_nm_benutzer_gruppe_ds(%(bid)s, %(gid)s)"""
-GET_USERS_IN_GROUP = """\
-SELECT benutzer_id FROM nm_benutzer_gruppe_tbl_view WHERE gruppe_id = %(id)s;"""
-CREATE_USER_SQL_M = """\
-SELECT ka_create_role(%(agency)s, %(grouprole)s, %(loginname)s,
-                      %(firstname)s, %(surname)s, %(phone)s, %(room)s,
-                      %(branchoffice)s, %(activated)s , %(setpassword)s)"""
-DELETE_USER_SQL = """SELECT ka_delete_role(%(login)s, %(agency)s)"""
-RESET_USER_PASSWORD_SQL = """SELECT waska_reset_password(%(login)s, %(agency)s)
-"""
-ALTER_USER_PASSWORD_SQL = """SELECT ka_set_password(%(login)s, %(password)s)"""
-ALTER_USER_STANDIN_SQL = """SELECT ka_set_standin(%(standin)s, %(userid)s)"""
-STORE_USER_DATA_SQL = """UPDATE ka_benutzer_tbl_view SET %s WHERE id = %%(id)s
-"""
-
-
-class UserGroupList:
-
-    def __init__(self):
-        self.list = []
-        try:
-            conn, cur = None, None
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(FETCH_USERGROUP_LIST_SQL)
-                for r in cur.fetchall():
-                    name = h.ensure_unicode(r[1])
-                    data = {'id': r[0], 'name': name}
-                    o = UserGroup()
-                    o.setData(data)
-                    self.list.append(o)
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on creating user group overview: %s" % str(err)
-
-    def getGroupList(self, filter):
-        if filter:
-            return [e for e in self.list if e.id not in filter]
-        else:
-            return self.list
-
-
-class UserGroupFactory:
-
-    def create(self, name):
-        try:
-            conn, cur = None, None
-            group = UserGroup()
-            fields = {'name': name}
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(CREATE_USERGROUP_DATA_SQL, fields)
-                r = cur.fetchone()
-                conn.commit()
-                data = {'id': r[0], 'name': name}
-                group.setData(data)
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on creating usergroup: %s" % str(err)
-        return group
-
-    def load(self, id):
-        try:
-            conn, cur = None, None
-            fields = {'id': id}
-            group = UserGroup()
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(FETCH_USERGROUP_DATA_SQL, fields)
-                r = cur.fetchone()
-                name = h.ensure_unicode(r[1])
-                data = {'id': r[0], 'name': name}
-                group.setData(data)
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on loading user group overview: %s" % str(err)
-        return group
-
-
-class UserGroup:
-
-    def __init__(self, id=None):
-        self.id = ''
-        self.name = ''
-
-        if id:
-            factory = UserGroupFactory()
-            group = factory.load(id)
-            self.id = group.id
-            self.name = group.name
-
-    def setData(self, data):
-        self.id = data.get('id', '')
-        self.name = data.get('name', '')
-
-    def setUser(self, list):
-        if not list:
-            return
-        old_user = set(self._getCurrentUserIds())
-        new_user = set([int(id) for id in list])
-
-        to_add = new_user.difference(old_user)
-        to_delete = old_user.difference(new_user)
-        try:
-            conn, cur = None, None
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                for id in to_delete:
-                    cur.execute(DELETE_USER_FROM_GROUP, {'bid': id,
-                                                         'gid': self.id})
-
-                for id in to_add:
-                    cur.execute(ADD_USER_TO_GROUP, {'bid': id, 'gid': self.id})
-                conn.commit()
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on setting userids in group: %s" % str(err)
-
-    def _getCurrentUserIds(self):
-        list = []
-        try:
-            conn, cur = None, None
-            fields = {'id': self.id}
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(GET_USERS_IN_GROUP, fields)
-                for id in cur.fetchall():
-                    list.append(int(id[0]))
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on geting userids in group: %s" % str(err)
-        return list
-
-    def getUser(self):
-        '''Returns a UserList object of users who are member if this group'''
-        # Build userlist of users who are member of this group
-        list = self._getCurrentUserIds()
-        users = UserListObject()
-        userlist = users.getUserList()
-        users.user = [user for user in userlist if user.id in list]
-        return users
-
-    def delete(self):
-        '''Deletes the usergroup object from the database'''
-        try:
-            conn, cur = None, None
-            fields = {'id': self.id}
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(DELETE_USERGROUP_DATA_SQL, fields)
-                conn.commit()
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on creating usergroup: %s" % str(err)
-
-    def store(self):
-        '''Stores the data the usergroup object in the database (UPDATE)'''
-        try:
-            conn, cur = None, None
-            fields = {'id': self.id, 'name': self.name}
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(STORE_USERGROUP_DATA_SQL, fields)
-                conn.commit()
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on creating usergroup: %s" % str(err)
-
-
-class UserListObject:
-
-    def __init__(self):
-        self.user = []
-        try:
-            conn, cur = None, None
-            try:
-                conn = db.getConnection()
-                cur = conn.cursor()
-                cur.execute(FETCH_USER_LIST_SQL)
-                for r in cur.fetchall():
-                    firstname = h.ensure_unicode(r[1])
-                    lastname = h.ensure_unicode(r[2])
-                    login = h.ensure_unicode(r[4])
-                    data = {'id': r[0], 'gid': r[5],
-                            'firstname': firstname, 'lastname': lastname,
-                            'role': r[3], 'login': login}
-                    uo = UserObject()
-                    uo.setData(data)
-                    self.user.append(uo)
-            finally:
-                db.recycleConnection(conn, cur)
-        except StandardError, err:
-            print >> sys.stderr, "Error on creating user overview: %s" % str(err)
-
-    def getAdminList(self, filter=None):
-        admins = [e for e in self.user if e.isAdmin()]
-        if filter:
-            return [e for e in admins if e.id not in filter]
-        else:
-            return admins
-
-    def getUserList(self, filter=None):
-        if filter:
-            return [e for e in self.user if e.id not in filter]
-        else:
-            return self.user
-
-
-class User:
-
-    def __init__(self, id=None):
-        self.id = id
-        self.gid = None
-        self.login = ''
-        self.full_login = '' #full login: ka_dbname_login
-        self.role = ''
-        self.agency = ''
-        self.last_name = ''
-        self.first_name = ''
-        self.activated = True
-        self.needs_passrefresh = True
-
-    def getLogin(self):
-        return self.login
-
-    def getAgency(self):
-        return self.agency
-
-    def getPermissionRole(self):
-        '''Returns the users permissionrole
-           Available rolenames:
-             * admin
-             * cm
-             * pt
-        '''
-        try:
-            tok = self.role.split('_')
-            return "_".join(tok[-1:])
-        except:
-            return None
-
-    def getRole(self):
-        """Return the user's role as a string to display in the ui
-           Translate Roles:
-             * admin -> Admin
-             * cm    -> CM
-             * pt   -> PT
-        """
-        permrole = self.getPermissionRole()
-        if permrole == 'cm':
-            return 'CM'
-        elif permrole == 'admin':
-            return 'Admin'
-        elif permrole == 'pt':
-            return 'PT'
-        else:
-            return permrole
-
-    def isActivated(self):
-        return self.activated
-
-    def needsNewPass(self):
-        return self.needs_passrefresh
-
-    def isAdmin(self):
-        return (self.getRole() == "Admin")
-
-    def shortenedName(self):
-        name = []
-        if self.last_name:
-            name.append(self.last_name)
-
-        if self.first_name:
-            name.append(", ")
-            name.append(self.first_name[0])
-            name.append(".")
-
-        if not name:
-            return ""
-
-        return "".join(name)
-
-
-class SessionUser(User):
-
-    def __init__(self, lname, password):
-        User.__init__(self, None)
-        tok = lname.split('_')
-        self.full_login = lname
-        self.login = "_".join(tok[2:])
-        self.agency = tok[1]
-        self.password = password
-
-    def setData(self, data):
-        self.id = data.get('id', '')
-        self.gid = data.get('gid', '')
-        self.first_name = data.get('firstname', '')
-        self.last_name = data.get('lastname', '')
-        self.activated = data.get('activated', False)
-        self.needs_passrefresh = data.get('newpass', True)
-        self.role = data.get('role', '')
-        self.last_login = data.get('last_login') or datetime.datetime.now()
-        self.standin = data.get('standin')
-
-
-class SessionSuperAdmin(User):
-
-    def __init__(self, lname, password):
-        User.__init__(self, 0)
-        self.last_name = 'Zentrale Administration'
-        self.needs_passrefresh = False
-        self.role = 'ka_%s_admin' % getDbName()
-        self.full_login = lname
-        tok = lname.split('_')
-        self.login = "_".join(tok[2:])
-        self.agency = tok[1]
-        self.password = password
-        self.last_login = datetime.datetime.now()
-
-
-class UserObject(User):
-
-    def __init__(self, id=None):
-        User.__init__(self, id)
-        self.telephone = ''
-        self.room = ''
-        self.branchoffice = ''
-        self.telephone = ''
-        self.standin = None
-
-        # Load existing user?
-        if not id is None:
-            #SuperAdmin
-            if str(id) == '0':
-                self.setAdmUser()
-            else:
-                self._fetchData(id)
-
-    def setNewsAsRead(self, id):
-        conn, cur = None, None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            fields = {'user_id': self.id, 'news_id': id}
-            cur.execute(MARK_NEWS_AS_READ_SQL, fields)
-            conn.commit()
-        finally:
-            db.recycleConnection(conn, cur)
-        return 1
-
-    def setAdmUser(self):
-        self.last_name = 'Zentrale Administration'
-        self.needs_passrefresh = False
-        self.role = 'ka_%s_admin_ka' % getDbName()
-        self.full_login = 'ka_%s_adm' % getDbName()
-        tok = self.full_login.split('_')
-        self.login = "_".join(tok[2:])
-        self.agency = tok[1]
-
-    def setPassword(self, password):
-        conn, cur = None, None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            fields = {'login': self.full_login, 'password': password}
-            cur.execute(ALTER_USER_PASSWORD_SQL, fields)
-            new_pass = cur.fetchone()[0]
-            conn.commit()
-            self.needs_passrefresh = False
-            return new_pass
-        finally:
-            db.recycleConnection(conn, cur)
-        return None
-
-    def resetPassword(self):
-        conn, cur = None, None
-        password = None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            fields = {'login': self.getLogin(), 'agency': self.getAgency()}
-            cur.execute(RESET_USER_PASSWORD_SQL, fields)
-            password = cur.fetchone()[0]
-            conn.commit()
-        finally:
-            db.recycleConnection(conn, cur)
-
-        # Now set and save the passrefresh flag
-        self.needs_passrefresh = True
-        self.store()
-
-        return password
-
-    def _fetchData(self, id):
-        conn, cur = None, None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            cur.execute(FETCH_USER_DATA_SQL % id)
-            ud = cur.fetchone()
-            if not ud is None:
-                # Set userdata
-                self.id = ud[0]
-                self.first_name = h.ensure_unicode(ud[1])
-                self.last_name = h.ensure_unicode(ud[2])
-                self.telephone = h.ensure_unicode(ud[3])
-                self.activated = ud[4]
-                self.needs_passrefresh = ud[5]
-                self.full_login = h.ensure_unicode(ud[6])
-                self.room = h.ensure_unicode(ud[7])
-                self.branchoffice = h.ensure_unicode(ud[8])
-                self.oid = ud[9]
-                self.standin = ud[10]
-                self.role = ud[11]
-                self.gid = ud[12] # id usergroup of the user
-                self.last_login = ud[13] # timestamp
-                tok = self.full_login.split('_')
-                self.login = "_".join(tok[2:])
-                self.agency = tok[1]
-        finally:
-            db.recycleConnection(conn, cur)
-
-    def setStandin(self, gid):
-        con, cur = None, None
-        fields = {'userid': self.id, 'standin':gid}
-        try:
-            con = db.getConnection()
-            cur = con.cursor()
-            cur.execute(ALTER_USER_STANDIN_SQL, fields)
-            con.commit()
-            session['USER_AUTHORIZED'].standin = gid
-            session.save()
-        finally:
-            db.recycleConnection(con, cur)
-
-    def setData(self, data):
-        """Set the user data from the dictionary data.
-        Usually data is the dictionary returned from the formencode validation.
-        """
-        self.id = data.get('id', self.id)
-        self.gid = data.get('gid', self.gid)
-        self.first_name = data.get('firstname', self.first_name)
-        self.role = data.get('role', self.role)
-        self.last_name= data.get('lastname', self.last_name)
-        self.telephone = data.get('telephone', self.telephone)
-        self.room = data.get('room', self.room)
-        self.branchoffice = data.get('branchoffice', self.branchoffice)
-        self.full_login = data.get('login', self.full_login)
-        tok = self.full_login.split('_')
-        self.login = "_".join(tok[2:])
-        self.activated = data.get('activated', self.activated)
-        self.needs_passrefresh = data.get('newpass', self.needs_passrefresh)
-
-    def createLogin(self, login=None, role=None, agency=None):
-        self.login = login
-        self.role = role
-        self.agency = agency
-        password = None
-        conn, cur = None, None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            fields = {'loginname': self.login,
-                      'grouprole': self.role,
-                      'agency': self.agency,
-                      'firstname': self.first_name,
-                      'surname': self.last_name,
-                      'phone': self.telephone,
-                      'room': self.room,
-                      'branchoffice': self.branchoffice,
-                      'activated': self.activated,
-                      'setpassword': self.needs_passrefresh
-                      }
-            cur.execute(CREATE_USER_SQL_M, fields)
-            result = cur.fetchone()
-            password = result[0]
-            conn.commit()
-        finally:
-            db.recycleConnection(conn, cur)
-        return password
-
-    def store(self):
-        fields = {
-            'vorname': self.first_name,
-            'nachname': self.last_name,
-            'telefon': self.telephone,
-            'aktiviert': self.activated,
-            'raumnummer': self.room,
-            'filiale': self.branchoffice,
-            'passwort_aendern': self.needs_passrefresh
-        }
-        update_str = []
-        for key in fields.iterkeys():
-            update_str.append('%s=%%(%s)s' % (key, key))
-        fields['id'] = self.id
-        conn, cur = None, None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            sql = STORE_USER_DATA_SQL % ", ".join(update_str)
-            cur.execute(sql, fields)
-            conn.commit()
-        finally:
-            db.recycleConnection(conn, cur)
-
-    def delete(self):
-        conn, cur = None, None
-        try:
-            conn = db.getConnection()
-            cur = conn.cursor()
-            fields = {'login': self.login, 'agency': self.agency}
-            cur.execute(DELETE_USER_SQL, fields)
-            conn.commit()
-            return True
-        finally:
-            db.recycleConnection(conn, cur)
-        return False



More information about the Mpuls-commits mailing list