source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/config/oiemiddleware.py @ 5466

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/config/oiemiddleware.py@5466
Revision 5466, 2.7 KB checked in by cbyrom, 10 years ago (diff)

Add to code to allow the OAI editor to be used with the new openid
based security system. Add the policy file and secured ini file +
adjust handling of users - enforcing page access via URL content

  • basically either by provider ID or via 'admin=1' parameter for

admin users. For the latter, provider security_redirector module to
allow admin users to use same point of entry as normal users.

  • Property svn:executable set to *
Line 
1'''
2 Middleware controller extension for the OAI info editor
3 
4 @author: C Byrom, Tessella Apr 2009
5'''
6import logging, urllib, os
7from paste.deploy import CONFIG
8from ndg.common.src.models.myconfig import myConfig
9from oai_info_editor.dal.providerinfodao import *
10from oai_info_editor.lib.harvester import Harvester
11   
12class OIEMiddleware(object):
13   
14    MISSING_HELP_TEXT_ERROR = 'Error: Help text missing from config file'
15
16    # flags to lookup in config files - and to refer to data stored in global constants
17    MANDATORY_DATA = 'mandatory'
18    FIXED_DATA = 'fixed'
19    HELP_DATA = 'help_text'
20   
21    def __init__(self, app, g, app_conf):
22        logging.debug("Setting up editor configuration")
23        #this is the next application in the wsgi stack
24        self.app=app
25       
26        #set up the app configuration file
27        cf=app_conf['configfile']
28        cf=myConfig(cf)
29     
30        self.globals=g
31        self.globals.ndgLink=cf.get('layout','ndgLink','http://ndg.nerc.ac.uk')
32        self.globals.ndgImage=cf.get('layout','ndgImage',None)
33        self.globals.helpIcon=cf.get('layout','helpIcon')
34        self.globals.LeftAlt=cf.get('layout','HdrLeftAlt')
35        self.globals.LeftLogo=cf.get('layout','HdrLeftLogo')
36        self.globals.pageLogo="bodcHdr"
37        self.globals.disclaimer=cf.get('default','disclaimer')
38        self.globals.xslt=cf.get('layout','xslt','')
39        self.globals.xmlIcon=cf.get('layout','XMLicon')
40        self.globals.loadingIcon=cf.get('layout','loadingIcon')
41       
42        self.globals.server=cf.get('SERVERS','server','')
43        self.globals.proxy = cf.get('SERVERS','proxyServer')
44        self.globals.mailServer = cf.get('SERVERS', 'mailserver')
45        self.globals.adminEmail = cf.get('SERVERS', 'adminemail')
46       
47        self.globals.dataDir = cf.get('DATA_STORE', 'appDataFileDir')
48        self.globals.backupDir = cf.get('DATA_STORE', 'backupFileDir')
49        harvestDir = cf.get('DATA_STORE', 'harvestDir')
50        if not harvestDir:
51            raise ValueError("No harvest directory config data has been specified - so cannot harvest files.")
52       
53        self.globals.harvester = Harvester(self.globals.mailServer, outDir = harvestDir)
54
55        # store a data access object to general use
56        logging.info("Set up central data access object for reuse across editor")
57        self.globals.dao = createDAOWithClient(client = FILE_CLIENT_TYPE, configFile = cf)
58        logging.info("DAO set up")
59           
60        self.config=cf
61        logging.info("- editor configuration complete")
62       
63    def __call__(self,environ,start_response):
64       
65        environ['appConfig']=self.config
66        return self.app(environ,start_response)
67   
Note: See TracBrowser for help on using the repository browser.