FEATURE: Category reordering dialog

This commit is contained in:
Kane York
2015-08-27 10:14:59 -07:00
parent e06d407153
commit 342eba4374
16 changed files with 373 additions and 6 deletions

View File

@ -37,7 +37,7 @@ class CategoriesController < ApplicationController
end
def move
guardian.ensure_can_create!(Category)
guardian.ensure_can_create_category!
params.require("category_id")
params.require("position")
@ -50,6 +50,24 @@ class CategoriesController < ApplicationController
end
end
def reorder
guardian.ensure_can_create_category!
params.require(:mapping)
change_requests = MultiJson.load(params[:mapping])
by_category = Hash[change_requests.map { |cat, pos| [Category.find(cat.to_i), pos] }]
unless guardian.is_admin?
raise Discourse::InvalidAccess unless by_category.keys.all? { |c| guardian.can_see_category? c }
end
by_category.each do |cat, pos|
cat.position = pos
cat.save if cat.position_changed?
end
render json: success_json
end
def show
if Category.topic_create_allowed(guardian).where(id: @category.id).exists?
@category.permission = CategoryGroup.permission_types[:full]