Skip to content

Commit

Permalink
When a user leaves a feed, any previous feed invitation they received…
Browse files Browse the repository at this point in the history
… for that feed should be deleted

This way, they can be invited again in the future.

Fixes: CV2-3802.
  • Loading branch information
caiosba authored Nov 24, 2023
1 parent 6520075 commit 4ad2855
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/feed_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class FeedTeam < ApplicationRecord
validates_presence_of :team_id, :feed_id
validate :saved_search_belongs_to_feed_team

after_destroy :delete_invitations

def requests_filters=(filters)
filters = filters.is_a?(String) ? JSON.parse(filters) : filters
self.send(:set_requests_filters, filters)
Expand All @@ -24,4 +26,9 @@ def saved_search_belongs_to_feed_team
errors.add(:saved_search_id, I18n.t(:"errors.messages.invalid_feed_saved_search_value")) if self.team_id != self.saved_search.team_id
end
end

def delete_invitations
# Delete invitations to that feed when a user leaves a feed so they can be invited again in the future
FeedInvitation.where(email: User.current.email, feed_id: self.feed_id).delete_all unless User.current.blank?
end
end
15 changes: 15 additions & 0 deletions test/models/feed_team_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ def setup
ft.save!
assert_equal 'bar', ft.reload.get_requests_filters[:foo]
end

test "should delete invitations when leaving feed" do
u = create_user
ft = create_feed_team
create_team_user user: u, team: ft.team, role: 'admin'
create_feed_invitation feed: ft.feed
fi = create_feed_invitation email: u.email, feed: ft.feed
assert_not_nil FeedInvitation.find_by_id(fi.id)
User.current = u
assert_difference 'FeedInvitation.count', -1 do
ft.destroy!
end
User.current = nil
assert_nil FeedInvitation.find_by_id(fi.id)
end
end

0 comments on commit 4ad2855

Please sign in to comment.