mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 07:31:12 +01:00
Fix: If default domain is premium for free users do not offer it as an option (#1763)
* Fix: If default domain is premium for free users do not offer it as an option * Refactored into simpler logic --------- Co-authored-by: Adrià Casajús <adria.casajus@proton.ch>
This commit is contained in:
parent
8c7e9f7fb3
commit
a539428607
2 changed files with 27 additions and 2 deletions
|
@ -169,8 +169,11 @@ def get_alias_suffixes(
|
|||
alias_suffixes.insert(0, alias_suffix)
|
||||
|
||||
if not default_domain_found:
|
||||
sl_domain = SLDomain.get(user.default_alias_public_domain_id)
|
||||
if sl_domain and not sl_domain.hidden:
|
||||
domain_conditions = {"id": user.default_alias_public_domain_id, "hidden": False}
|
||||
if not user.is_premium():
|
||||
domain_conditions["premium_only"] = False
|
||||
sl_domain = SLDomain.get_by(**domain_conditions)
|
||||
if sl_domain:
|
||||
prefix = (
|
||||
""
|
||||
if config.DISABLE_ALIAS_SUFFIX
|
||||
|
|
|
@ -84,6 +84,28 @@ def test_get_default_domain_hidden():
|
|||
assert suffixes[0].domain != default_domain.domain
|
||||
|
||||
|
||||
def test_get_default_domain_is_premium_for_free_user():
|
||||
user = create_new_user()
|
||||
PartnerUser.create(
|
||||
partner_id=get_proton_partner().id,
|
||||
user_id=user.id,
|
||||
external_user_id=random_token(10),
|
||||
flush=True,
|
||||
)
|
||||
user.trial_end = None
|
||||
default_domain = SLDomain.filter_by(partner_id=None, premium_only=True).first()
|
||||
user.default_alias_public_domain_id = default_domain.id
|
||||
Session.flush()
|
||||
options = AliasOptions(
|
||||
show_sl_domains=False, show_partner_domains=get_proton_partner()
|
||||
)
|
||||
suffixes = get_alias_suffixes(user, alias_options=options)
|
||||
for suffix in suffixes:
|
||||
domain = SLDomain.get_by(domain=suffix.domain)
|
||||
assert not domain.premium_only
|
||||
assert suffixes[0].domain != default_domain.domain
|
||||
|
||||
|
||||
def test_suffixes_are_valid():
|
||||
user = create_new_user()
|
||||
PartnerUser.create(
|
||||
|
|
Loading…
Reference in a new issue