From 66e9be8c7ade45e05ee43ca5df8d7e8ce5bd6947 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Wed, 22 Aug 2018 17:57:12 +0700 Subject: [PATCH] Update .travis.yml to use mysql for db. Fix RECORDS_ALLOW_EDIT config key --- .travis.yml | 12 ++++++++---- app/__init__.py | 2 +- app/models.py | 6 +++--- config_template.py | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4adf1e2..422faa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,12 @@ language: python python: - "3.5.2" before_install: - - 'sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg' - - 'echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list' - - 'travis_retry sudo apt-get update' - - 'travis_retry sudo apt-get install python3-dev libxml2-dev libxmlsec1-dev yarn' + - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg + - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + - travis_retry sudo apt-get update + - travis_retry sudo apt-get install python3-dev libxml2-dev libxmlsec1-dev yarn + - mysql -e 'CREATE DATABASE pda'; + - mysql -e "GRANT ALL PRIVILEGES ON pda.* to pda@'%' IDENTIFIED BY 'changeme'"; install: - pip install -r requirements.txt before_script: @@ -18,3 +20,5 @@ script: - sh run_travis.sh cache: yarn: true +services: + - mysql \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index 0a462b6..37c25ae 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -40,5 +40,5 @@ from app import models try: from app import views -except OperationalError: +except: logging.error("You have not initialized the DB yet or DB migration is running...") diff --git a/app/models.py b/app/models.py index 9878168..9ac98da 100644 --- a/app/models.py +++ b/app/models.py @@ -1372,7 +1372,7 @@ class Record(object): list_deleted_records = [x for x in list_current_records if x not in list_new_records] # convert back to list of hash - deleted_records = [x for x in current_records if [x['name'],x['type']] in list_deleted_records and (x['type'] in app.config['RECORDS_ALLOW_EDIT'] and x['type'] != 'SOA')] + deleted_records = [x for x in current_records if [x['name'],x['type']] in list_deleted_records and (x['type'] in Setting().get_records_allow_to_edit() and x['type'] != 'SOA')] # return a tuple return deleted_records, new_records @@ -1612,13 +1612,13 @@ class Record(object): """ Check if record is allowed to edit """ - return self.type in app.config['RECORDS_ALLOW_EDIT'] + return self.type in Setting().get_records_allow_to_edit() def is_allowed_delete(self): """ Check if record is allowed to removed """ - return (self.type in app.config['RECORDS_ALLOW_EDIT'] and self.type != 'SOA') + return (self.type in Setting().get_records_allow_to_edit() and self.type != 'SOA') def exists(self, domain): """ diff --git a/config_template.py b/config_template.py index 7ed3d60..1a1c1f8 100644 --- a/config_template.py +++ b/config_template.py @@ -26,10 +26,10 @@ SQLA_DB_NAME = 'pda' SQLALCHEMY_TRACK_MODIFICATIONS = True # DATBASE - MySQL -#SQLALCHEMY_DATABASE_URI = 'mysql://'+SQLA_DB_USER+':'+SQLA_DB_PASSWORD+'@'+SQLA_DB_HOST+'/'+SQLA_DB_NAME +SQLALCHEMY_DATABASE_URI = 'mysql://'+SQLA_DB_USER+':'+SQLA_DB_PASSWORD+'@'+SQLA_DB_HOST+'/'+SQLA_DB_NAME # DATABSE - SQLite -SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'pdns.db') +# SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'pdns.db') # SAML Authnetication SAML_ENABLED = False