debian-mirror-gitlab/app/controllers/admin/topics_controller.rb

87 lines
2 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
class Admin::TopicsController < Admin::ApplicationController
include SendFileUpload
include PreviewMarkdown
2022-08-13 15:12:31 +05:30
before_action :topic, only: [:edit, :update, :destroy]
2021-11-18 22:05:49 +05:30
feature_category :projects
def index
@topics = Projects::TopicsFinder.new(params: params.permit(:search)).execute.page(params[:page]).without_count
end
def new
@topic = Projects::Topic.new
end
def edit
end
def create
@topic = Projects::Topic.new(topic_params)
if @topic.save
redirect_to edit_admin_topic_path(@topic), notice: _('Topic %{topic_name} was successfully created.') % { topic_name: @topic.name }
else
render "new"
end
end
def update
if @topic.update(topic_params)
redirect_to edit_admin_topic_path(@topic), notice: _('Topic was successfully updated.')
else
render "edit"
end
end
2022-08-13 15:12:31 +05:30
def destroy
@topic.destroy!
redirect_to admin_topics_path,
status: :found,
notice: _('Topic %{topic_name} was successfully removed.') % { topic_name: @topic.title_or_name }
end
2022-08-27 11:52:29 +05:30
def merge
source_topic = Projects::Topic.find(merge_params[:source_topic_id])
target_topic = Projects::Topic.find(merge_params[:target_topic_id])
begin
::Topics::MergeService.new(source_topic, target_topic).execute
rescue ArgumentError => e
return render status: :bad_request, json: { type: :alert, message: e.message }
end
message = _('Topic %{source_topic} was successfully merged into topic %{target_topic}.')
redirect_to admin_topics_path,
status: :found,
notice: message % { source_topic: source_topic.name, target_topic: target_topic.name }
end
2021-11-18 22:05:49 +05:30
private
def topic
@topic ||= Projects::Topic.find(params[:id])
end
def topic_params
params.require(:projects_topic).permit(allowed_topic_params)
end
def allowed_topic_params
[
:avatar,
:description,
2022-07-16 23:28:13 +05:30
:name,
:title
2021-11-18 22:05:49 +05:30
]
end
2022-08-27 11:52:29 +05:30
def merge_params
params.permit([:source_topic_id, :target_topic_id])
end
2021-11-18 22:05:49 +05:30
end