Code

Add flags to allow to restrict DB modifications.
authorstefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 29 Mar 2011 20:13:53 +0000 (20:13 +0000)
committerstefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 29 Mar 2011 20:13:53 +0000 (20:13 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4583 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/backends/rdbms_common.py
roundup/configuration.py

index eb1b7c9a33e777053775b656a1c759a54ba25be2..b37f164dd42bd67a3fd2f03d247dc6a1d5419ab0 100644 (file)
@@ -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 = []
index b145e96ecc1d77ba77963ed80496786348174496..8b862627d1d9f5a84192c11b9689f78a9013bc21 100644 (file)
@@ -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"