You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. class Settings::KeywordMutesController < ApplicationController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :load_keyword_mute, only: [:edit, :update, :destroy]
  6. def index
  7. @keyword_mutes = paginated_keyword_mutes_for_account
  8. end
  9. def new
  10. @keyword_mute = keyword_mutes_for_account.build
  11. end
  12. def create
  13. @keyword_mute = keyword_mutes_for_account.create(keyword_mute_params)
  14. if @keyword_mute.persisted?
  15. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  16. else
  17. render :new
  18. end
  19. end
  20. def update
  21. if @keyword_mute.update(keyword_mute_params)
  22. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  23. else
  24. render :edit
  25. end
  26. end
  27. def destroy
  28. @keyword_mute.destroy!
  29. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  30. end
  31. def destroy_all
  32. keyword_mutes_for_account.delete_all
  33. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  34. end
  35. private
  36. def keyword_mutes_for_account
  37. Glitch::KeywordMute.where(account: current_account)
  38. end
  39. def load_keyword_mute
  40. @keyword_mute = keyword_mutes_for_account.find(params[:id])
  41. end
  42. def keyword_mute_params
  43. params.require(:keyword_mute).permit(:keyword, :whole_word)
  44. end
  45. def paginated_keyword_mutes_for_account
  46. keyword_mutes_for_account.order(:keyword).page params[:page]
  47. end
  48. end