mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
rename default_random_alias_public_domain_id -> default_alias_public_domain_id
This commit is contained in:
parent
e0a414212e
commit
75d1b090cd
6 changed files with 43 additions and 27 deletions
|
@ -76,8 +76,7 @@ def update_setting():
|
|||
if sl_domain.premium_only and not user.is_premium():
|
||||
return jsonify(error="You cannot use this domain"), 400
|
||||
|
||||
# make sure only default_random_alias_domain_id or default_random_alias_public_domain_id is set
|
||||
user.default_random_alias_public_domain_id = sl_domain.id
|
||||
user.default_alias_public_domain_id = sl_domain.id
|
||||
user.default_alias_custom_domain_id = None
|
||||
else:
|
||||
custom_domain = CustomDomain.get_by(domain=default_domain)
|
||||
|
@ -89,10 +88,8 @@ def update_setting():
|
|||
LOG.exception("%s cannot use domain %s", user, default_domain)
|
||||
return jsonify(error="invalid domain"), 400
|
||||
else:
|
||||
# make sure only default_random_alias_domain_id or
|
||||
# default_random_alias_public_domain_id is set
|
||||
user.default_alias_custom_domain_id = custom_domain.id
|
||||
user.default_random_alias_public_domain_id = None
|
||||
user.default_alias_public_domain_id = None
|
||||
|
||||
db.session.commit()
|
||||
return jsonify(setting_to_dict(user))
|
||||
|
|
|
@ -58,7 +58,7 @@ def available_suffixes(user: User) -> [bool, str, str]:
|
|||
suffix_info = (False, suffix, signer.sign(suffix).decode())
|
||||
|
||||
# put the default domain to top
|
||||
if user.default_random_alias_public_domain_id == domain.id:
|
||||
if user.default_alias_public_domain_id == domain.id:
|
||||
suffixes.insert(0, suffix_info)
|
||||
else:
|
||||
suffixes.append(suffix_info)
|
||||
|
@ -113,7 +113,7 @@ def available_suffixes_more_info(user: User) -> [SuffixInfo]:
|
|||
False, suffix, signer.sign(suffix).decode(), sl_domain.premium_only
|
||||
)
|
||||
# put the default domain to top
|
||||
if user.default_random_alias_public_domain_id == sl_domain.id:
|
||||
if user.default_alias_public_domain_id == sl_domain.id:
|
||||
suffixes.insert(0, suffix_info)
|
||||
else:
|
||||
suffixes.append(suffix_info)
|
||||
|
|
|
@ -207,8 +207,7 @@ def setting():
|
|||
flash("You cannot use this domain", "error")
|
||||
return redirect(url_for("dashboard.setting"))
|
||||
|
||||
# make sure only default_random_alias_domain_id or default_random_alias_public_domain_id is set
|
||||
current_user.default_random_alias_public_domain_id = sl_domain.id
|
||||
current_user.default_alias_public_domain_id = sl_domain.id
|
||||
current_user.default_alias_custom_domain_id = None
|
||||
else:
|
||||
custom_domain = CustomDomain.get_by(domain=default_domain)
|
||||
|
@ -222,16 +221,14 @@ def setting():
|
|||
"%s cannot use domain %s", current_user, default_domain
|
||||
)
|
||||
else:
|
||||
# make sure only default_random_alias_domain_id or
|
||||
# default_random_alias_public_domain_id is set
|
||||
current_user.default_alias_custom_domain_id = (
|
||||
custom_domain.id
|
||||
)
|
||||
current_user.default_random_alias_public_domain_id = None
|
||||
current_user.default_alias_public_domain_id = None
|
||||
|
||||
else:
|
||||
current_user.default_alias_custom_domain_id = None
|
||||
current_user.default_random_alias_public_domain_id = None
|
||||
current_user.default_alias_public_domain_id = None
|
||||
|
||||
db.session.commit()
|
||||
flash("Your preference has been updated", "success")
|
||||
|
|
|
@ -204,14 +204,14 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
fido_uuid = db.Column(db.String(), nullable=True, unique=True)
|
||||
|
||||
# the default domain that's used when user creates a new random alias
|
||||
# default_random_alias_domain_id XOR default_random_alias_public_domain_id
|
||||
# default_alias_custom_domain_id XOR default_alias_public_domain_id
|
||||
default_alias_custom_domain_id = db.Column(
|
||||
db.ForeignKey("custom_domain.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
default=None,
|
||||
)
|
||||
|
||||
default_random_alias_public_domain_id = db.Column(
|
||||
default_alias_public_domain_id = db.Column(
|
||||
db.ForeignKey("public_domain.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
default=None,
|
||||
|
@ -559,8 +559,8 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
|
||||
return custom_domain.domain
|
||||
|
||||
if self.default_random_alias_public_domain_id:
|
||||
sl_domain = SLDomain.get(self.default_random_alias_public_domain_id)
|
||||
if self.default_alias_public_domain_id:
|
||||
sl_domain = SLDomain.get(self.default_alias_public_domain_id)
|
||||
# sanity check
|
||||
if not sl_domain:
|
||||
LOG.exception("Problem with %s public random alias domain", self)
|
||||
|
@ -573,7 +573,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
sl_domain,
|
||||
)
|
||||
self.default_alias_custom_domain_id = None
|
||||
self.default_random_alias_public_domain_id = None
|
||||
self.default_alias_public_domain_id = None
|
||||
db.session.commit()
|
||||
return FIRST_ALIAS_DOMAIN
|
||||
|
||||
|
@ -1050,10 +1050,8 @@ class Alias(db.Model, ModelMixin):
|
|||
random_email = generate_email(
|
||||
scheme=scheme, in_hex=in_hex, alias_domain=custom_domain.domain
|
||||
)
|
||||
elif user.default_random_alias_public_domain_id:
|
||||
sl_domain: SLDomain = SLDomain.get(
|
||||
user.default_random_alias_public_domain_id
|
||||
)
|
||||
elif user.default_alias_public_domain_id:
|
||||
sl_domain: SLDomain = SLDomain.get(user.default_alias_public_domain_id)
|
||||
if sl_domain.premium_only and not user.is_premium():
|
||||
LOG.warning("%s not premium, cannot use %s", user, sl_domain)
|
||||
else:
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: rename_default_alias_public_domain_id
|
||||
Revises: f66ca777f409
|
||||
Create Date: 2020-12-31 14:11:45.429299
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'rename_default_alias_public_domain_id'
|
||||
down_revision = 'f66ca777f409'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.alter_column('users', 'default_random_alias_public_domain_id', new_column_name='default_alias_public_domain_id')
|
||||
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.alter_column('users', 'default_alias_public_domain_id', new_column_name='default_random_alias_public_domain_id')
|
|
@ -121,17 +121,15 @@ def test_available_suffixes_default_domain(flask_client):
|
|||
user = login(flask_client)
|
||||
|
||||
sl_domain = SLDomain.query.first()
|
||||
CustomDomain.create(
|
||||
user_id=user.id, domain="test.com", verified=True, commit=True
|
||||
)
|
||||
CustomDomain.create(user_id=user.id, domain="test.com", verified=True, commit=True)
|
||||
|
||||
user.default_random_alias_public_domain_id = sl_domain.id
|
||||
user.default_alias_public_domain_id = sl_domain.id
|
||||
|
||||
# first suffix is SL Domain
|
||||
first_suffix = available_suffixes(user)[0]
|
||||
assert first_suffix[1].endswith(f"@{sl_domain.domain}")
|
||||
|
||||
user.default_random_alias_public_domain_id = None
|
||||
user.default_alias_public_domain_id = None
|
||||
# first suffix is custom domain
|
||||
first_suffix = available_suffixes(user)[0]
|
||||
assert first_suffix[1] == "@test.com"
|
||||
|
|
Loading…
Reference in a new issue