Skip to content

Commit

Permalink
Merge pull request #13727 from dmarcoux/authorization-accordion_revie…
Browse files Browse the repository at this point in the history
…ws_component

Only display AccordionReviewsComponent if the user can handle the request
  • Loading branch information
Dany Marcoux authored Jan 19, 2023
2 parents c6e11c1 + d0eb7b8 commit 731e47f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/api/app/components/accordion_reviews_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class AccordionReviewsComponent < ApplicationComponent
def initialize(request_reviews, request_state)
def initialize(request_reviews, request_state, can_handle_request:)
super

@can_handle_request = can_handle_request
@accepted_reviews = request_reviews.select(&:accepted?)
@accepted_reviews_count = @accepted_reviews.size
@pending_reviews = request_reviews.select(&:new?)
Expand All @@ -12,7 +13,8 @@ def initialize(request_reviews, request_state)
end

def render?
(@accepted_reviews_count + @pending_reviews_count + @declined_reviews_count).positive? &&
@can_handle_request &&
(@accepted_reviews_count + @pending_reviews_count + @declined_reviews_count).positive? &&
# Declined is not really a final state, since the request can always be reopened...
(BsRequest::FINAL_REQUEST_STATES.exclude?(@request_state) || @request_state == :declined)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
%strong auto-accepted
in #{time_ago_in_words(bs_request.accept_at)}.

= render AccordionReviewsComponent.new(request_reviews, bs_request.state)
= render AccordionReviewsComponent.new(request_reviews, bs_request.state, can_handle_request: policy(bs_request).handle_request?)

= render RequestDecisionComponent.new(bs_request: bs_request, action: action,
is_target_maintainer: is_target_maintainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def preview
pending_reviews = Review.opened.take(3)
accepted_reviews = Review.accepted.take(2)
declined_review = Review.declined.take(1)
render(AccordionReviewsComponent.new(pending_reviews + accepted_reviews + declined_review, :review))
render(AccordionReviewsComponent.new(pending_reviews + accepted_reviews + declined_review, :review, can_handle_request: true))
end
end

0 comments on commit 731e47f

Please sign in to comment.