Fix for #1530 (Handle improper migrated database with config_mature_content_tags NULL instead of "")

This commit is contained in:
Ozzie Isaacs 2020-07-20 20:28:10 +02:00
parent 450411a732
commit 93a0217d5f
2 changed files with 17 additions and 7 deletions

View File

@ -102,7 +102,6 @@ class _Settings(_Base):
config_kobo_proxy = Column(Boolean, default=False) config_kobo_proxy = Column(Boolean, default=False)
config_ldap_provider_url = Column(String, default='example.org') config_ldap_provider_url = Column(String, default='example.org')
config_ldap_port = Column(SmallInteger, default=389) config_ldap_port = Column(SmallInteger, default=389)
config_ldap_authentication = Column(SmallInteger, default=constants.LDAP_AUTH_SIMPLE) config_ldap_authentication = Column(SmallInteger, default=constants.LDAP_AUTH_SIMPLE)
@ -215,8 +214,13 @@ class _ConfigSQL(object):
return self.show_element_new_user(constants.DETAIL_RANDOM) return self.show_element_new_user(constants.DETAIL_RANDOM)
def list_denied_tags(self): def list_denied_tags(self):
mct = self.config_denied_tags.split(",") try:
return [t.strip() for t in mct] mct = self.config_denied_tags.split(",")
return [t.strip() for t in mct]
except AttributeError:
# Fix for improper migrated database with config_mature_content_tags NULL instead of ""
self.config_denied_tags = ""
return ['']
def list_allowed_tags(self): def list_allowed_tags(self):
mct = self.config_allowed_tags.split(",") mct = self.config_allowed_tags.split(",")

View File

@ -176,8 +176,14 @@ class UserBase:
return self.check_visibility(constants.DETAIL_RANDOM) return self.check_visibility(constants.DETAIL_RANDOM)
def list_denied_tags(self): def list_denied_tags(self):
mct = self.denied_tags.split(",") try:
return [t.strip() for t in mct] mct = self.denied_tags.split(",")
return [t.strip() for t in mct]
except AttributeError:
# Fix for improper migrated database with config_mature_content_tags NULL instead of ""
self.denied_tags=""
return ['']
def list_allowed_tags(self): def list_allowed_tags(self):
mct = self.allowed_tags.split(",") mct = self.allowed_tags.split(",")
@ -563,8 +569,8 @@ def migrate_Database(session):
conn = engine.connect() conn = engine.connect()
conn.execute("ALTER TABLE user ADD column `denied_tags` String DEFAULT ''") conn.execute("ALTER TABLE user ADD column `denied_tags` String DEFAULT ''")
conn.execute("ALTER TABLE user ADD column `allowed_tags` String DEFAULT ''") conn.execute("ALTER TABLE user ADD column `allowed_tags` String DEFAULT ''")
conn.execute("ALTER TABLE user ADD column `denied_column_value` DEFAULT ''") conn.execute("ALTER TABLE user ADD column `denied_column_value` String DEFAULT ''")
conn.execute("ALTER TABLE user ADD column `allowed_column_value` DEFAULT ''") conn.execute("ALTER TABLE user ADD column `allowed_column_value` String DEFAULT ''")
session.commit() session.commit()
try: try:
session.query(exists().where(User.series_view)).scalar() session.query(exists().where(User.series_view)).scalar()