From bbcd4fc3550dccc6f53bc583f7d9b4d03fcdad53 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sat, 25 Apr 2020 15:21:35 +0200 Subject: [PATCH 1/5] remove "trigger-email" --- app/dashboard/templates/dashboard/index.html | 20 ++++---------------- app/dashboard/views/index.py | 14 +------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 7fdd74f6..dab6005d 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -223,9 +223,10 @@
+ class="save-mailbox btn btn-sm btn-outline-info w-100"> Update
@@ -409,19 +410,6 @@ }); }); - $(".trigger-email").on("click", function (e) { - notie.confirm({ - text: "SimpleLogin server will send an email to this alias " + - "and it will arrive to your inbox, please confirm.", - cancelCallback: () => { - // nothing to do - }, - submitCallback: () => { - $(this).closest("form").submit(); - } - }); - }); - $(".custom-switch-input").change(async function (e) { let aliasId = $(this).data("alias"); let alias = $(this).parent().find(".alias").val(); diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index c721b9fe..6f94a600 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -33,19 +33,7 @@ def index(): # User generates a new email if request.method == "POST": - if request.form.get("form-name") == "trigger-email": - alias_id = request.form.get("alias-id") - alias = Alias.get(alias_id) - - LOG.d("trigger an email to %s", alias) - email_utils.send_test_email_alias(alias.email, alias.user.name) - - flash( - f"An email sent to {alias.email} is on its way, please check your inbox/spam folder", - "success", - ) - - elif request.form.get("form-name") == "create-custom-email": + if request.form.get("form-name") == "create-custom-email": if current_user.can_create_new_alias(): return redirect(url_for("dashboard.custom_alias")) else: From fb9dc2352903a43253e45767f8ff2ccc0e8e307c Mon Sep 17 00:00:00 2001 From: Son NK Date: Sat, 25 Apr 2020 15:26:07 +0200 Subject: [PATCH 2/5] remove form POST switch-email-forwarding --- app/dashboard/templates/dashboard/index.html | 51 +++++++++----------- app/dashboard/views/index.py | 17 ------- 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index dab6005d..340cb50e 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -110,34 +110,31 @@
-
- - - -
+ +
@@ -412,7 +409,7 @@ $(".custom-switch-input").change(async function (e) { let aliasId = $(this).data("alias"); - let alias = $(this).parent().find(".alias").val(); + let alias = $(this).data("alias-email"); try { let res = await fetch(`/api/aliases/${aliasId}/toggle`, { diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 6f94a600..433e934e 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -63,23 +63,6 @@ def index(): else: flash(f"You need to upgrade your plan to create new alias.", "warning") - elif request.form.get("form-name") == "switch-email-forwarding": - alias_id = request.form.get("alias-id") - alias: Alias = Alias.get(alias_id) - - LOG.d("switch email forwarding for %s", alias) - - alias.enabled = not alias.enabled - if alias.enabled: - flash(f"Alias {alias.email} is enabled", "success") - else: - flash(f"Alias {alias.email} is disabled", "warning") - - db.session.commit() - return redirect( - url_for("dashboard.index", highlight_alias_id=alias.id, query=query) - ) - elif request.form.get("form-name") == "delete-email": alias_id = request.form.get("alias-id") alias: Alias = Alias.get(alias_id) From 1a081f87c4aa856035ec090139cc444b01e4541b Mon Sep 17 00:00:00 2001 From: Son NK Date: Sat, 25 Apr 2020 15:28:25 +0200 Subject: [PATCH 3/5] Remove "set-note" post form --- app/dashboard/templates/dashboard/index.html | 40 +++++++++----------- app/dashboard/views/index.py | 12 ------ 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 340cb50e..09fde197 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -248,29 +248,23 @@ {% endif %} -
-
- -
- -
- -
- - - - - Save - -
+
+
+
- + + +
@@ -459,7 +453,7 @@ }); if (res.ok) { - toastr.success(`Saved`); + toastr.success(`Note Saved`); } else { toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error"); // reset to the original value diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 433e934e..fce041a4 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -87,18 +87,6 @@ def index(): LOG.error("alias %s has been added before to DeletedAlias", email) db.session.rollback() - elif request.form.get("form-name") == "set-note": - alias_id = request.form.get("alias-id") - alias: Alias = Alias.get(alias_id) - note = request.form.get("note") - - alias.note = note - db.session.commit() - - flash(f"Update note for alias {alias.email}", "success") - return redirect( - url_for("dashboard.index", highlight_alias_id=alias.id, query=query) - ) elif request.form.get("form-name") == "set-mailbox": alias_id = request.form.get("alias-id") From a2666cc4fede900d9497cb7060f902317f5c6ee6 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sat, 25 Apr 2020 15:30:19 +0200 Subject: [PATCH 4/5] remove "set-mailbox" form post --- app/dashboard/templates/dashboard/index.html | 47 +++++++++----------- app/dashboard/views/index.py | 25 +---------- 2 files changed, 22 insertions(+), 50 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 09fde197..0f9344c0 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -215,33 +215,28 @@
{% if mailboxes|length > 1 %} -
-
Current mailbox
-
-
- -
- -
- - - - - Update - -
- +
Current mailbox
+
+
+
- + + + +
{% elif alias_info.mailbox != None and alias_info.mailbox.email != current_user.email %}
Owned by {{ alias_info.mailbox.email }} mailbox diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index fce041a4..ca083d62 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -87,30 +87,7 @@ def index(): LOG.error("alias %s has been added before to DeletedAlias", email) db.session.rollback() - - elif request.form.get("form-name") == "set-mailbox": - alias_id = request.form.get("alias-id") - alias: Alias = Alias.get(alias_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: - alias.mailbox_id = mailbox.id - db.session.commit() - LOG.d("Set alias %s mailbox to %s", alias, mailbox) - - flash( - f"Update mailbox for {alias.email} to {mailbox_email}", "success", - ) - return redirect( - url_for( - "dashboard.index", highlight_alias_id=alias.id, query=query, - ) - ) - - return redirect(url_for("dashboard.index", query=query)) + return redirect(url_for("dashboard.index", query=query, sort=sort)) client_users = ( ClientUser.filter_by(user_id=current_user.id) From ee7e783f2a58d5f211acba68ceae98176eeb27e0 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sat, 25 Apr 2020 15:31:20 +0200 Subject: [PATCH 5/5] keep sort param when redirecting back to index --- app/dashboard/views/index.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index ca083d62..40c981e0 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -57,7 +57,10 @@ def index(): return redirect( url_for( - "dashboard.index", highlight_alias_id=alias.id, query=query, + "dashboard.index", + highlight_alias_id=alias.id, + query=query, + sort=sort, ) ) else: @@ -69,7 +72,12 @@ def index(): if not alias: flash("Unknown error, sorry for the inconvenience", "error") return redirect( - url_for("dashboard.index", highlight_alias_id=alias.id, query=query) + url_for( + "dashboard.index", + highlight_alias_id=alias.id, + query=query, + sort=sort, + ) ) LOG.d("delete gen email %s", alias)