logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

statuses_controller.rb (1987B)


  1. # frozen_string_literal: true
  2. module Admin
  3. class StatusesController < BaseController
  4. helper_method :current_params
  5. before_action :set_account
  6. before_action :set_status, only: [:update, :destroy]
  7. PER_PAGE = 20
  8. def index
  9. authorize :status, :index?
  10. @statuses = @account.statuses.where(visibility: [:public, :unlisted])
  11. if params[:media]
  12. account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
  13. @statuses.merge!(Status.where(id: account_media_status_ids))
  14. end
  15. @statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
  16. @form = Form::StatusBatch.new
  17. end
  18. def create
  19. authorize :status, :update?
  20. @form = Form::StatusBatch.new(form_status_batch_params.merge(current_account: current_account))
  21. flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
  22. redirect_to admin_account_statuses_path(@account.id, current_params)
  23. end
  24. def update
  25. authorize @status, :update?
  26. @status.update!(status_params)
  27. log_action :update, @status
  28. redirect_to admin_account_statuses_path(@account.id, current_params)
  29. end
  30. def destroy
  31. authorize @status, :destroy?
  32. RemovalWorker.perform_async(@status.id)
  33. log_action :destroy, @status
  34. render json: @status
  35. end
  36. private
  37. def status_params
  38. params.require(:status).permit(:sensitive)
  39. end
  40. def form_status_batch_params
  41. params.require(:form_status_batch).permit(:action, status_ids: [])
  42. end
  43. def set_status
  44. @status = @account.statuses.find(params[:id])
  45. end
  46. def set_account
  47. @account = Account.find(params[:account_id])
  48. end
  49. def current_params
  50. page = (params[:page] || 1).to_i
  51. {
  52. media: params[:media],
  53. page: page > 1 && page,
  54. }.select { |_, value| value.present? }
  55. end
  56. end
  57. end