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
|
2022-02-16 15:55:44 -08:00
|
|
|
@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
|
2022-02-16 15:55:44 -08:00
|
|
|
@response[:message] = t(".success")
|
2022-09-02 10:59:43 -07:00
|
|
|
@response[:id] = rule.id.to_s # Returning this as a string as JavaScript defines all numbers as floats
|
2021-12-22 14:15:47 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
params.require :id
|
|
|
|
params.require :muted_phrase
|
|
|
|
|
|
|
|
unless user_signed_in?
|
|
|
|
@response[:status] = :noauth
|
2022-02-16 15:55:44 -08:00
|
|
|
@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
|
2022-02-16 15:55:44 -08:00
|
|
|
@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
|
2022-02-16 15:55:44 -08:00
|
|
|
@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
|
2022-02-16 15:55:44 -08:00
|
|
|
@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
|
2022-02-16 15:55:44 -08:00
|
|
|
@response[:message] = t(".nopriv")
|
2021-12-22 14:15:47 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
rule.destroy!
|
|
|
|
|
|
|
|
@response[:status] = :okay
|
2022-02-16 15:55:44 -08:00
|
|
|
@response[:message] = t(".success")
|
2021-12-22 14:15:47 -08:00
|
|
|
@response[:success] = true
|
|
|
|
end
|
|
|
|
end
|