Full-mailbox User can change alias mailbox
This commit is contained in:
parent
a467830a23
commit
e4bb85ac87
|
@ -134,12 +134,6 @@
|
|||
|
||||
<hr class="my-2">
|
||||
|
||||
{% if alias_info.mailbox != None %}
|
||||
<div class="small-text">
|
||||
Owned by <b>{{ alias_info.mailbox.email }}</b> mailbox
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<p class="small-text">
|
||||
Created {{ gen_email.created_at | dt }}
|
||||
{% if alias_info.highlight %}
|
||||
|
@ -157,10 +151,42 @@
|
|||
</a>
|
||||
</div>
|
||||
|
||||
{% if current_user.full_mailbox and mailboxes|length > 1 %}
|
||||
<form method="post">
|
||||
<div class="small-text mt-2">Current mailbox</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control form-control-sm custom-select" name="mailbox">
|
||||
{% for mailbox in mailboxes %}
|
||||
<option value="{{ mailbox }}" {% if mailbox == alias_info.mailbox.email %} selected {% endif %}>
|
||||
{{ mailbox }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-2">
|
||||
<input type="hidden" name="form-name" value="set-mailbox">
|
||||
<input type="hidden" name="gen-email-id" value="{{ gen_email.id }}">
|
||||
|
||||
<button class="btn btn-sm btn-outline-info w-100">
|
||||
Update
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
{% elif alias_info.mailbox != None %}
|
||||
<div class="small-text">
|
||||
Owned by <b>{{ alias_info.mailbox.email }}</b> mailbox
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<form method="post">
|
||||
<div class="row mt-2">
|
||||
|
||||
<div class="col-10">
|
||||
<div class="col-lg-10">
|
||||
<textarea
|
||||
name="note"
|
||||
class="form-control"
|
||||
|
@ -168,11 +194,11 @@
|
|||
placeholder="Alias Note.">{{ gen_email.note or "" }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<div class="col-lg-2">
|
||||
<input type="hidden" name="form-name" value="set-note">
|
||||
<input type="hidden" name="gen-email-id" value="{{ gen_email.id }}">
|
||||
|
||||
<button class="btn btn-sm btn-outline-success">
|
||||
<button class="btn btn-sm btn-outline-success w-100">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -142,6 +142,31 @@ def index():
|
|||
)
|
||||
)
|
||||
|
||||
elif request.form.get("form-name") == "set-mailbox":
|
||||
gen_email_id = request.form.get("gen-email-id")
|
||||
gen_email: GenEmail = GenEmail.get(gen_email_id)
|
||||
mailbox_email = request.form.get("mailbox")
|
||||
|
||||
mailbox = Mailbox.get_by(email=mailbox_email)
|
||||
if not mailbox or mailbox.user_id != current_user.id:
|
||||
flash("Something went wrong, please retry", "warning")
|
||||
else:
|
||||
gen_email.mailbox_id = mailbox.id
|
||||
db.session.commit()
|
||||
LOG.d("Set alias %s mailbox to %s", gen_email, mailbox)
|
||||
|
||||
flash(
|
||||
f"Update mailbox for {gen_email.email} to {mailbox_email}",
|
||||
"success",
|
||||
)
|
||||
return redirect(
|
||||
url_for(
|
||||
"dashboard.index",
|
||||
highlight_gen_email_id=gen_email.id,
|
||||
query=query,
|
||||
)
|
||||
)
|
||||
|
||||
return redirect(url_for("dashboard.index", query=query))
|
||||
|
||||
client_users = (
|
||||
|
@ -153,6 +178,8 @@ def index():
|
|||
|
||||
sorted(client_users, key=lambda cu: cu.client.name)
|
||||
|
||||
mailboxes = current_user.mailboxes()
|
||||
|
||||
return render_template(
|
||||
"dashboard/index.html",
|
||||
client_users=client_users,
|
||||
|
@ -160,6 +187,7 @@ def index():
|
|||
highlight_gen_email_id=highlight_gen_email_id,
|
||||
query=query,
|
||||
AliasGeneratorEnum=AliasGeneratorEnum,
|
||||
mailboxes=mailboxes,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -162,6 +162,13 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
GenEmail.create_new(user.id, prefix="my-first-alias")
|
||||
db.session.flush()
|
||||
|
||||
# todo: uncomment when all existing users are full_mailbox
|
||||
# to run just after migrating all existing user to full mailbox
|
||||
# so new users are automatically full-mailbox
|
||||
# Mailbox.create(user_id=user.id, email=user.email, verified=True)
|
||||
# user.full_mailbox = True
|
||||
# db.session.flush()
|
||||
|
||||
# Schedule onboarding emails
|
||||
Job.create(
|
||||
name=JOB_ONBOARDING_1,
|
||||
|
@ -511,7 +518,7 @@ class GenEmail(db.Model, ModelMixin):
|
|||
mailbox = db.relationship("Mailbox")
|
||||
|
||||
@classmethod
|
||||
def create_new(cls, user_id, prefix, note=None):
|
||||
def create_new(cls, user_id, prefix, note=None, mailbox_id=None):
|
||||
if not prefix:
|
||||
raise Exception("alias prefix cannot be empty")
|
||||
|
||||
|
@ -523,7 +530,9 @@ class GenEmail(db.Model, ModelMixin):
|
|||
if not cls.get_by(email=email):
|
||||
break
|
||||
|
||||
return GenEmail.create(user_id=user_id, email=email, note=note)
|
||||
return GenEmail.create(
|
||||
user_id=user_id, email=email, note=note, mailbox_id=mailbox_id
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_new_random(
|
||||
|
|
15
server.py
15
server.py
|
@ -132,6 +132,7 @@ def fake_data():
|
|||
is_admin=True,
|
||||
otp_secret="base32secret3232",
|
||||
can_use_multiple_mailbox=True,
|
||||
full_mailbox=True,
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
|
@ -156,9 +157,13 @@ def fake_data():
|
|||
api_key = ApiKey.create(user_id=user.id, name="Firefox")
|
||||
api_key.code = "codeFF"
|
||||
|
||||
GenEmail.create_new(user.id, "e1@")
|
||||
GenEmail.create_new(user.id, "e2@")
|
||||
GenEmail.create_new(user.id, "e3@")
|
||||
m1 = Mailbox.create(user_id=user.id, email="m1@cd.ef", verified=True)
|
||||
m2 = Mailbox.create(user_id=user.id, email="m2@zt.com", verified=False)
|
||||
m3 = Mailbox.create(user_id=user.id, email="m3@cd.ef", verified=True)
|
||||
db.session.commit()
|
||||
|
||||
GenEmail.create_new(user.id, "e1@", mailbox_id=m1.id)
|
||||
GenEmail.create_new(user.id, "e2@", mailbox_id=m3.id)
|
||||
|
||||
CustomDomain.create(user_id=user.id, domain="ab.cd", verified=True)
|
||||
CustomDomain.create(
|
||||
|
@ -185,10 +190,6 @@ def fake_data():
|
|||
client2.published = True
|
||||
db.session.commit()
|
||||
|
||||
Mailbox.create(user_id=user.id, email="ab@cd.ef", verified=True)
|
||||
Mailbox.create(user_id=user.id, email="xy@zt.com", verified=False)
|
||||
db.session.commit()
|
||||
|
||||
DeletedAlias.create(user_id=user.id, email="d1@ab.cd")
|
||||
DeletedAlias.create(user_id=user.id, email="d2@ab.cd")
|
||||
db.session.commit()
|
||||
|
|
Loading…
Reference in New Issue