Skip to content

A platform for community discussion. Free, open, simple.

UX: Use DPageHeader on the Emails page (#30781)

Gary Pendergast5da6a06ce3fb
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-email-templates-edit.js b/app/assets/javascripts/admin/addon/controllers/admin-email-templates-edit.js
similarity index 92%
rename from app/assets/javascripts/admin/addon/controllers/admin-customize-email-templates-edit.js
rename to app/assets/javascripts/admin/addon/controllers/admin-email-templates-edit.js
index f326158cb45..97ec0bb0f53 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-email-templates-edit.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-email-templates-edit.js
@@ -6,11 +6,11 @@ import discourseComputed from "discourse/lib/decorators";
import { bufferedProperty } from "discourse/mixins/buffered-content";
import { i18n } from "discourse-i18n";
-export default class AdminCustomizeEmailTemplatesEditController extends Controller.extend(
+export default class AdminEmailTemplatesEditController extends Controller.extend(
bufferedProperty("emailTemplate")
) {
@service dialog;
- @controller adminCustomizeEmailTemplates;
+ @controller adminEmailTemplates;
emailTemplate = null;
saved = false;
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-email-templates.js b/app/assets/javascripts/admin/addon/controllers/admin-email-templates.js
similarity index 67%
rename from app/assets/javascripts/admin/addon/controllers/admin-customize-email-templates.js
rename to app/assets/javascripts/admin/addon/controllers/admin-email-templates.js
index b23dc51ebcd..dbf78e79aba 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-email-templates.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-email-templates.js
@@ -3,7 +3,7 @@ import { action } from "@ember/object";
import { sort } from "@ember/object/computed";
import { service } from "@ember/service";
-export default class AdminCustomizeEmailTemplatesController extends Controller {
+export default class AdminEmailTemplatesController extends Controller {
@service router;
titleSorting = ["title"];
@@ -11,6 +11,6 @@ export default class AdminCustomizeEmailTemplatesController extends Controller {
@action
onSelectTemplate(template) {
- this.router.transitionTo("adminCustomizeEmailTemplates.edit", template);
+ this.router.transitionTo("adminEmailTemplates.edit", template);
}
}
diff --git a/app/assets/javascripts/admin/addon/models/email-template.js b/app/assets/javascripts/admin/addon/models/email-template.js
index 360935f30e8..55c3ae1f06d 100644
--- a/app/assets/javascripts/admin/addon/models/email-template.js
+++ b/app/assets/javascripts/admin/addon/models/email-template.js
@@ -4,7 +4,7 @@ import RestModel from "discourse/models/rest";
export default class EmailTemplate extends RestModel {
revert() {
- return ajax(`/admin/customize/email_templates/${this.id}`, {
+ return ajax(`/admin/email/templates/${this.id}`, {
type: "DELETE",
}).then((result) =>
getProperties(result.email_template, "subject", "body", "can_revert")
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-email-templates-edit.js b/app/assets/javascripts/admin/addon/routes/admin-email-templates-edit.js
similarity index 72%
rename from app/assets/javascripts/admin/addon/routes/admin-customize-email-templates-edit.js
rename to app/assets/javascripts/admin/addon/routes/admin-email-templates-edit.js
index 523b536f776..c749ab7a349 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-email-templates-edit.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-email-templates-edit.js
@@ -1,9 +1,9 @@
import Route from "@ember/routing/route";
import { scrollTop } from "discourse/mixins/scroll-top";
-export default class AdminCustomizeEmailTemplatesEditRoute extends Route {
+export default class AdminEmailTemplatesEditRoute extends Route {
model(params) {
- const all = this.modelFor("adminCustomizeEmailTemplates");
+ const all = this.modelFor("adminEmailTemplates");
return all.findBy("id", params.id);
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-customize-email-templates.js b/app/assets/javascripts/admin/addon/routes/admin-email-templates.js
similarity index 69%
rename from app/assets/javascripts/admin/addon/routes/admin-customize-email-templates.js
rename to app/assets/javascripts/admin/addon/routes/admin-email-templates.js
index d97677bec8e..41289ff7a34 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-customize-email-templates.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-email-templates.js
@@ -2,7 +2,7 @@ import { action } from "@ember/object";
import Route from "@ember/routing/route";
import { service } from "@ember/service";
-export default class AdminCustomizeEmailTemplatesRoute extends Route {
+export default class AdminEmailTemplatesRoute extends Route {
@service router;
model() {
@@ -15,13 +15,11 @@ export default class AdminCustomizeEmailTemplatesRoute extends Route {
@action
didTransition() {
- const editController = this.controllerFor(
- "adminCustomizeEmailTemplates.edit"
- );
+ const editController = this.controllerFor("adminEmailTemplates.edit");
if (!editController.emailTemplate) {
this.router.transitionTo(
- "adminCustomizeEmailTemplates.edit",
+ "adminEmailTemplates.edit",
this.controller.get("sortedTemplates.firstObject")
);
}
diff --git a/app/assets/javascripts/admin/addon/routes/admin-route-map.js b/app/assets/javascripts/admin/addon/routes/admin-route-map.js
index 60c95bc5659..0fbf3ce3b9f 100644
--- a/app/assets/javascripts/admin/addon/routes/admin-route-map.js
+++ b/app/assets/javascripts/admin/addon/routes/admin-route-map.js
@@ -38,6 +38,13 @@ export default function () {
this.route("rejected");
this.route("previewDigest", { path: "/preview-digest" });
this.route("advancedTest", { path: "/advanced-test" });
+ this.route(
+ "adminEmailTemplates",
+ { path: "/templates", resetNamespace: true },
+ function () {
+ this.route("edit", { path: "/:id" });
+ }
+ );
}
);
@@ -80,13 +87,6 @@ export default function () {
this.route("edit", { path: "/:id" });
}
);
- this.route(
- "adminCustomizeEmailTemplates",
- { path: "/email_templates", resetNamespace: true },
- function () {
- this.route("edit", { path: "/:id" });
- }
- );
this.route("adminCustomizeRobotsTxt", {
path: "/robots",
resetNamespace: true,
diff --git a/app/assets/javascripts/admin/addon/templates/customize.hbs b/app/assets/javascripts/admin/addon/templates/customize.hbs
index f2be8dc4945..3967aa7995b 100644
--- a/app/assets/javascripts/admin/addon/templates/customize.hbs
+++ b/app/assets/javascripts/admin/addon/templates/customize.hbs
@@ -17,11 +17,6 @@
@label="admin.site_text.title"
class="admin-customize-site-text"
/>
- <NavItem
- @route="adminCustomizeEmailTemplates"
- @label="admin.customize.email_templates.title"
- class="admin-customize-email-templates"
- />
<NavItem
@route="adminCustomizeEmailStyle"
@label="admin.customize.email_style.title"
diff --git a/app/assets/javascripts/admin/addon/templates/customize-email-templates-edit.hbs b/app/assets/javascripts/admin/addon/templates/email-templates-edit.hbs
similarity index 87%
rename from app/assets/javascripts/admin/addon/templates/customize-email-templates-edit.hbs
rename to app/assets/javascripts/admin/addon/templates/email-templates-edit.hbs
index d8e7694dd11..23c5a6eed69 100644
--- a/app/assets/javascripts/admin/addon/templates/customize-email-templates-edit.hbs
+++ b/app/assets/javascripts/admin/addon/templates/email-templates-edit.hbs
@@ -1,7 +1,7 @@
<ComboBox
@value={{this.emailTemplate.id}}
- @content={{this.adminCustomizeEmailTemplates.sortedTemplates}}
- @onChange={{this.adminCustomizeEmailTemplates.onSelectTemplate}}
+ @content={{this.adminEmailTemplates.sortedTemplates}}
+ @onChange={{this.adminEmailTemplates.onSelectTemplate}}
@nameProperty="title"
/>
diff --git a/app/assets/javascripts/admin/addon/templates/customize-email-templates.hbs b/app/assets/javascripts/admin/addon/templates/email-templates.hbs
similarity index 100%
rename from app/assets/javascripts/admin/addon/templates/customize-email-templates.hbs
rename to app/assets/javascripts/admin/addon/templates/email-templates.hbs
diff --git a/app/assets/javascripts/admin/addon/templates/email.hbs b/app/assets/javascripts/admin/addon/templates/email.hbs
index 720875ceb3f..e32422ced6f 100644
--- a/app/assets/javascripts/admin/addon/templates/email.hbs
+++ b/app/assets/javascripts/admin/addon/templates/email.hbs
@@ -1,23 +1,33 @@
-<AdminNav>
- <NavItem @route="adminEmail.index" @label="admin.email.settings" />
- <NavItem
- @route="adminEmail.previewDigest"
- @label="admin.email.preview_digest"
- />
- <NavItem
- @route="adminEmail.advancedTest"
- @label="admin.email.advanced_test.title"
- />
- <NavItem
- @route="adminCustomizeEmailTemplates"
- @label="admin.email.templates"
- />
- <NavItem @route="adminEmail.sent" @label="admin.email.sent" />
- <NavItem @route="adminEmail.skipped" @label="admin.email.skipped" />
- <NavItem @route="adminEmail.bounced" @label="admin.email.bounced" />
- <NavItem @route="adminEmail.received" @label="admin.email.received" />
- <NavItem @route="adminEmail.rejected" @label="admin.email.rejected" />
-</AdminNav>
+<DPageHeader
+ @titleLabel={{i18n "admin.email.title"}}
+ @descriptionLabel={{i18n "admin.email.description"}}
+ @shouldDisplay={{true}}
+>
+ <:breadcrumbs>
+ <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
+ <DBreadcrumbsItem
+ @path="/admin/email"
+ @label={{i18n "admin.email.title"}}
+ />
+ </:breadcrumbs>
+ <:tabs>
+ <NavItem @route="adminEmail.index" @label="admin.email.settings" />
+ <NavItem
+ @route="adminEmail.previewDigest"
+ @label="admin.email.preview_digest"
+ />
+ <NavItem
+ @route="adminEmail.advancedTest"
+ @label="admin.email.advanced_test.title"
+ />
+ <NavItem @route="adminEmailTemplates" @label="admin.email.templates" />
+ <NavItem @route="adminEmail.sent" @label="admin.email.sent" />
+ <NavItem @route="adminEmail.skipped" @label="admin.email.skipped" />
+ <NavItem @route="adminEmail.bounced" @label="admin.email.bounced" />
+ <NavItem @route="adminEmail.received" @label="admin.email.received" />
+ <NavItem @route="adminEmail.rejected" @label="admin.email.rejected" />
+ </:tabs>
+</DPageHeader>
<div class="admin-container">
{{outlet}}
diff --git a/app/assets/javascripts/discourse/app/adapters/email-template.js b/app/assets/javascripts/discourse/app/adapters/email-template.js
index dba32c64737..203bbeea4ce 100644
--- a/app/assets/javascripts/discourse/app/adapters/email-template.js
+++ b/app/assets/javascripts/discourse/app/adapters/email-template.js
@@ -1,7 +1,9 @@
import RestAdapter from "discourse/adapters/rest";
export default class EmailTemplateAdapter extends RestAdapter {
- basePath() {
- return "/admin/customize/";
+ pathFor(store, type, id) {
+ return id === undefined
+ ? "/admin/email/templates"
+ : `/admin/email/templates/${id}`;
}
}
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js
index 95522804dc6..45107d29ad5 100644
--- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js
+++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-nav-map.js
@@ -162,7 +162,7 @@ export const ADMIN_NAV_MAP = [
links: [
{
name: "admin_server_setup",
- route: "adminEmail.index",
+ route: "adminEmail",
label: "admin.email_settings.sidebar_link.server_setup.title",
icon: "gear",
keywords: "admin.email_settings.sidebar_link.server_setup.keywords",
diff --git a/app/assets/stylesheets/common/admin/customize.scss b/app/assets/stylesheets/common/admin/customize.scss
index 0c976c9ddf1..479e6d2cff4 100644
--- a/app/assets/stylesheets/common/admin/customize.scss
+++ b/app/assets/stylesheets/common/admin/customize.scss
@@ -955,7 +955,7 @@
}
}
-.admin-customize-email-templates {
+.admin-email-templates {
.email-template,
.controls {
margin-top: 1em;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index e6df269021a..2f92bc409a4 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6334,7 +6334,8 @@ en:
email:
title: "Emails"
- settings: "Email Settings"
+ description: "Customize the templates used to create emails, preview summary emails that will be sent out, and view email logs."
+ settings: "Settings"
templates: "Templates"
templates_title: "Email Templates"
preview_digest: "Preview Summary"
diff --git a/config/routes.rb b/config/routes.rb
index f8480e6a819..a02f3df9be5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -194,6 +194,13 @@ Discourse::Application.routes.draw do
post "handle_mail"
get "advanced-test"
post "advanced-test" => "email#advanced_test"
+ get "templates" => "email_templates#index"
+ get "templates/(:id)" => "email_templates#show", :constraints => { id: /[0-9a-z_.]+/ }
+ delete "templates/(:id)" => "email_templates#revert",
+ :constraints => {
+ id: /[0-9a-z_.]+/,
+ }
+ put "templates/(:id)" => "email_templates#update", :constraints => { id: /[0-9a-z_.]+/ }
end
end
@@ -279,17 +286,6 @@ Discourse::Application.routes.draw do
get "reseed" => "site_texts#get_reseed_options"
post "reseed" => "site_texts#reseed"
- get "email_templates" => "email_templates#index"
- get "email_templates/(:id)" => "email_templates#show", :constraints => { id: /[0-9a-z_.]+/ }
- put "email_templates/(:id)" => "email_templates#update",
- :constraints => {
- id: /[0-9a-z_.]+/,
- }
- delete "email_templates/(:id)" => "email_templates#revert",
- :constraints => {
- id: /[0-9a-z_.]+/,
- }
-
get "robots" => "robots_txt#show"
put "robots.json" => "robots_txt#update"
delete "robots.json" => "robots_txt#reset"
diff --git a/spec/requests/admin/email_templates_controller_spec.rb b/spec/requests/admin/email_templates_controller_spec.rb
index fc52952f3b9..339772ade35 100644
--- a/spec/requests/admin/email_templates_controller_spec.rb
+++ b/spec/requests/admin/email_templates_controller_spec.rb
@@ -23,7 +23,7 @@ RSpec.describe Admin::EmailTemplatesController do
before { sign_in(admin) }
it "should work if you are an admin" do
- get "/admin/customize/email_templates.json"
+ get "/admin/email/templates.json"
expect(response.status).to eq(200)
@@ -32,7 +32,7 @@ RSpec.describe Admin::EmailTemplatesController do
end
it "returns overridden = true if subject or body has translation_overrides record" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: original_subject,
@@ -42,7 +42,7 @@ RSpec.describe Admin::EmailTemplatesController do
headers: headers
expect(response.status).to eq(200)
- get "/admin/customize/email_templates.json"
+ get "/admin/email/templates.json"
expect(response.status).to eq(200)
templates = response.parsed_body["email_templates"]
template = templates.find { |t| t["id"] == "user_notifications.admin_login" }
@@ -50,7 +50,7 @@ RSpec.describe Admin::EmailTemplatesController do
TranslationOverride.destroy_all
- get "/admin/customize/email_templates.json"
+ get "/admin/email/templates.json"
expect(response.status).to eq(200)
templates = response.parsed_body["email_templates"]
template = templates.find { |t| t["id"] == "user_notifications.admin_login" }
@@ -60,7 +60,7 @@ RSpec.describe Admin::EmailTemplatesController do
shared_examples "email templates inaccessible" do
it "denies access with a 404 response" do
- get "/admin/customize/email_templates.json"
+ get "/admin/email/templates.json"
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
@@ -89,7 +89,7 @@ RSpec.describe Admin::EmailTemplatesController do
before { sign_in(admin) }
it "returns 'not found' when an unknown email template id is used" do
- put "/admin/customize/email_templates/non_existent_template",
+ put "/admin/email/templates/non_existent_template",
params: {
email_template: {
subject: "Foo",
@@ -106,7 +106,7 @@ RSpec.describe Admin::EmailTemplatesController do
shared_examples "invalid email template" do
it "returns the right error messages" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -124,7 +124,7 @@ RSpec.describe Admin::EmailTemplatesController do
end
it "doesn't create translation overrides" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -138,7 +138,7 @@ RSpec.describe Admin::EmailTemplatesController do
end
it "doesn't create entries in the Staff Log" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -224,7 +224,7 @@ RSpec.describe Admin::EmailTemplatesController do
let(:email_body) { "The body contains [%{site_name}](%{base_url}) and %{email_token}." }
it "returns the successfully updated email template" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -249,7 +249,7 @@ RSpec.describe Admin::EmailTemplatesController do
end
it "creates translation overrides" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -263,7 +263,7 @@ RSpec.describe Admin::EmailTemplatesController do
end
it "creates entries in the Staff Log" do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -293,7 +293,7 @@ RSpec.describe Admin::EmailTemplatesController do
old_subject = I18n.t("system_messages.pending_users_reminder.subject_template")
expect(old_subject).to be_a(Hash)
- put "/admin/customize/email_templates/system_messages.pending_users_reminder",
+ put "/admin/email/templates/system_messages.pending_users_reminder",
params: {
email_template: {
subject: "",
@@ -316,7 +316,7 @@ RSpec.describe Admin::EmailTemplatesController do
shared_examples "email template update not allowed" do
it "prevents updates with a 404 response" do
- put "/admin/customize/email_templates/some_id",
+ put "/admin/email/templates/some_id",
params: {
email_template: {
subject: "Subject",
@@ -352,7 +352,7 @@ RSpec.describe Admin::EmailTemplatesController do
before { sign_in(admin) }
it "returns 'not found' when an unknown email template id is used" do
- delete "/admin/customize/email_templates/non_existent_template", headers: headers
+ delete "/admin/email/templates/non_existent_template", headers: headers
expect(response).not_to be_successful
json = response.parsed_body
@@ -364,7 +364,7 @@ RSpec.describe Admin::EmailTemplatesController do
let(:email_body) { "The body contains [%{site_name}](%{base_url}) and %{email_token}." }
before do
- put "/admin/customize/email_templates/user_notifications.admin_login",
+ put "/admin/email/templates/user_notifications.admin_login",
params: {
email_template: {
subject: email_subject,
@@ -378,14 +378,14 @@ RSpec.describe Admin::EmailTemplatesController do
expect(I18n.t("user_notifications.admin_login.subject_template")).to eq(email_subject)
expect(I18n.t("user_notifications.admin_login.text_body_template")).to eq(email_body)
- delete "/admin/customize/email_templates/user_notifications.admin_login", headers: headers
+ delete "/admin/email/templates/user_notifications.admin_login", headers: headers
expect(I18n.t("user_notifications.admin_login.subject_template")).to eq(original_subject)
expect(I18n.t("user_notifications.admin_login.text_body_template")).to eq(original_body)
end
it "returns the restored email template" do
- delete "/admin/customize/email_templates/user_notifications.admin_login", headers: headers
+ delete "/admin/email/templates/user_notifications.admin_login", headers: headers
expect(response.status).to eq(200)
json = response.parsed_body
@@ -403,7 +403,7 @@ RSpec.describe Admin::EmailTemplatesController do
it "creates entries in the Staff Log" do
UserHistory.delete_all
- delete "/admin/customize/email_templates/user_notifications.admin_login", headers: headers
+ delete "/admin/email/templates/user_notifications.admin_login", headers: headers
log = UserHistory.find_by_subject("user_notifications.admin_login.subject_template")
@@ -424,7 +424,7 @@ RSpec.describe Admin::EmailTemplatesController do
shared_examples "email template reversal not allowed" do
it "prevents reversals with a 404 response" do
- delete "/admin/customize/email_templates/some_id", headers: headers
+ delete "/admin/email/templates/some_id", headers: headers
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))