Skip to content

Commit

Permalink
Disallow author and anonymous inbox filter combination
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeldesu committed Jan 25, 2024
1 parent 134c575 commit b96651f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/inbox_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class InboxFilter
anonymous
].freeze

FORBIDDEN_PARAM_GROUPS = [
%i[author anonymous]
].freeze

attr_reader :params, :user

def initialize(user, params)
Expand All @@ -18,6 +22,8 @@ def initialize(user, params)
end

def results
return Inbox.none unless valid_params?

scope = @user.inboxes
.includes(:question, user: :profile)
.order(:created_at)
Expand All @@ -32,6 +38,10 @@ def results

private

def valid_params?
FORBIDDEN_PARAM_GROUPS.none? { |combination| combination.all? { |key| params.key?(key) } }
end

def scope_for(key, value)
case key.to_s
when "author"
Expand Down

0 comments on commit b96651f

Please sign in to comment.