mentions_controller.rb 1.2 KB

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