Retrospring/app/controllers/ajax/mute_rule_controller.rb

68 lines
1.4 KiB
Ruby
Raw Normal View History

2021-12-22 14:15:47 -08:00
class Ajax::MuteRuleController < AjaxController
def create
params.require :muted_phrase
unless user_signed_in?
@response[:status] = :noauth
@response[:message] = t(".noauth")
2021-12-22 14:15:47 -08:00
return
end
rule = MuteRule.create!(user: current_user, muted_phrase: params[:muted_phrase])
@response[:status] = :okay
@response[:success] = true
@response[:message] = t(".success")
2021-12-22 14:15:47 -08:00
@response[:id] = rule.id
end
def update
params.require :id
params.require :muted_phrase
unless user_signed_in?
@response[:status] = :noauth
@response[:message] = t(".noauth")
2021-12-22 14:15:47 -08:00
return
end
rule = MuteRule.find(params[:id])
if rule.user_id != current_user.id
@response[:status] = :nopriv
@response[:message] = t(".nopriv")
2021-12-22 14:15:47 -08:00
return
end
rule.muted_phrase = params[:muted_phrase]
rule.save!
@response[:status] = :okay
@response[:message] = t(".success")
2021-12-22 14:15:47 -08:00
@response[:success] = true
end
def destroy
params.require :id
unless user_signed_in?
@response[:status] = :noauth
@response[:message] = t(".noauth")
2021-12-22 14:15:47 -08:00
return
end
rule = MuteRule.find(params[:id])
if rule.user_id != current_user.id
@response[:status] = :nopriv
@response[:message] = t(".nopriv")
2021-12-22 14:15:47 -08:00
return
end
rule.destroy!
@response[:status] = :okay
@response[:message] = t(".success")
2021-12-22 14:15:47 -08:00
@response[:success] = true
end
end