mirror of
https://github.com/Mailu/Mailu.git
synced 2024-12-14 10:53:30 +02:00
Store the quota status in database
This commit is contained in:
parent
2b2ab864d1
commit
76617a3c97
@ -1,11 +1,11 @@
|
||||
from mailu import app, db, dkim, login_manager, quota
|
||||
from mailu import app, db, dkim, login_manager
|
||||
|
||||
from sqlalchemy.ext import declarative
|
||||
from passlib import context, hash
|
||||
from datetime import datetime, date
|
||||
from email.mime import text
|
||||
|
||||
|
||||
import sqlalchemy
|
||||
import re
|
||||
import time
|
||||
import os
|
||||
@ -235,6 +235,7 @@ class User(Base, Email):
|
||||
backref=db.backref('users', cascade='all, delete-orphan'))
|
||||
password = db.Column(db.String(255), nullable=False)
|
||||
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)
|
||||
|
||||
@ -266,8 +267,14 @@ class User(Base, Email):
|
||||
return self.email
|
||||
|
||||
@property
|
||||
def quota_bytes_used(self):
|
||||
return quota.get(self.email + "/quota/storage") or 0
|
||||
def destination(self):
|
||||
if self.foward_enabled:
|
||||
result = self.self.forward_destination
|
||||
if self.forward_keep:
|
||||
result += ',' + self.email
|
||||
return result
|
||||
else:
|
||||
return self.email
|
||||
|
||||
scheme_dict = {'SHA512-CRYPT': "sha512_crypt",
|
||||
'SHA256-CRYPT': "sha256_crypt",
|
||||
@ -329,6 +336,17 @@ class Alias(Base, Email):
|
||||
wildcard = db.Column(db.Boolean(), nullable=False, default=False)
|
||||
destination = db.Column(CommaSeparatedList, nullable=False, default=[])
|
||||
|
||||
@classmethod
|
||||
def resolve(cls, localpart, domain_name):
|
||||
return cls.query.filter(
|
||||
sqlalchemy._and(cls.domain_name == domain_name,
|
||||
sqlalchemy._or(
|
||||
cls.localpart == localpart,
|
||||
cls.wildcard.like(localpart)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Token(Base):
|
||||
""" A token is an application password for a given user.
|
||||
|
28
core/admin/migrations/versions/25fd6c7bcb4a_.py
Normal file
28
core/admin/migrations/versions/25fd6c7bcb4a_.py
Normal file
@ -0,0 +1,28 @@
|
||||
""" Add a column for used quota
|
||||
|
||||
Revision ID: 25fd6c7bcb4a
|
||||
Revises: 049fed905da7
|
||||
Create Date: 2018-07-25 21:56:09.729153
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '25fd6c7bcb4a'
|
||||
down_revision = '049fed905da7'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table('user') as batch:
|
||||
batch.add_column(sa.Column('quota_bytes_used', sa.Integer(), nullable=False, server_default='0'))
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table('user') as batch:
|
||||
batch.drop_column('user', 'quota_bytes_used')
|
Loading…
Reference in New Issue
Block a user