From 94c9fa12fbec1c5f4506fa01595428dbb962d4b3 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Fri, 18 Nov 2022 22:51:05 +0100 Subject: [PATCH] Add policy for mute rules --- app/controllers/settings/mutes_controller.rb | 3 +++ app/policies/mute_rule_policy.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 app/policies/mute_rule_policy.rb diff --git a/app/controllers/settings/mutes_controller.rb b/app/controllers/settings/mutes_controller.rb index 38675db3..28f9d094 100644 --- a/app/controllers/settings/mutes_controller.rb +++ b/app/controllers/settings/mutes_controller.rb @@ -21,6 +21,9 @@ class Settings::MutesController < ApplicationController def destroy rule = MuteRule.find(params[:id]) + + authorize rule + rule.destroy! respond_to do |format| diff --git a/app/policies/mute_rule_policy.rb b/app/policies/mute_rule_policy.rb new file mode 100644 index 00000000..8e0c9576 --- /dev/null +++ b/app/policies/mute_rule_policy.rb @@ -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