[Mpuls-commits] r6075 - base/trunk/mpulsweb/model
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Sep 27 17:54:28 CEST 2012
Author: torsten
Date: 2012-09-27 17:54:28 +0200 (Thu, 27 Sep 2012)
New Revision: 6075
Modified:
base/trunk/mpulsweb/model/user.py
Log:
Added functions to set the visibility of cases of an agency for users. This is
only used if the evaluation server is enabled.
Modified: base/trunk/mpulsweb/model/user.py
===================================================================
--- base/trunk/mpulsweb/model/user.py 2012-09-27 15:51:54 UTC (rev 6074)
+++ base/trunk/mpulsweb/model/user.py 2012-09-27 15:54:28 UTC (rev 6075)
@@ -24,6 +24,7 @@
import datetime
import logging
+from pylons import g
import mpulsweb.lib.helpers as h
from mpulsweb.lib.security import getDbName
@@ -41,6 +42,8 @@
FROM ka_benutzer_tbl_view
ORDER BY nachname
"""
+FETCH_LINKED_AGENCY= """\
+SELECT fkz_id from nm_user_fkz where user_id = %(user_id)s"""
FETCH_USERGROUP_LIST_SQL = """\
SELECT id, name FROM ka_benutzergruppe_tbl_view ORDER BY name"""
FETCH_USERGROUP_DATA_SQL = """\
@@ -77,6 +80,9 @@
SELECT ka_create_role(%(agency)s, %(grouprole)s, %(loginname)s,
%(firstname)s, %(surname)s, %(phone)s, %(room)s,
%(branchoffice)s, %(activated)s , %(setpassword)s)"""
+GET_LAST_CREATED_USER = """\
+SELECT max(id) from ka_benutzer_tbl
+"""
DELETE_USER_SQL = """SELECT ka_delete_role(%(login)s, %(agency)s)"""
RESET_USER_PASSWORD_SQL = """SELECT mpuls_reset_password(%(login)s, %(agency)s)
"""
@@ -84,6 +90,8 @@
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
"""
+DELETE_USER_AGENCY_SQL = """DELETE from nm_user_fkz WHERE user_id = %(id)s"""
+ADD_USER_AGENCY_SQL = """INSERT INTO nm_user_fkz (user_id, fkz_id) VALUES (%(id)s, %(fkz)s)"""
def parse_dblogin(dblogin):
@@ -337,6 +345,17 @@
else:
return permrole
+ def getLinkedAgency(self):
+ """Returns a list of ids of linked agencys. This function is only used
+ in evaluation server."""
+ if g.mpuls_config.is_enabled('module', 'agency-overview'):
+ conn = db.getConnection()
+ cur = conn.cursor()
+ cur.execute(FETCH_LINKED_AGENCY % {'user_id': self.id})
+ return [int(id[0]) for id in cur.fetchall()]
+ else:
+ return []
+
def isActivated(self):
return self.activated
@@ -404,6 +423,7 @@
self.branchoffice = ''
self.telephone = ''
self.standin = None
+ self.agencys = []
# Load existing user?
if not id is None:
@@ -482,6 +502,7 @@
self.gid = ud[12] # id usergroup of the user
self.last_login = ud[13] # timestamp
self.login, self.agency = parse_dblogin(self.full_login)
+ self.linked_fkz = self.getLinkedAgency()
finally:
db.recycleConnection(conn, cur)
@@ -504,6 +525,7 @@
self.branchoffice = data.get('branchoffice', self.branchoffice)
self.activated = data.get('activated', self.activated)
self.needs_passrefresh = data.get('newpass', self.needs_passrefresh)
+ self.linked_fkz = data.get('agencys', self.agencys)
if "full_login" in data:
self.full_login = data.get("full_login", self.full_login)
@@ -546,7 +568,16 @@
}
cur.execute(CREATE_USER_SQL_M, fields)
result = cur.fetchone()
+ cur.execute(GET_LAST_CREATED_USER)
+ self.id = cur.fetchone()[0]
password = result[0]
+
+ # Set responsibilty
+ if g.mpuls_config.is_enabled('module', 'agency-overview'):
+ cur.execute(DELETE_USER_AGENCY_SQL, {'id': self.id})
+ for fkz in self.linked_fkz:
+ cur.execute(ADD_USER_AGENCY_SQL, {'id': self.id, 'fkz': fkz})
+
conn.commit()
finally:
db.recycleConnection(conn, cur)
@@ -568,6 +599,12 @@
fields['id'] = self.id
db.execute(STORE_USER_DATA_SQL % ", ".join(update_str), fields)
+ # Set responsibilty
+ if g.mpuls_config.is_enabled('module', 'agency-overview'):
+ db.execute(DELETE_USER_AGENCY_SQL, {'id': self.id})
+ for fkz in self.linked_fkz:
+ db.execute(ADD_USER_AGENCY_SQL, {'id': self.id, 'fkz': fkz})
+
def delete(self):
db.execute(DELETE_USER_SQL,
{'login': self.login, 'agency': self.agency})
More information about the Mpuls-commits
mailing list