From 66df7a31b0572324600bfd3e43ab0c0941aa38b0 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Sun, 13 Jan 2019 10:17:38 +0100 Subject: [PATCH 1/4] Unify and coerce booleans from env used in admin At some places, the string that DOMAIN_REGISTRATION is got used like a boolean (an easy misassumption to make while in python and dealing with the config dict), making `DOMAIN_REGISTRATION=False` act as a truthy value. To stop such future problems from happening, coerce environment config strings to real bools. closes #830 --- CHANGELOG.md | 1 + core/admin/mailu/configuration.py | 14 +++++++++++--- core/admin/mailu/manage.py | 2 +- core/admin/mailu/models.py | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07b5b164..2b068547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ v1.6.0 - unreleased - Bug: Don't recursivly chown on mailboxes ([#776](https://github.com/Mailu/Mailu/issues/776)) - Bug: Fix forced password input for user edit ([#745](https://github.com/Mailu/Mailu/issues/745)) - Bug: Fetched accounts: Password field is of type "text" ([#789](https://github.com/Mailu/Mailu/issues/789)) +- Bug: DOMAIN_REGISTRATION=False in .env was not treated correctly ([#830](https://github.com/Mailu/Mailu/issues/830)) v1.5.1 - 2017-11-21 ------------------- diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py index 95004017..a8cd3e25 100644 --- a/core/admin/mailu/configuration.py +++ b/core/admin/mailu/configuration.py @@ -30,11 +30,11 @@ DEFAULT_CONFIG = { 'POSTMASTER': 'postmaster', 'TLS_FLAVOR': 'cert', 'AUTH_RATELIMIT': '10/minute;1000/hour', - 'DISABLE_STATISTICS': 'False', + 'DISABLE_STATISTICS': False, # Mail settings 'DMARC_RUA': None, 'DMARC_RUF': None, - 'WELCOME': 'False', + 'WELCOME': False, 'WELCOME_SUBJECT': 'Dummy welcome topic', 'WELCOME_BODY': 'Dummy welcome body', 'DKIM_SELECTOR': 'dkim', @@ -74,13 +74,21 @@ class ConfigManager(dict): def __init__(self): self.config = dict() + def __coerce_value(self, value): + if isinstance(value, str) and value.lower() in ('true','yes'): + return True + elif isinstance(value, str) and value.lower() in ('false', 'no'): + return False + return value + def init_app(self, app): self.config.update(app.config) # get environment variables self.config.update({ - key: os.environ.get(key, value) + key: self.__coerce_value(os.environ.get(key, value)) for key, value in DEFAULT_CONFIG.items() }) + # automatically set the sqlalchemy string if self.config['DB_FLAVOR']: template = self.DB_TEMPLATES[self.config['DB_FLAVOR']] diff --git a/core/admin/mailu/manage.py b/core/admin/mailu/manage.py index 4846c2d6..e11644e7 100644 --- a/core/admin/mailu/manage.py +++ b/core/admin/mailu/manage.py @@ -31,7 +31,7 @@ def advertise(): instance_id = str(uuid.uuid4()) with open(app.config["INSTANCE_ID_PATH"], "w") as handle: handle.write(instance_id) - if app.config["DISABLE_STATISTICS"].lower() != "true": + if not app.config["DISABLE_STATISTICS"]: try: socket.gethostbyname(app.config["STATS_ENDPOINT"].format(instance_id)) except: diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 37823f02..15685abd 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -410,7 +410,7 @@ class User(Base, Email): return emails def send_welcome(self): - if app.config["WELCOME"].lower() == "true": + if app.config["WELCOME"]: self.sendmail(app.config["WELCOME_SUBJECT"], app.config["WELCOME_BODY"]) From 686db1f33fa22aa60822c8f835221798756a3e96 Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Sun, 13 Jan 2019 11:22:45 +0100 Subject: [PATCH 2/4] Add reminder for users not to forget POSTMASTER account or alias --- docs/compose/setup.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/compose/setup.rst b/docs/compose/setup.rst index 942a368e..3ff1f678 100644 --- a/docs/compose/setup.rst +++ b/docs/compose/setup.rst @@ -154,3 +154,5 @@ Finally, you must create the initial admin user account: docker-compose exec admin flask mailu admin me example.net password This will create a user named ``me@example.net`` with password ``password`` and administration privileges. Connect to the Web admin interface and change the password to a strong one. + + .. note:: It is vitally important that either a user with the same email as ``POSTMASTER`` in your ``.env`` exists, or you remember to create an alias with this name after you log in. All kinds of strange errors will occur as a result of not doing so! From 11d6d383280aec93590c1eb35d7c87a53374f185 Mon Sep 17 00:00:00 2001 From: hoellen Date: Tue, 15 Jan 2019 10:20:57 +0100 Subject: [PATCH 3/4] Revert "Change quota columns type to BigInteger " --- core/admin/mailu/models.py | 6 +++--- core/admin/migrations/versions/2335c80a6bc3_.py | 2 +- core/admin/migrations/versions/25fd6c7bcb4a_.py | 2 +- core/admin/migrations/versions/ff0417f4318f_.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 4168b606..37823f02 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -131,7 +131,7 @@ class Domain(Base): backref=db.backref('manager_of'), lazy='dynamic') max_users = db.Column(db.Integer, nullable=False, default=-1) max_aliases = db.Column(db.Integer, nullable=False, default=-1) - max_quota_bytes = db.Column(db.BigInteger(), nullable=False, default=0) + max_quota_bytes = db.Column(db.Integer(), nullable=False, default=0) signup_enabled = db.Column(db.Boolean(), nullable=False, default=False) @property @@ -307,8 +307,8 @@ class User(Base, Email): domain = db.relationship(Domain, backref=db.backref('users', cascade='all, delete-orphan')) password = db.Column(db.String(255), nullable=False) - quota_bytes = db.Column(db.BigInteger(), nullable=False, default=10**9) - quota_bytes_used = db.Column(db.BigInteger(), nullable=False, default=0) + quota_bytes = db.Column(db.Integer(), nullable=False, default=10**9) + quota_bytes_used = db.Column(db.Integer(), nullable=False, default=0) global_admin = db.Column(db.Boolean(), nullable=False, default=False) enabled = db.Column(db.Boolean(), nullable=False, default=True) diff --git a/core/admin/migrations/versions/2335c80a6bc3_.py b/core/admin/migrations/versions/2335c80a6bc3_.py index 43d03547..ac5c1e83 100644 --- a/core/admin/migrations/versions/2335c80a6bc3_.py +++ b/core/admin/migrations/versions/2335c80a6bc3_.py @@ -15,7 +15,7 @@ import sqlalchemy as sa def upgrade(): - op.add_column('domain', sa.Column('max_quota_bytes', sa.BigInteger(), nullable=False, server_default='0')) + op.add_column('domain', sa.Column('max_quota_bytes', sa.Integer(), nullable=False, server_default='0')) def downgrade(): diff --git a/core/admin/migrations/versions/25fd6c7bcb4a_.py b/core/admin/migrations/versions/25fd6c7bcb4a_.py index 6e89d2c3..cf9a0fc7 100644 --- a/core/admin/migrations/versions/25fd6c7bcb4a_.py +++ b/core/admin/migrations/versions/25fd6c7bcb4a_.py @@ -20,7 +20,7 @@ import sqlalchemy as sa def upgrade(): with op.batch_alter_table('user') as batch: - batch.add_column(sa.Column('quota_bytes_used', sa.BigInteger(), nullable=False, server_default='0')) + batch.add_column(sa.Column('quota_bytes_used', sa.Integer(), nullable=False, server_default='0')) def downgrade(): diff --git a/core/admin/migrations/versions/ff0417f4318f_.py b/core/admin/migrations/versions/ff0417f4318f_.py index 99411087..7c92f241 100644 --- a/core/admin/migrations/versions/ff0417f4318f_.py +++ b/core/admin/migrations/versions/ff0417f4318f_.py @@ -41,7 +41,7 @@ def upgrade(): sa.Column('comment', sa.String(length=255), nullable=True), sa.Column('localpart', sa.String(length=80), nullable=False), sa.Column('password', sa.String(length=255), nullable=False), - sa.Column('quota_bytes', sa.BigInteger(), nullable=False), + sa.Column('quota_bytes', sa.Integer(), nullable=False), sa.Column('global_admin', sa.Boolean(), nullable=False), sa.Column('enable_imap', sa.Boolean(), nullable=False), sa.Column('enable_pop', sa.Boolean(), nullable=False), From 2342f64270bd9c90d461de98cf8b6e4b610e71a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Tue, 15 Jan 2019 14:33:29 +0200 Subject: [PATCH 4/4] Delete .mergify.yml --- .mergify.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .mergify.yml diff --git a/.mergify.yml b/.mergify.yml deleted file mode 100644 index 927bfc3e..00000000 --- a/.mergify.yml +++ /dev/null @@ -1,23 +0,0 @@ -pull_request_rules: - - name: Successful travis and 2 approved reviews - conditions: - - status-success=continuous-integration/travis-ci/pr - - label!=["status"/wip","status/blocked"] - - "#approved-reviews-by>=2" - actions: - merge: - method: merge - dismiss_reviews: - approved: true - - - name: Trusted author, successful travis and 1 approved review - conditions: - - author~=(kaiyou|muhlemmer|mildred|HorayNarea|adi90x|hoellen|ofthesun9) - - status-success=continuous-integration/travis-ci/pr - - label!=["status"/wip","status/blocked","review/need2"] - - "#approved-reviews-by>=1" - actions: - merge: - method: merge - dismiss_reviews: - approved: true