Add policy for mute rules

This commit is contained in:
Andreas Nedbal 2022-11-18 22:51:05 +01:00 committed by Andreas Nedbal
parent c8f990e319
commit 94c9fa12fb
2 changed files with 17 additions and 0 deletions

View File

@ -21,6 +21,9 @@ class Settings::MutesController < ApplicationController
def destroy def destroy
rule = MuteRule.find(params[:id]) rule = MuteRule.find(params[:id])
authorize rule
rule.destroy! rule.destroy!
respond_to do |format| respond_to do |format|

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
class MuteRulePolicy
attr_reader :user, :mute_rule
def initialize(user, mute_rule)
@user = user
@mute_rule = mute_rule
end
def destroy?
user == mute_rule.user || user.admin?
end
end