Skip to content

Commit cb9aa4e

Browse files
committed
Add flags to allow to restrict DB modifications.
1 parent 2730ac3 commit cb9aa4e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

roundup/backends/rdbms_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ def update_class(self, spec, old_spec, force=0):
513513
# no changes
514514
return 0
515515

516+
if not self.config.RDBMS_ALLOW_ALTER:
517+
raise DatabaseError(_('ALTER operation disallowed: %r -> %r.'%(old_spec, new_spec)))
518+
516519
logger = logging.getLogger('roundup.hyperdb')
517520
logger.info('update_class %s'%spec.classname)
518521

@@ -737,6 +740,10 @@ def drop_multilink_table_indexes(self, classname, ml):
737740
def create_class(self, spec):
738741
""" Create a database table according to the given spec.
739742
"""
743+
744+
if not self.config.RDBMS_ALLOW_CREATE:
745+
raise DatabaseError(_('CREATE operation disallowed: "%s".'%spec.classname))
746+
740747
cols, mls = self.create_class_table(spec)
741748
self.create_journal_table(spec)
742749

@@ -749,6 +756,10 @@ def drop_class(self, cn, spec):
749756
750757
Drop the journal and multilink tables too.
751758
"""
759+
760+
if not self.config.RDBMS_ALLOW_DROP:
761+
raise DatabaseError(_('DROP operation disallowed: "%s".'%cn))
762+
752763
properties = spec[1]
753764
# figure the multilinks
754765
mls = []

roundup/configuration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ def str2value(self, value):
610610
"Only used in SQLite connections."),
611611
(IntegerNumberOption, 'cache_size', '100',
612612
"Size of the node cache (in elements)"),
613+
(BooleanOption, "allow_create", "yes",
614+
"Setting this option to 'no' protects the database against table creations."),
615+
(BooleanOption, "allow_alter", "yes",
616+
"Setting this option to 'no' protects the database against table alterations."),
617+
(BooleanOption, "allow_drop", "yes",
618+
"Setting this option to 'no' protects the database against table drops."),
613619
(NullableOption, 'template', '',
614620
"Name of the PostgreSQL template for database creation.\n"
615621
"For database creation the template used has to match\n"

0 commit comments

Comments
 (0)