def upgrade_1_1( defenv, appenv ) : """Upgrade database version from 1.1 to 1.2""" import zeta.lib.helpers as h from zeta.config.environment import syscomp, wikicomp, vcscomp, attachcomp # Upgrade with SQL scripts upgradewithscripts( '1_1', defenv, appenv ) # Set created_on value for static_wiki table for older entries swikis = syscomp.updatecreatedon( byuser=g_user ) print " Updated `created_on` field for %s guest wiki entries" % len(swikis) # Update guest wiki pages' type attribute print " Updating guest wiki pages' type attribute" swtype = wikicomp.get_wikitype(syscomp.get_sysentry('def_wikitype')) [ syscomp.set_staticwiki(sw.path, sw.text, swtype=swtype, byuser=g_user) for sw in syscomp.get_staticwiki() ] # Add wiki types, wikitypes = syscomp.get_sysentry( 'wikitypes' ) wikitypes = h.parse_csv( wikitypes ) addtypes = h.WIKITYPES addtypes = [ wt for wt in addtypes if wt not in wikitypes ] if addtypes : print " Adding `%s` wikitype to system table" % addtypes wikitypes = ', '.join( wikitypes + addtypes ) syscomp.set_sysentry({ 'wikitypes' : wikitypes }, byuser=g_user ) print " Adding `%s` wikitypes to wiki_type table" % wikitypes wikicomp.create_wikitype( addtypes, byuser=g_user ) # Move attachment contents from database to envpath print " Moving attachment contents from database to disk files " atts = attachcomp.get_attach() [ attachcomp.db2file(a) for a in atts ] # Update the size field in attachment table. print " Updating attachment size field in db table " [ attachcomp.updatesize(a) for a in atts ] # Add `hg` vcs type. vcstypes = syscomp.get_sysentry( 'vcstypes' ) vcstypes = h.parse_csv( vcstypes ) if 'hg' not in vcstypes : print " Adding `hg` vcstype to system table" vcstypes = ', '.join( vcstypes + [ 'hg' ] ) syscomp.set_sysentry({ 'vcstypes' : vcstypes }, byuser=g_user ) print " Adding `hg` vcstype to vcs_type table" vcscomp.create_vcstype( ['hg'], byuser=g_user )
def upgradedb( self, environ ) : r""" ==== Upgrade database When ever a deployed version of application is upgraded with a new version, database //might// get outdated. To bring the database in consistence with the application, use this command. > [<PRE paster request <.ini file> /pasteradmin/upgradedb >] """ from zeta.model.upgrade import upgradedb from zeta.config.environment import syscomp dbver_db = syscomp.get_sysentry( u'database_version' ) dbver_app = dbversion defenv = join( pkg_path, 'defenv' ) print "Current database version : %s" % dbver_db print "Application compatible version : %s" % dbver_app print "Upgrading the database from, %s to %s ..." % (dbver_db, dbver_app) upgradedb( dbver_db, dbver_app, defenv, config['zeta.envpath'] ) syscomp.set_sysentry( { u'database_version' : unicode(dbver_app) }, byuser=u'admin' ) print "Database set to latest DB version %s" % dbver_app
def check(self, app, environ, start_response): """Should return True if the user has all or any permissions or False if the user doesn't exist or the permission check fails. In this implementation permission names are uppercase.""" from zeta.lib.helpers import fromconfig from zeta.config.environment import userscomp, syscomp, projcomp authusername = environ.get('REMOTE_USER', u'anonymous') if not _currentuser() and not userscomp.user_exists(authusername): raise NotAuthorizedError('No such user %s' % authusername) # If and when strict authentication strict = self.strict or syscomp.get_sysentry('strictauth') if (authusername == 'anonymous') and (strict in ['True', 'true']): raise NotAuthenticatedError('Please login or Register yourself') if self.project: # This block is only used for testing. p = self.project teams = projcomp.userinteams( p, authusername ) + \ [ projcomp.team_nomember ] context = [(p.projectname, t) for t in teams] + [authusername] else: context = None # Check for permissions. status = pms_root.check(self.permnames, allliterals=self.all, context=context) if status == False: raise NotAuthorizedError("User doesn't have the permissions %s" % self.permnames) return app(environ, start_response)
def check(self, app, environ, start_response): """ Should return True if the user belong to all or any of the permission group or False if the user doesn't exist or permission check fails. In this implementation group names are lower case. """ from zeta.lib.helpers import fromconfig from zeta.config.environment import userscomp, syscomp authusername = environ.get('REMOTE_USER', u'anonymous') if not _currentuser() and not userscomp.user_exists(authusername): raise NotAuthorizedError('No such user') # If Strict authentication is enabled, and REMOTE_USER is 'anonymous' strict = self.strict or syscomp.get_sysentry('strictauth') if (authusername == 'anonymous') and (strict in ['True', 'true']): raise NotAuthenticatedError('Please login or Register yourself') # Check for permission groups if not userscomp.user_has_permgroups(authusername, self.permgroups, self.all): if self.error: raise self.error else: raise NotAuthorizedError( "User doesn't belong to permgroups %s" % self.permgroups) return app(environ, start_response)
def upgrade_1_0( defenv, appenv ) : """Upgrade database version from 1.0 to 1.1""" import zeta.lib.helpers as h from zeta.config.environment import syscomp, vcscomp, userscomp # Should we explicitly create a table ???, # Create ticket_filter table print " Creating table for `ticket_filters`, `reviewset`, `vcsmount`\n" meta.metadata.create_all( bind=meta.engine, checkfirst=True ) # Update `googlemaps` field in system table print " `googlemaps` should specify the generated key (No more boolean) ...\n" entry = { u'googlemaps' : u'' } syscomp.set_sysentry( entry, byuser=g_user ) # Rename ZETA_ADMIN permission name to SITE_ADMIN permission name print " Changing permission name ZETA_ADMIN to SITE_ADMIN" userscomp.change_permname( 'ZETA_ADMIN', 'SITE_ADMIN', byuser=g_user ) # Add `bzr` vcs type. vcstypes = syscomp.get_sysentry( 'vcstypes' ) vcstypes = h.parse_csv( vcstypes ) if 'bzr' not in vcstypes : print " Adding `bzr` vcstype to system table" vcstypes = ', '.join( vcstypes + [ 'bzr' ] ) syscomp.set_sysentry({ 'vcstypes' : vcstypes }, byuser=g_user ) print " Adding `bzr` vcstype to vcs_type table" vcscomp.create_vcstype( ['bzr'], byuser=g_user )
def __before__( self, environ ) : # TODO : Should the following line remain commented ? # self.beforecontrollers() from zeta.config.environment import userscomp, syscomp c.sysentries = syscomp.get_sysentry() if not request.environ['paste.command_request'] : raise Exception( 'Invoke these request via command' )
def updateoffset(self, account, offset, byuser=None): """Remember `offset` till which mails where fetched for `account`""" from zeta.config.environment import syscomp accoffsets = eval(syscomp.get_sysentry(u'mailacc_offsets', '{}')) accoffsets[account] = offset accoffsets = pprint.pformat(accoffsets) syscomp.set_sysentry({u'mailacc_offsets': unicode(accoffsets)}, byuser=byuser)
def mailoffset(self, account, byuser=None): """Use `system-entries` field `mailacc_offsets` and remember the `offset` from which to fetch mails for `account`""" from zeta.config.environment import syscomp accoffsets = eval(syscomp.get_sysentry(u'mailacc_offsets', '{}')) if account in accoffsets: offset = accoffsets[account] else: offset = MAIL_STARTCOUNT self.updateoffset(account, offset, byuser=byuser) return offset
def tagcloud( self, environ ) : """Tag cloud""" from zeta.config.environment import syscomp, tagcomp c.rclose = h.ZResp() # Setup context for page generation c.specialtags = h.parse_csv( syscomp.get_sysentry( 'specialtags' )) c.tagpercentile = tagcomp.tagpercentile c.title = 'TagCloud' # Html page generation c.rclose.append(render( '/derived/tag/tagcloud.html' )) return c.rclose
def replogprocess( self, environ ) : r""" ==== Process repository logs Fetch repository logs, interpret the log message and update the database. > [<PRE paster request <.ini file> /pasteradmin/replogprocess \ [ id=<repid> ] [ project=<projectname> ] [ name=<rep-name> ] >] where, : id :: VCS id. : project :: Optional projectname : name :: Optional repository name, which will be confirmed with //id// """ from zeta.config.environment import vcscomp, syscomp args = cmd_parse_request() vcsid = args.get( 'id', None ) project = args.get( 'project', None ) name = args.get( 'name', None ) vcs = vcsid and vcscomp.get_vcs( int(vcsid) ) namechk = name and vcs.name == name or True # Fetch the revision number from which messages had to be processed d_offs = syscomp.get_sysentry( 'replogs', None ) d_offs = {} if d_offs == None else eval(d_offs) replogs = [] if vcs and namechk : print "Processing repository logs for %s" % vcs.name print "---------------------------------" print "vcs-id : %s" % vcs.id print "vcs-name : %s" % vcs.name print "vcs-type : %s" % vcs.type.vcs_typename print "project : %s" % vcs.project.projectname fromrev = d_offs.get( vcs.id, 1 ) vrep = va.open_repository( vcs ) replogs = vrep.logs( vcs.rooturl, revstart=fromrev ) for r in replogs : ctxt = parse( r[0] ) if isinstance( ctxt, Context ) : ctxt.commit( config, u'admin' ) print "%s," % r[1] if replogs : d_offs[ vcs.id ] = replogs[-1][1] print "\nProcessed from %s to %s\n" % (replogs[0][1], replogs[-1][1])
def check(self, app, environ, start_response): from zeta.lib.helpers import fromconfig from zeta.config.environment import userscomp, syscomp authusername = environ.get('REMOTE_USER', u'anonymous') # If and when strict authentication strict = self.strict or syscomp.get_sysentry('strictauth') if (authusername == 'anonymous') and (strict in ['True', 'true']): raise NotAuthenticatedError('Please login or Register yourself') status = pms_root.check(['SITE_ADMIN'], context=lambda: [authusername]) if status == False: raise NotAuthorizedError('You are not site administrator') return app(environ, start_response)
def check(self, app, environ, start_response): from zeta.lib.helpers import fromconfig from zeta.config.environment import userscomp, syscomp authusername = environ.get('REMOTE_USER', u'anonymous') # If and when strict authentication strict = self.strict or syscomp.get_sysentry('strictauth') if (authusername == 'anonymous') and (strict in ['True', 'true']): raise NotAuthenticatedError('Please login or Register yourself') # Valid user if not _currentuser() and not userscomp.user_exists(authusername): raise NotAuthorizedError( 'You are allowed to access this resource.') return app(environ, start_response)
def upgradeenv( self, environ ) : r""" ==== Upgrade environment directory When ever a deployed version of application is upgraded with the new version, environment directory //might// get outdated. To bring the environment in consistence with application, use this command. > [<PRE paster request <.ini file> /pasteradmin/upgradeenv >] """ import zeta.lib.upgradeenv from zeta.config.environment import syscomp appver_db = syscomp.get_sysentry( u'product_version' ) defenv = join( pkg_path, 'defenv' ) zeta.lib.upgradeenv.upgradeenv( appver_db, defenv, config['zeta.envpath'] ) syscomp.set_sysentry( { u'product_version' : unicode(zetaversion) }, byuser=u'admin' )
def check(self, app, environ, start_response): from zeta.lib.helpers import fromconfig from zeta.config.environment import userscomp, syscomp authusername = environ.get('REMOTE_USER', u'anonymous') # If and when strict authentication strict = self.strict or syscomp.get_sysentry('strictauth') if (authusername == 'anonymous') and (strict in ['True', 'true']): raise NotAuthenticatedError('Please login or Register yourself') if self.project: # This block is only used for testing. p = self.project context = [(p.projectname, authusername)] else: context = None # Check permissions status = pms_root.check(['PMS_PROJECT_ADMIN'], context=context) if status == False: raise NotAuthorizedError('You are not the project administrator') return app(environ, start_response)
def __before__( self, environ=None ) : """Called before calling any actions under this controller""" from zeta.config.environment import syscomp, userscomp # Collect the query values into 'context' c.username = request.params.get( 'username', None ) c.password = request.params.get( 'password', None ) # setup Environment, since we are not calling standard # self.beforecontrollers() environ = request.environ c.sysentries = syscomp.get_sysentry() # Initialize Permission Mapping System. permmod.pms_root = permmod.init_pms( ctxt=c.sysentries ) # Authenticate user, `anonymous` users cannot use XMLRPC user = userscomp.get_user( unicode(c.username) ) if user and user.password == c.password : c.authuser = user c.authusername = user.username else : c.authuser = None c.authusername = ''
def system( self ) : """Get the system table entries""" from zeta.config.environment import syscomp return (True, syscomp.get_sysentry(), '')