mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 00:03:03 +08:00
Merge pull request #811 from cquintana92/feature/ignore-or-reject-for-blocked-contacts
Allow to configure ignore or reject response for blocked contacts
This commit is contained in:
commit
7d008228e3
5 changed files with 98 additions and 2 deletions
|
@ -28,6 +28,7 @@ from app.email_utils import (
|
|||
)
|
||||
from app.log import LOG
|
||||
from app.models import (
|
||||
BlockBehaviourEnum,
|
||||
PlanEnum,
|
||||
File,
|
||||
ResetPasswordCode,
|
||||
|
@ -303,7 +304,17 @@ def setting():
|
|||
Session.commit()
|
||||
flash("Your preference has been updated", "success")
|
||||
return redirect(url_for("dashboard.setting"))
|
||||
|
||||
elif request.form.get("form-name") == "change-blocked-behaviour":
|
||||
choose = request.form.get("blocked-behaviour")
|
||||
if choose == str(BlockBehaviourEnum.return_2xx.value):
|
||||
current_user.block_behaviour = BlockBehaviourEnum.return_2xx.name
|
||||
elif choose == str(BlockBehaviourEnum.return_5xx.value):
|
||||
current_user.block_behaviour = BlockBehaviourEnum.return_5xx.name
|
||||
else:
|
||||
flash("There was an error. Please try again", "warning")
|
||||
return redirect(url_for("dashboard.setting"))
|
||||
Session.commit()
|
||||
flash("Your preference has been updated", "success")
|
||||
elif request.form.get("form-name") == "export-data":
|
||||
return redirect(url_for("api.export_data"))
|
||||
elif request.form.get("form-name") == "export-alias":
|
||||
|
@ -318,6 +329,7 @@ def setting():
|
|||
form=form,
|
||||
PlanEnum=PlanEnum,
|
||||
SenderFormatEnum=SenderFormatEnum,
|
||||
BlockBehaviourEnum=BlockBehaviourEnum,
|
||||
promo_form=promo_form,
|
||||
change_email_form=change_email_form,
|
||||
pending_email=pending_email,
|
||||
|
|
|
@ -221,6 +221,11 @@ class AliasSuffixEnum(EnumE):
|
|||
random_string = 1 # Completely random string
|
||||
|
||||
|
||||
class BlockBehaviourEnum(EnumE):
|
||||
return_2xx = 0
|
||||
return_5xx = 1
|
||||
|
||||
|
||||
class Hibp(Base, ModelMixin):
|
||||
__tablename__ = "hibp"
|
||||
name = sa.Column(sa.String(), nullable=False, unique=True, index=True)
|
||||
|
@ -438,6 +443,13 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
|
|||
# in minutes
|
||||
phone_quota = sa.Column(sa.Integer, nullable=True)
|
||||
|
||||
# Status code to return if is blocked
|
||||
block_behaviour = sa.Column(
|
||||
sa.Enum(BlockBehaviourEnum),
|
||||
nullable=False,
|
||||
server_default=BlockBehaviourEnum.return_2xx.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def directory_quota(self):
|
||||
return min(
|
||||
|
|
|
@ -140,6 +140,7 @@ from app.log import LOG, set_message_id
|
|||
from app.models import (
|
||||
Alias,
|
||||
Contact,
|
||||
BlockBehaviourEnum,
|
||||
EmailLog,
|
||||
User,
|
||||
RefusedEmail,
|
||||
|
@ -607,8 +608,13 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str
|
|||
alias_id=contact.alias_id,
|
||||
commit=True,
|
||||
)
|
||||
|
||||
res_status = status.E200
|
||||
if user.block_behaviour == BlockBehaviourEnum.return_5xx:
|
||||
res_status = status.E502
|
||||
|
||||
# do not return 5** to allow user to receive emails later when alias is enabled or contact is unblocked
|
||||
return [(True, status.E200)]
|
||||
return [(True, res_status)]
|
||||
|
||||
ret = []
|
||||
mailboxes = alias.mailboxes
|
||||
|
|
38
migrations/versions/2022_021812_9282e982bc05_.py
Normal file
38
migrations/versions/2022_021812_9282e982bc05_.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
"""Add block_behaviour setting for user
|
||||
|
||||
Revision ID: 9282e982bc05
|
||||
Revises: 07b870d7cc86
|
||||
Create Date: 2022-02-18 12:37:55.707424
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '9282e982bc05'
|
||||
down_revision = '07b870d7cc86'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def __create_enum() -> postgresql.ENUM:
|
||||
return postgresql.ENUM('return_2xx', 'return_5xx', name='block_behaviour_enum')
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
block_behaviour_enum = __create_enum()
|
||||
block_behaviour_enum.create(op.get_bind())
|
||||
|
||||
op.add_column('users', sa.Column('block_behaviour', block_behaviour_enum, nullable=False, default='return_2xx', server_default='return_2xx'))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('users', 'block_behaviour')
|
||||
|
||||
block_behaviour_enum = __create_enum()
|
||||
block_behaviour_enum.drop(op.get_bind())
|
||||
# ### end Alembic commands ###
|
|
@ -490,6 +490,34 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" id="blocked-behaviour">
|
||||
<div class="card-body">
|
||||
<div class="card-title">Blocked contact behaviour</div>
|
||||
<div class="mb-3">
|
||||
When an email is sent to one of your blocked contacts you can decide what response they should see. <br>
|
||||
If you select "Ignore", they will see the message as delivered, but we won't actually forward it to you. <br>
|
||||
If you select "Reject", we will tell them that the alias they have does not exist.
|
||||
</div>
|
||||
<form method="post" action="#blocked-behaviour" class="form-inline">
|
||||
<input type="hidden" name="form-name" value="change-blocked-behaviour">
|
||||
|
||||
<select class="form-control mr-sm-2" name="blocked-behaviour">
|
||||
<option value="{{ BlockBehaviourEnum.return_2xx.value }}"
|
||||
{% if current_user.block_behaviour.value == BlockBehaviourEnum.return_2xx.value %} selected="selected" {% endif %}>
|
||||
Ignore (the sender will see the email as delivered, but you won't receive anything).
|
||||
</option>
|
||||
<option value="{{ BlockBehaviourEnum.return_5xx.value }}"
|
||||
{% if current_user.block_behaviour.value == BlockBehaviourEnum.return_5xx.value %} selected="selected" {% endif %}>
|
||||
Reject (the sender will be told that your alias does not exist).
|
||||
</option>
|
||||
|
||||
</select>
|
||||
|
||||
<button class="btn btn-outline-primary">Update</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="card-title">Alias Import</div>
|
||||
|
|
Loading…
Reference in a new issue