A platform for community discussion. Free, open, simple.
FIX: Allow for cateogry edit routes of unknown depth (#11426)
jbrw4c118e4d7ae6
diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.jsindex c37eeeef854..2f60ce8350d 100644--- a/app/assets/javascripts/discourse/app/models/category.js+++ b/app/assets/javascripts/discourse/app/models/category.js@@ -490,12 +490,6 @@ Category.reopenClass({return ajax(`/c/${id}/show.json`);},- reloadBySlug(slug, parentSlug) {- return parentSlug- ? ajax(`/c/${parentSlug}/${slug}/find_by_slug.json`)- : ajax(`/c/${slug}/find_by_slug.json`);- },-reloadBySlugPath(slugPath) {return ajax(`/c/${slugPath}/find_by_slug.json`);},@@ -507,7 +501,7 @@ Category.reopenClass({this._includePermissions(result.category, store, site));}- return this.reloadBySlug(params.slug, params.parentSlug).then((result) =>+ return this.reloadBySlugPath(params.slug).then((result) =>this._includePermissions(result.category, store, site));},diff --git a/app/assets/javascripts/discourse/app/routes/app-route-map.js b/app/assets/javascripts/discourse/app/routes/app-route-map.jsindex 5352b1ff7c9..8e66333e3e4 100644--- a/app/assets/javascripts/discourse/app/routes/app-route-map.js+++ b/app/assets/javascripts/discourse/app/routes/app-route-map.js@@ -22,16 +22,9 @@ export default function () {this.route("topicBySlugOrId", { path: "/t/:slugOrId", resetNamespace: true });this.route("newCategory", { path: "/new-category" });- this.route("editCategory", { path: "/c/:slug/edit" }, function () {+ this.route("editCategory", { path: "/c/*slug/edit" }, function () {this.route("tabs", { path: "/:tab" });});- this.route(- "editChildCategory",- { path: "/c/:parentSlug/:slug/edit" },- function () {- this.route("tabs", { path: "/:tab" });- }- );this.route("discovery", { path: "/", resetNamespace: true }, function () {// topdiff --git a/app/assets/javascripts/discourse/app/routes/edit-child-category-index.js b/app/assets/javascripts/discourse/app/routes/edit-child-category-index.jsdeleted file mode 100644index 43c73864de4..00000000000--- a/app/assets/javascripts/discourse/app/routes/edit-child-category-index.js+++ /dev/null@@ -1,8 +0,0 @@-import DiscourseRoute from "discourse/routes/discourse";--export default DiscourseRoute.extend({- afterModel() {- const params = this.paramsFor("editChildCategory");- this.replaceWith(`/c/${params.parentSlug}/${params.slug}/edit/general`);- },-});diff --git a/app/assets/javascripts/discourse/app/routes/edit-child-category-tabs.js b/app/assets/javascripts/discourse/app/routes/edit-child-category-tabs.jsdeleted file mode 100644index 402bed4910e..00000000000--- a/app/assets/javascripts/discourse/app/routes/edit-child-category-tabs.js+++ /dev/null@@ -1,19 +0,0 @@-import DiscourseRoute from "discourse/routes/discourse";--export default DiscourseRoute.extend({- model() {- return this.modelFor("editChildCategory");- },-- renderTemplate() {- this.render("edit-category-tabs", {- controller: "edit-category-tabs",- model: this.currentModel,- });-- this.controllerFor("editCategory.tabs").set(- "parentParams",- this.paramsFor("editChildCategory")- );- },-});diff --git a/app/assets/javascripts/discourse/app/routes/edit-child-category.js b/app/assets/javascripts/discourse/app/routes/edit-child-category.jsdeleted file mode 100644index f9ebcf1255c..00000000000--- a/app/assets/javascripts/discourse/app/routes/edit-child-category.js+++ /dev/null@@ -1,19 +0,0 @@-import Category from "discourse/models/category";-import DiscourseRoute from "discourse/routes/discourse";-import I18n from "I18n";--export default DiscourseRoute.extend({- model(params) {- return Category.reloadCategoryWithPermissions(- params,- this.store,- this.site- );- },-- titleToken() {- return I18n.t("category.edit_dialog_title", {- categoryName: this.currentModel.name,- });- },-});diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rbindex 32ad2df84d1..e6070790f41 100644--- a/app/controllers/categories_controller.rb+++ b/app/controllers/categories_controller.rb@@ -204,7 +204,7 @@ class CategoriesController < ApplicationControllerdef find_by_slugparams.require(:category_slug)- @category = Category.find_by_slug(params[:category_slug], params[:parent_category_slug])+ @category = Category.find_by_slug_path(params[:category_slug].split('/'))raise Discourse::NotFound unless @category.present?diff --git a/config/routes.rb b/config/routes.rbindex 1cd24d1f0e4..897c35f6ac7 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -681,10 +681,8 @@ Discourse::Application.routes.draw doget "c/:id/show" => "categories#show"- get "c/:category_slug/find_by_slug" => "categories#find_by_slug"- get "c/:parent_category_slug/:category_slug/find_by_slug" => "categories#find_by_slug"- get "c/:category_slug/edit(/:tab)" => "categories#find_by_slug", constraints: { format: 'html' }- get "c/:parent_category_slug/:category_slug/edit(/:tab)" => "categories#find_by_slug", constraints: { format: 'html' }+ get "c/*category_slug/find_by_slug" => "categories#find_by_slug"+ get "c/*category_slug/edit(/:tab)" => "categories#find_by_slug", constraints: { format: 'html' }get "/new-category" => "categories#show", constraints: { format: 'html' }get "c/*category_slug_path_with_id.rss" => "list#category_feed", format: :rss