mentions_controller.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class MentionsController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. # GET /api/v1/mentions
  5. def index
  6. list = mentionable_object.mentions
  7. if response_full?
  8. item_ids = list.map(&:id)
  9. assets = ApplicationModel::CanAssets.reduce list
  10. render json: {
  11. record_ids: item_ids,
  12. assets: assets,
  13. }
  14. return
  15. end
  16. # return result
  17. render json: {
  18. mentions: list,
  19. }
  20. end
  21. # POST /api/v1/mentions
  22. def create
  23. Mention.subscribe! mentionable_object, current_user
  24. render json: true, status: :created
  25. end
  26. # DELETE /api/v1/mentions
  27. def destroy
  28. Mention.where(user: current_user, id: params[:id]).destroy_all
  29. render json: true, status: :ok
  30. end
  31. def mentionable_object
  32. @mentionable_object ||= begin
  33. case params[:mentionable_type]
  34. when 'Ticket'
  35. Ticket.find_by id: params[:mentionable_id]
  36. else
  37. raise Exceptions::UnprocessableEntity, __("The parameter 'mentionable_type' is invalid.")
  38. end
  39. end
  40. end
  41. end