670e6a33f8
There are two motivations for this: 1. It looks like we're going to add other features that require server-side storage (e.g. user notes). 2. Namespacing glitchsoc modifications is a good idea anyway: even if we do not end up doing (1), if upstream introduces a keyword-mute feature that also uses a "KeywordMute" model, we can avoid some merge conflicts this way and work on the more interesting task of choosing which implementation to use.
72 lines
1.7 KiB
Ruby
72 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Settings::KeywordMutesController < ApplicationController
|
|
layout 'admin'
|
|
|
|
before_action :authenticate_user!
|
|
before_action :set_account
|
|
before_action :load_keyword_mute, only: [:edit, :update, :destroy]
|
|
|
|
def index
|
|
@keyword_mutes = paginated_keyword_mutes_for_account
|
|
end
|
|
|
|
def new
|
|
@keyword_mute = keyword_mutes_for_account.build
|
|
end
|
|
|
|
def create
|
|
@keyword_mute = keyword_mutes_for_account.create(keyword_mute_params)
|
|
|
|
if @keyword_mute.persisted?
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
if @keyword_mute.update(keyword_mute_params)
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @keyword_mute.destroy
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
else
|
|
# FIXME
|
|
redirect_to settings_keyword_mutes_path, notice: "huh that didn't work right"
|
|
end
|
|
end
|
|
|
|
def destroy_all
|
|
keyword_mutes_for_account.delete_all
|
|
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
end
|
|
|
|
private
|
|
|
|
def set_account
|
|
@account = current_user.account
|
|
end
|
|
|
|
def keyword_mutes_for_account
|
|
Glitch::KeywordMute.where(account: @account)
|
|
end
|
|
|
|
def load_keyword_mute
|
|
@keyword_mute = keyword_mutes_for_account.find(params[:id])
|
|
end
|
|
|
|
def keyword_mute_params
|
|
params.require(:keyword_mute).permit(:keyword, :whole_word)
|
|
end
|
|
|
|
def paginated_keyword_mutes_for_account
|
|
keyword_mutes_for_account.order(:keyword).page params[:page]
|
|
end
|
|
end
|