mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
FEATURE: Category reordering dialog
This commit is contained in:
@ -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]
|
||||
|
Reference in New Issue
Block a user