FEATURE: Add 'Advanced Test' for admin panel.

This commit is contained in:
Bianca Nenciu 2018-11-29 01:03:50 +02:00 committed by Régis Hanol
parent 1a4f592749
commit 56890efd7a
8 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Ember.Controller.extend({
email: null,
text: null,
elided: null,
format: null,
actions: {
run() {
this.set("loading", true);
ajax("/admin/email/advanced-test", {
type: "POST",
data: { email: this.get("email") }
})
.then(data => {
this.setProperties({
text: data.text,
elided: data.elided,
format: data.format
});
})
.catch(popupAjaxError)
.finally(() => this.set("loading", false));
}
}
});

View File

@ -31,6 +31,7 @@ export default function() {
this.route("received"); this.route("received");
this.route("rejected"); this.route("rejected");
this.route("previewDigest", { path: "/preview-digest" }); this.route("previewDigest", { path: "/preview-digest" });
this.route("advancedTest", { path: "/advanced-test" });
} }
); );

View File

@ -0,0 +1,25 @@
<p>{{i18n 'admin.email.advanced_test.desc'}}</p>
<div class='email-advanced-test'>
<label for="email">{{i18n 'admin.email.advanced_test.email'}}</label>
{{textarea name="email" value=email class="advanced-test"}}
<button class='btn' {{action "run"}}>{{i18n 'admin.email.advanced_test.run'}}</button>
</div>
{{#conditional-loading-spinner condition=loading}}
{{#if format}}
<hr/>
<div class="text">
<h3>{{i18n 'admin.email.advanced_test.text'}}</h3>
<pre>{{{text}}}</pre>
</div>
<hr/>
<div class="elided">
<h3>{{i18n 'admin.email.advanced_test.elided'}}</h3>
<pre>{{{elided}}}</pre>
</div>
{{/if}}
{{/conditional-loading-spinner}}

View File

@ -1,6 +1,7 @@
{{#admin-nav}} {{#admin-nav}}
{{nav-item route='adminEmail.index' label='admin.email.settings'}} {{nav-item route='adminEmail.index' label='admin.email.settings'}}
{{nav-item route='adminEmail.previewDigest' label='admin.email.preview_digest'}} {{nav-item route='adminEmail.previewDigest' label='admin.email.preview_digest'}}
{{nav-item route='adminEmail.advancedTest' label='admin.email.advanced_test.title'}}
{{nav-item route='adminCustomizeEmailTemplates' label='admin.email.templates'}} {{nav-item route='adminCustomizeEmailTemplates' label='admin.email.templates'}}
{{nav-item route='adminEmail.sent' label='admin.email.sent'}} {{nav-item route='adminEmail.sent' label='admin.email.sent'}}
{{nav-item route='adminEmail.skipped' label='admin.email.skipped'}} {{nav-item route='adminEmail.skipped' label='admin.email.skipped'}}

View File

@ -83,3 +83,15 @@
border-width: 1px; border-width: 1px;
} }
} }
.email-advanced-test {
.admin-controls {
display: block;
}
textarea {
width: 95%;
height: 150px;
font-family: monospace;
}
}

View File

@ -89,6 +89,19 @@ class Admin::EmailController < Admin::AdminController
render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text) render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text)
end end
def advanced_test
params.require(:email)
receiver = Email::Receiver.new(params['email'])
text, elided, format = receiver.select_body
render json: success_json.merge!(
text: text,
elided: elided,
format: format
)
end
def send_digest def send_digest
params.require(:last_seen_at) params.require(:last_seen_at)
params.require(:username) params.require(:username)

View File

@ -3413,6 +3413,13 @@ en:
settings: "Settings" settings: "Settings"
templates: "Templates" templates: "Templates"
preview_digest: "Preview Summary" preview_digest: "Preview Summary"
advanced_test:
title: "Advanced Test"
desc: "See how Discourse processes recieved emails. To be able to correctly process the email, please paste below the whole original email message."
email: "Original message"
run: "Run Test"
text: "Selected Text Body"
elided: "Elided Text"
sending_test: "Sending test Email..." sending_test: "Sending test Email..."
error: "<b>ERROR</b> - %{server_error}" error: "<b>ERROR</b> - %{server_error}"
test_error: "There was a problem sending the test email. Please double-check your mail settings, verify that your host is not blocking mail connections, and try again." test_error: "There was a problem sending the test email. Please double-check your mail settings, verify that your host is not blocking mail connections, and try again."

View File

@ -159,6 +159,8 @@ Discourse::Application.routes.draw do
get "send-digest" => "email#send_digest" get "send-digest" => "email#send_digest"
get "smtp_should_reject" get "smtp_should_reject"
post "handle_mail" post "handle_mail"
get "advanced-test"
post "advanced-test" => "email#advanced_test"
end end
end end