From: stefan Date: Tue, 29 Mar 2011 20:13:53 +0000 (+0000) Subject: Add flags to allow to restrict DB modifications. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;ds=sidebyside;h=60ea5de95086964697b78a6563750bb3e4d276c5;p=roundup.git Add flags to allow to restrict DB modifications. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4583 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index eb1b7c9..b37f164 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -513,6 +513,9 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): # no changes return 0 + if not self.config.RDBMS_ALLOW_ALTER: + raise DatabaseError(_('ALTER operation disallowed: %r -> %r.'%(old_spec, new_spec))) + logger = logging.getLogger('roundup.hyperdb') logger.info('update_class %s'%spec.classname) @@ -737,6 +740,10 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): def create_class(self, spec): """ Create a database table according to the given spec. """ + + if not self.config.RDBMS_ALLOW_CREATE: + raise DatabaseError(_('CREATE operation disallowed: "%s".'%spec.classname)) + cols, mls = self.create_class_table(spec) self.create_journal_table(spec) @@ -749,6 +756,10 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): Drop the journal and multilink tables too. """ + + if not self.config.RDBMS_ALLOW_DROP: + raise DatabaseError(_('DROP operation disallowed: "%s".'%cn)) + properties = spec[1] # figure the multilinks mls = [] diff --git a/roundup/configuration.py b/roundup/configuration.py index b145e96..8b86262 100644 --- a/roundup/configuration.py +++ b/roundup/configuration.py @@ -610,6 +610,12 @@ SETTINGS = ( "Only used in SQLite connections."), (IntegerNumberOption, 'cache_size', '100', "Size of the node cache (in elements)"), + (BooleanOption, "allow_create", "yes", + "Setting this option to 'no' protects the database against table creations."), + (BooleanOption, "allow_alter", "yes", + "Setting this option to 'no' protects the database against table alterations."), + (BooleanOption, "allow_drop", "yes", + "Setting this option to 'no' protects the database against table drops."), (NullableOption, 'template', '', "Name of the PostgreSQL template for database creation.\n" "For database creation the template used has to match\n"