appy.gen: added a session invalidation mechanism: authenticated users will be automatically logged out when their Zope session will expire; improvements in the CodeAnalysis system: more Zope-related extensions are recognized: .vpy, .cpy for Python files, .cpt for Zope Page Templates.
This commit is contained in:
parent
7f02ee3914
commit
791ee42164
|
@ -543,9 +543,24 @@ def traverseWrapper(self, path, response=None, validated_hook=None):
|
||||||
if os.path.splitext(path)[-1].lower() not in doNotTrack:
|
if os.path.splitext(path)[-1].lower() not in doNotTrack:
|
||||||
# Do nothing when the user gets non-pages
|
# Do nothing when the user gets non-pages
|
||||||
userId = self['AUTHENTICATED_USER'].getId()
|
userId = self['AUTHENTICATED_USER'].getId()
|
||||||
if userId: loggedUsers[userId] = t
|
if userId:
|
||||||
|
loggedUsers[userId] = t
|
||||||
|
# "Touch" the SESSION object. Else, expiration won't occur.
|
||||||
|
session = self.SESSION
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def onDelSession(sessionObject, container):
|
||||||
|
'''This function is called when a session expires.'''
|
||||||
|
rq = container.REQUEST
|
||||||
|
if rq.cookies.has_key('__ac') and rq.cookies.has_key('_ZopeId') and \
|
||||||
|
(rq['_ZopeId'] == sessionObject.token):
|
||||||
|
# The request comes from a guy whose session has expired.
|
||||||
|
resp = rq.RESPONSE
|
||||||
|
resp.expireCookie('__ac', path='/')
|
||||||
|
# If the request is a (secundary) Ajax request, we return an empty page.
|
||||||
|
resp.write('<center>For security reasons, your session has ' \
|
||||||
|
'expired.</center>')
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class ZopeInstaller:
|
class ZopeInstaller:
|
||||||
'''This Zope installer runs every time Zope starts and encounters this
|
'''This Zope installer runs every time Zope starts and encounters this
|
||||||
|
@ -629,6 +644,10 @@ class ZopeInstaller:
|
||||||
cfg.profile_registry.registerProfile(self.productName, self.productName,
|
cfg.profile_registry.registerProfile(self.productName, self.productName,
|
||||||
'Installation of %s' % self.productName, 'profiles/default',
|
'Installation of %s' % self.productName, 'profiles/default',
|
||||||
self.productName, cfg.EXTENSION, for_=cfg.IPloneSiteRoot)
|
self.productName, cfg.EXTENSION, for_=cfg.IPloneSiteRoot)
|
||||||
|
# Register a function warning us when a session object is deleted.
|
||||||
|
app = self.zopeContext._ProductContext__app
|
||||||
|
if hasattr(app, 'temp_folder'): # This is not the case in test mode
|
||||||
|
app.temp_folder.session_data.setDelNotificationTarget(onDelSession)
|
||||||
|
|
||||||
def install(self):
|
def install(self):
|
||||||
self.logger.info('is being installed...')
|
self.logger.info('is being installed...')
|
||||||
|
|
|
@ -34,6 +34,7 @@ from Products.Archetypes.Extensions.utils import install_subskin
|
||||||
from Products.Archetypes.config import TOOL_NAME as ARCHETYPETOOLNAME
|
from Products.Archetypes.config import TOOL_NAME as ARCHETYPETOOLNAME
|
||||||
from Products.Archetypes import listTypes, process_types
|
from Products.Archetypes import listTypes, process_types
|
||||||
from Products.GenericSetup import EXTENSION, profile_registry
|
from Products.GenericSetup import EXTENSION, profile_registry
|
||||||
|
from Products.Transience.Transience import TransientObjectContainer
|
||||||
import appy.gen
|
import appy.gen
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger('<!applicationName!>')
|
logger = logging.getLogger('<!applicationName!>')
|
||||||
|
|
|
@ -197,7 +197,7 @@ def normalizeString(s, usage='fileName'):
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
typeLetters = {'b': bool, 'i': int, 'j': long, 'f':float, 's':str, 'u':unicode,
|
typeLetters = {'b': bool, 'i': int, 'j': long, 'f':float, 's':str, 'u':unicode,
|
||||||
'l': list, 'd': dict}
|
'l': list, 'd': dict}
|
||||||
|
exts = {'py': ('.py', '.vpy', '.cpy'), 'pt': ('.pt', '.cpt')}
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class CodeAnalysis:
|
class CodeAnalysis:
|
||||||
'''This class holds information about some code analysis (line counts) that
|
'''This class holds information about some code analysis (line counts) that
|
||||||
|
@ -285,10 +285,9 @@ class CodeAnalysis:
|
||||||
'''Analyses file named p_fileName.'''
|
'''Analyses file named p_fileName.'''
|
||||||
self.numberOfFiles += 1
|
self.numberOfFiles += 1
|
||||||
theFile = file(fileName)
|
theFile = file(fileName)
|
||||||
if fileName.endswith('.py'):
|
ext = os.path.splitext(fileName)[1]
|
||||||
self.analysePythonFile(theFile)
|
if ext in exts['py']: self.analysePythonFile(theFile)
|
||||||
elif fileName.endswith('.pt'):
|
elif ext in exts['pt']: self.analyseZptFile(theFile)
|
||||||
self.analyseZptFile(theFile)
|
|
||||||
theFile.close()
|
theFile.close()
|
||||||
|
|
||||||
def printReport(self):
|
def printReport(self):
|
||||||
|
@ -330,6 +329,8 @@ class LinesCounter:
|
||||||
# or real code within a given part of self.folder code hierarchy.
|
# or real code within a given part of self.folder code hierarchy.
|
||||||
testMarker1 = '%stest%s' % (os.sep, os.sep)
|
testMarker1 = '%stest%s' % (os.sep, os.sep)
|
||||||
testMarker2 = '%stest' % os.sep
|
testMarker2 = '%stest' % os.sep
|
||||||
|
testMarker3 = '%stests%s' % (os.sep, os.sep)
|
||||||
|
testMarker4 = '%stests' % os.sep
|
||||||
j = os.path.join
|
j = os.path.join
|
||||||
for root, folders, files in os.walk(self.folder):
|
for root, folders, files in os.walk(self.folder):
|
||||||
rootName = os.path.basename(root)
|
rootName = os.path.basename(root)
|
||||||
|
@ -338,13 +339,15 @@ class LinesCounter:
|
||||||
continue
|
continue
|
||||||
# Are we in real code or in test code ?
|
# Are we in real code or in test code ?
|
||||||
self.inTest = False
|
self.inTest = False
|
||||||
if root.endswith(testMarker2) or (root.find(testMarker1) != -1):
|
if root.endswith(testMarker2) or (root.find(testMarker1) != -1) or \
|
||||||
|
root.endswith(testMarker4) or (root.find(testMarker3) != -1):
|
||||||
self.inTest = True
|
self.inTest = True
|
||||||
# Scan the files in this folder
|
# Scan the files in this folder
|
||||||
for fileName in files:
|
for fileName in files:
|
||||||
if fileName.endswith('.py'):
|
ext = os.path.splitext(fileName)[1]
|
||||||
|
if ext in exts['py']:
|
||||||
self.python[self.inTest].analyseFile(j(root, fileName))
|
self.python[self.inTest].analyseFile(j(root, fileName))
|
||||||
elif fileName.endswith('.pt'):
|
elif ext in exts['pt']:
|
||||||
self.zpt[self.inTest].analyseFile(j(root, fileName))
|
self.zpt[self.inTest].analyseFile(j(root, fileName))
|
||||||
self.printReport()
|
self.printReport()
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue