Skip to content

Commit

Permalink
rails-5.0-message-controller-spec: add participant logic to message_p…
Browse files Browse the repository at this point in the history
…olicy and check both users and conversation.users if not persisted (#331)
  • Loading branch information
Tooyosi authored Jul 2, 2024
1 parent 7a6384d commit cbb562c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/policies/message_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ def destroy?
false
end

def participant?
return false unless logged_in?
Array.wrap(record).each do |r|
if r.persisted?
return r.users.exists?(id: user.id)
elsif r.conversation
return r.conversation.users.exists?(id: user.id)
end
return false
end
true
end

class Scope < Scope
def resolve
scope.joins(:conversation, :user_conversations).where({
Expand Down

0 comments on commit cbb562c

Please sign in to comment.