0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/plugins/discourse-zendesk-plugin/app/controllers/discourse_zendesk_plugin/issues_controller.rb
Gabriel Grubba 8373bbc4ff SECURITY: Block ticket creation when user can't see the topic
This change ensures that users can only create tickets for topics they have access to view.

Also adds tests to the happy path of ticket creation.
2026-03-19 15:21:28 +00:00

23 lines
653 B
Ruby
Vendored

# frozen_string_literal: true
module DiscourseZendeskPlugin
class IssuesController < ApplicationController
include DiscourseZendeskPlugin::Helper
requires_plugin PLUGIN_NAME
def create
topic = Topic.find(params[:topic_id])
guardian.ensure_can_see!(topic)
if topic.custom_fields[DiscourseZendeskPlugin::ZENDESK_ID_FIELD].blank?
create_ticket(topic.first_post)
end
topic_view = ::TopicView.new(topic.id, current_user)
topic_view_serializer =
::TopicViewSerializer.new(topic_view, scope: topic_view.guardian, root: false)
render_json_dump topic_view_serializer
end
end
end