From 3b2bb356eb5f1f9ee2c43c46173eef183bff2bb4 Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:04:03 -0300 Subject: [PATCH] If a user declines a feed invitation, they can be invited again Fixes CV2-3802. --- app/models/ability.rb | 2 +- app/models/feed_invitation.rb | 3 ++- lib/check_basic_abilities.rb | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 5c4c7e6ece..ced37dbdaf 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -85,7 +85,7 @@ def editor_perms obj.annotation.team&.id == @context_team.id end can [:create, :update, :read, :destroy], [Account, Source, TiplineNewsletter, TiplineResource, Feed, FeedTeam], :team_id => @context_team.id - can [:create, :update, :destroy], FeedInvitation, { feed: { team_id: @context_team.id } } + can [:create, :update], FeedInvitation, { feed: { team_id: @context_team.id } } can :destroy, FeedTeam do |obj| obj.team.id == @context_team.id || obj.feed.team.id == @context_team.id end diff --git a/app/models/feed_invitation.rb b/app/models/feed_invitation.rb index 3b983386cc..c7c2ec49fd 100644 --- a/app/models/feed_invitation.rb +++ b/app/models/feed_invitation.rb @@ -18,7 +18,8 @@ def accept!(team_id) end def reject! - self.update_column(:state, :rejected) + # self.update_column(:state, :rejected) + self.destroy! end private diff --git a/lib/check_basic_abilities.rb b/lib/check_basic_abilities.rb index 8b5691d720..5d57449858 100644 --- a/lib/check_basic_abilities.rb +++ b/lib/check_basic_abilities.rb @@ -125,8 +125,8 @@ def extra_perms_for_all_users !(@user.cached_teams & obj.feed.team_ids).empty? end - can :read, FeedInvitation do |obj| - @user.email == obj.email || @user.id == obj.user_id + can [:read, :destroy], FeedInvitation do |obj| + @user.email == obj.email || @user.id == obj.user_id || TeamUser.where(user_id: @user.id, team_id: obj.feed.team_id, role: 'admin').exists? end end