From 2175d1bcdd9530b9d94ee07ebb665ee297ed1be2 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 4 Feb 2008 23:59:54 +0000 Subject: [PATCH] more permission work with funding sources some label changes pulled the user code out into its own module git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8622 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../oilsweb/oilsweb/controllers/acq/fund_source.py | 2 +- Open-ILS/web/oilsweb/oilsweb/lib/__init__.py | 79 +++------------------- Open-ILS/web/oilsweb/oilsweb/lib/acq/fund.py | 4 +- Open-ILS/web/oilsweb/oilsweb/lib/user.py | 63 +++++++++++++++++ .../default/acq/financial/create_fund_source.html | 2 +- .../default/acq/financial/list_fund_sources.html | 2 +- .../default/acq/financial/view_fund_source.html | 2 +- .../templates/oils/default/common/widgets.html | 10 ++- 8 files changed, 84 insertions(+), 80 deletions(-) create mode 100644 Open-ILS/web/oilsweb/oilsweb/lib/user.py diff --git a/Open-ILS/web/oilsweb/oilsweb/controllers/acq/fund_source.py b/Open-ILS/web/oilsweb/oilsweb/controllers/acq/fund_source.py index ea31dc14e0..b19d058740 100644 --- a/Open-ILS/web/oilsweb/oilsweb/controllers/acq/fund_source.py +++ b/Open-ILS/web/oilsweb/oilsweb/controllers/acq/fund_source.py @@ -48,7 +48,7 @@ class FundSourceController(BaseController): r.ctx.core.org_tree = oils.org.OrgUtil.fetch_org_tree() r.ctx.core.perm_tree['CREATE_FUNDING_SOURCE'] = oils.org.OrgUtil.get_union_tree(perm_orgs) - r.ctx.core.perm_orgs['CREATE_FUNDING_SOURCE'] = perm_orgs + r.ctx.core.high_perm_orgs['CREATE_FUNDING_SOURCE'] = perm_orgs r.ctx.acq.currency_types = fund_mgr.fetch_currency_types() return r.render('acq/financial/create_fund_source.html') diff --git a/Open-ILS/web/oilsweb/oilsweb/lib/__init__.py b/Open-ILS/web/oilsweb/oilsweb/lib/__init__.py index f9ca5d0731..045f25f0dc 100644 --- a/Open-ILS/web/oilsweb/oilsweb/lib/__init__.py +++ b/Open-ILS/web/oilsweb/oilsweb/lib/__init__.py @@ -1,20 +1,10 @@ from oilsweb.lib.context import Context, SubContext, ContextItem import osrf.ses, oils.utils.csedit, pylons.config, oils.utils.utils, oils.event +import oilsweb.lib.user from gettext import gettext as _ -class AuthException(Exception): - def __init__(self, info=''): - self.info = info - def __str__(self): - return "%s: %s" % (self.__class__.__name__, unicode(self.info)) - - - class CoreContext(SubContext): - # cache the authenticated user info - _auth_cache = {} - def __init__(self): self.prefix = ContextItem() # web prefix self.media_prefix = ContextItem() # media prefix @@ -28,8 +18,10 @@ class CoreContext(SubContext): self.org_tree = ContextItem() # full org tree self.page = ContextItem() # the current page - # place to store perm org sets - self.perm_orgs = ContextItem(default_value={}) + self.work_orgs = ContextItem() + + # place to store perm org sets for a given permission + self.high_perm_orgs = ContextItem(default_value={}) # place to store slim perm org trees self.perm_tree = ContextItem(default_value={}) @@ -38,67 +30,12 @@ class CoreContext(SubContext): self.prefix = pylons.config['oils_prefix'] self.media_prefix = pylons.config['oils_media_prefix'] self.ac_prefix = pylons.config['oils_added_content_prefix'] - self.skin = 'default' # XXX self.theme = 'default' # XXX + usermgr = oilsweb.lib.user.User(self) + usermgr.fetch_user() + #self.work_orgs = usermgr.fetch_work_orgs() - self.fetchUser() - - def doLogin(self): - if pylons.config.get('oils_demo_user'): - evt = oils.utils.utils.login( - pylons.config['oils_demo_user'], - pylons.config['oils_demo_password'], - 'staff', - pylons.config['oils_demo_workstation']) - oils.event.Event.parse_and_raise(evt) - self.authtoken = evt['payload']['authtoken'] - - def fetchUser(self): - ''' Grab the logged in user and their workstation ''' - - if not self.authtoken: - self.doLogin() - - if self.authtoken: - - if self.authtoken in CoreContext._auth_cache: - self.user = CoreContext._auth_cache[self.authtoken]['user'] - self.workstation = CoreContext._auth_cache[self.authtoken]['workstation'] - return - - self.user = osrf.ses.ClientSession.atomic_request( - 'open-ils.auth', - 'open-ils.auth.session.retrieve', self.authtoken) - - evt = oils.event.Event.parse_event(self.user) - if evt and evt.text_code == 'NO_SESSION': - # our authtoken has timed out. If we have the ability - # to loin, go ahead and try - self.doLogin() - self.user = osrf.ses.ClientSession.atomic_request( - 'open-ils.auth', - 'open-ils.auth.session.retrieve', self.authtoken) - oils.event.Event.parse_and_raise(self.user) - - - if not self.user: - raise AuthException(_('No user found with authtoken %(self.authtoken)s')) - self.workstation = oils.utils.csedit.CSEditor().retrieve_actor_workstation(self.user.wsid()) - - if not self.workstation: - raise AuthException(_('No workstation found')) - - # cache the auth data and destroy any old auth data - CoreContext._auth_cache = { - self.authtoken : { - 'user' : self.user, - 'workstation' : self.workstation - } - } - else: - raise AuthException(_('No authentication token provided')) - Context.applySubContext('core', CoreContext) diff --git a/Open-ILS/web/oilsweb/oilsweb/lib/acq/fund.py b/Open-ILS/web/oilsweb/oilsweb/lib/acq/fund.py index a52e25eefd..e3548dfc68 100644 --- a/Open-ILS/web/oilsweb/oilsweb/lib/acq/fund.py +++ b/Open-ILS/web/oilsweb/oilsweb/lib/acq/fund.py @@ -51,9 +51,7 @@ class FundMgr(object): def retrieve_org_fund_sources(self): sources = self.ses.request( 'open-ils.acq.funding_source.org.retrieve', - self.request_mgr.ctx.core.authtoken, - self.request_mgr.ctx.core.workstation.owning_lib(), - {"full_path":1}).recv().content() + self.request_mgr.ctx.core.authtoken).recv().content() oils.event.Event.parse_and_raise(sources) return sources diff --git a/Open-ILS/web/oilsweb/oilsweb/lib/user.py b/Open-ILS/web/oilsweb/oilsweb/lib/user.py new file mode 100644 index 0000000000..d0f47c1147 --- /dev/null +++ b/Open-ILS/web/oilsweb/oilsweb/lib/user.py @@ -0,0 +1,63 @@ +import osrf.ses, oils.utils.csedit, pylons.config, oils.utils.utils, oils.event +from gettext import gettext as _ + +class AuthException(Exception): + def __init__(self, info=''): + self.info = info + def __str__(self): + return "%s: %s" % (self.__class__.__name__, unicode(self.info)) + +class User(object): + ''' General purpose user utility methods ''' + + def __init__(self, ctx): + self.ctx = ctx + + def try_auto_login(self): + if pylons.config.get('oils_demo_user'): + evt = oils.utils.utils.login( + pylons.config['oils_demo_user'], + pylons.config['oils_demo_password'], + 'staff', + pylons.config['oils_demo_workstation']) + oils.event.Event.parse_and_raise(evt) + self.ctx.authtoken = evt['payload']['authtoken'] + + def fetch_user(self): + ''' Grab the logged in user and their workstation ''' + + if not self.ctx.authtoken: + self.try_auto_login() + + if not self.ctx.authtoken: + raise AuthException(_('No authentication token provided')) + + self.ctx.user = osrf.ses.ClientSession.atomic_request( + 'open-ils.auth', + 'open-ils.auth.session.retrieve', self.ctx.authtoken) + + evt = oils.event.Event.parse_event(self.ctx.user) + if evt and evt.text_code == 'NO_SESSION': + # our authtoken has timed out. See if we can autologin + self.try_auto_login() + if not self.ctx.authtoken: + raise AuthException(_('No authentication token provided')) + self.ctx.user = osrf.ses.ClientSession.atomic_request( + 'open-ils.auth', + 'open-ils.auth.session.retrieve', self.ctx.authtoken) + oils.event.Event.parse_and_raise(self.ctx.user) + + self.ctx.workstation = oils.utils.csedit.CSEditor().retrieve_actor_workstation(self.ctx.user.wsid()) + if not self.ctx.workstation: + raise AuthException(_('No workstation found')) + + def fetch_work_orgs(self): + work_orgs = osrf.ses.ClientSession.atomic_request( + 'open-ils.actor', + 'open-ils.actor.user.get_work_ous.ids', + self.ctx.authtoken) + oils.event.Event.parse_and_raise(work_orgs) + return work_orgs + + + diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/create_fund_source.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/create_fund_source.html index f2d1f25736..b7972d7cf7 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/create_fund_source.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/create_fund_source.html @@ -20,7 +20,7 @@ ${widget.org_select( c.oils.acq.fund_source_owner_.cgi_name, c.oils.core.perm_tree['CREATE_FUNDING_SOURCE'], c.oils.core.workstation.id(), - c.oils.util.get_min_org_depth(c.oils.core.perm_orgs['CREATE_FUNDING_SOURCE']))} + c.oils.util.get_min_org_depth(c.oils.core.high_perm_orgs['CREATE_FUNDING_SOURCE']))} diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_fund_sources.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_fund_sources.html index 672b305c4b..3021a8c763 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_fund_sources.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_fund_sources.html @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- <%inherit file='../base.html'/> <%namespace file='../../common/widgets.html' name='widget'/> -<%def name="page_title()">${_('Create Fund Source')} +<%def name="page_title()">${_('Fund Sources')} <%def name="block_content()"> diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund_source.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund_source.html index ee9078fab0..455354cf58 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund_source.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund_source.html @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- <%inherit file='../base.html'/> <%namespace file='../../common/widgets.html' name='widget'/> -<%def name="page_title()">${_('Create Fund Source')} +<%def name="page_title()">${_('View Fund Source')} <%def name="block_content()"> diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/widgets.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/widgets.html index 0a2fcbb025..89dbb18d0e 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/widgets.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/widgets.html @@ -26,8 +26,14 @@ <%def name='org_select(select_name, tree=None, selected=None, disable_depth=-1)'> - + <% if tree is None: tree = c.oils.core.org_tree -- 2.11.0