Cache perms in session.

Cache auth in session.
Error in update issue voucher where departments could never change fixed.
Added logging for sqlalchemy in development.ini
This commit is contained in:
Tanshu 2013-01-02 22:47:39 +05:30
parent fc06aab741
commit a9176f783d
5 changed files with 31 additions and 18 deletions

View File

@ -2,14 +2,19 @@ import uuid
from brewman.models.auth import User
def groupfinder(user_id, request):
if type(user_id) == str:
user_id = uuid.UUID(user_id)
perms = []
user = User.by_id(user_id)
for item in user.groups:
for perm in item.roles:
perms.append(perm.name)
perms = f7(perms)
if request is not None and 'perms' in request.session:
perms = request.session['perms']
else:
if type(user_id) == str:
user_id = uuid.UUID(user_id)
perms = []
user = User.by_id(user_id)
for item in user.groups:
for perm in item.roles:
perms.append(perm.name)
perms = f7(perms)
if request is not None:
request.session['perms'] = perms
return perms

View File

@ -1,6 +1,5 @@
import datetime
import uuid
from pyramid.response import Response
from pyramid.security import authenticated_userid
from pyramid.view import view_config
from sqlalchemy import or_
@ -10,7 +9,7 @@ from brewman.models.master import AttendanceType, Employee
from brewman.models.validation_exception import ValidationError, TryCatchFunction
from brewman.models.voucher import Attendance
from brewman.views.fingerprint import get_prints
from brewman.views.services.session import session_period_start, session_period_finish, session_current_date
from brewman.views.services.session import session_period_start, session_period_finish, session_current_date
__author__ = 'tanshu'

View File

@ -36,6 +36,8 @@ def user_permission(request):
user_id = authenticated_userid(request)
if user_id is None:
auth = {'isAuthenticated': False, 'perms': {}}
elif 'auth' in request.session:
auth = request.session['auth']
else:
user = User.by_id(uuid.UUID(user_id))
auth = {'isAuthenticated': True, 'Name': user.name, 'UserID': user.id}
@ -44,6 +46,7 @@ def user_permission(request):
for item in Role.list():
perms[item.name] = True if item.name in session_perms else False
auth['perms'] = perms
request.session['auth'] = auth
return auth

View File

@ -71,6 +71,13 @@ def issue_update_voucher(voucher, json, user):
voucher.user_id = user.id
voucher.last_edit_date = datetime.datetime.now()
for item in voucher.journals:
if item.debit == 1:
destination = item.cost_center_id
else:
source = item.cost_center_id
old_batch_consumed = True if source == CostCenter.cost_center_purchase() else False if destination == CostCenter.cost_center_purchase() else None
for item in json['Journals']:
if int(item['Debit']) == 1:
destination = uuid.UUID(item['CostCenter']['CostCenterID'])
@ -78,14 +85,8 @@ def issue_update_voucher(voucher, json, user):
source = uuid.UUID(item['CostCenter']['CostCenterID'])
if source == destination:
raise ValidationError("Source cannot be the same as destination")
new_batch_consumed = True if source == CostCenter.cost_center_purchase() else False if destination == CostCenter.cost_center_purchase() else None
for item in voucher.journals:
if item.debit == 1:
destination = item.cost_center_id
else:
source = item.cost_center_id
old_batch_consumed = True if source == CostCenter.cost_center_purchase() else False if destination == CostCenter.cost_center_purchase() else None
new_batch_consumed = True if source == CostCenter.cost_center_purchase() else False if destination == CostCenter.cost_center_purchase() else None
if new_batch_consumed != old_batch_consumed:
raise ValidationError("Purchase cost center cannot be changed")

View File

@ -18,7 +18,7 @@ port = 6543
# Begin logging configuration
[loggers]
keys = root, brewman
keys = root, brewman, sqlalchemy.engine.base
[handlers]
keys = console
@ -35,6 +35,11 @@ level = DEBUG
handlers =
qualname = brewman
[logger_sqlalchemy.engine.base]
level = DEBUG
handlers =
qualname = sqlalchemy.engine.base
[handler_console]
class = StreamHandler
args = (sys.stderr,)