mirror of
https://github.com/discourse/discourse.git
synced 2025-04-02 18:05:57 +08:00
Make it possible to edit a category with an empty slug
This commit is contained in:
parent
cbe0168922
commit
372442bd1c
@ -38,14 +38,14 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
destroy: function(callback) {
|
destroy: function(callback) {
|
||||||
return Discourse.ajax(Discourse.getURL("/categories/") + (this.get('slug')), { type: 'DELETE' });
|
return Discourse.ajax(Discourse.getURL("/categories/") + (this.get('slug') || this.get('id')), { type: 'DELETE' });
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Category.reopenClass({
|
Discourse.Category.reopenClass({
|
||||||
findBySlug: function(categorySlug) {
|
findBySlugOrId: function(slugOrId) {
|
||||||
return Discourse.ajax({url: Discourse.getURL("/categories/") + categorySlug + ".json"}).then(function (result) {
|
return Discourse.ajax({url: Discourse.getURL("/categories/") + slugOrId + ".json"}).then(function (result) {
|
||||||
return Discourse.Category.create(result.category);
|
return Discourse.Category.create(result.category);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||||||
var categoryView = this;
|
var categoryView = this;
|
||||||
|
|
||||||
// We need the topic_count to be correct, so get the most up-to-date info about this category from the server.
|
// We need the topic_count to be correct, so get the most up-to-date info about this category from the server.
|
||||||
Discourse.Category.findBySlug( this.get('category.slug') ).then( function(cat) {
|
Discourse.Category.findBySlugOrId( this.get('category.slug') || this.get('category.id') ).then( function(cat) {
|
||||||
categoryView.set('category', cat);
|
categoryView.set('category', cat);
|
||||||
Discourse.get('site').updateCategory(cat);
|
Discourse.get('site').updateCategory(cat);
|
||||||
categoryView.set('id', categoryView.get('category.slug'));
|
categoryView.set('id', categoryView.get('category.slug'));
|
||||||
|
@ -3,6 +3,7 @@ require_dependency 'category_serializer'
|
|||||||
class CategoriesController < ApplicationController
|
class CategoriesController < ApplicationController
|
||||||
|
|
||||||
before_filter :ensure_logged_in, except: [:index, :show]
|
before_filter :ensure_logged_in, except: [:index, :show]
|
||||||
|
before_filter :fetch_category, only: [:show, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
list = CategoryList.new(current_user)
|
list = CategoryList.new(current_user)
|
||||||
@ -11,7 +12,6 @@ class CategoriesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@category = Category.where(slug: params[:id]).first
|
|
||||||
render_serialized(@category, CategorySerializer)
|
render_serialized(@category, CategorySerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -27,17 +27,13 @@ class CategoriesController < ApplicationController
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
requires_parameters(*required_param_keys)
|
requires_parameters(*required_param_keys)
|
||||||
|
|
||||||
@category = Category.where(id: params[:id]).first
|
|
||||||
guardian.ensure_can_edit!(@category)
|
guardian.ensure_can_edit!(@category)
|
||||||
|
|
||||||
json_result(@category, serializer: CategorySerializer) { |cat| cat.update_attributes(category_params) }
|
json_result(@category, serializer: CategorySerializer) { |cat| cat.update_attributes(category_params) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
category = Category.where(slug: params[:id]).first
|
guardian.ensure_can_delete!(@category)
|
||||||
guardian.ensure_can_delete!(category)
|
@category.destroy
|
||||||
category.destroy
|
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -54,4 +50,8 @@ class CategoriesController < ApplicationController
|
|||||||
def category_params
|
def category_params
|
||||||
params.slice(*category_param_keys)
|
params.slice(*category_param_keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_category
|
||||||
|
@category = Category.where(slug: params[:id]).first || Category.where(id: params[:id].to_i).first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user