Skip to content

Commit

Permalink
Implement user requests listing under new controllers
Browse files Browse the repository at this point in the history
We want it to be more "the rails way" and to move specific code out of generic concerns
  • Loading branch information
danidoni committed Dec 4, 2024
1 parent 6c87f39 commit 2103735
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
66 changes: 58 additions & 8 deletions src/api/app/controllers/webui/users/bs_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class BsRequestsController < WebuiController
before_action :require_login
before_action :set_user

include Webui::RequestsFilter

REQUEST_METHODS = {
'all_requests_table' => :requests,
'requests_out_table' => :outgoing_requests,
Expand All @@ -14,27 +16,75 @@ class BsRequestsController < WebuiController

def index
if Flipper.enabled?(:request_index, User.session)
redirect_to requests_path(involvement: params[:involvement], state: params[:state])
else
parsed_params = BsRequest::DataTable::ParamsParser.new(params).parsed_params
requests_query = BsRequest::DataTable::FindForUserOrGroupQuery.new(@user_or_group, request_method, parsed_params)
@requests_data_table = BsRequest::DataTable::Table.new(requests_query, parsed_params[:draw])
set_filter_involvement
set_filter_state
set_filter_action_type
set_filter_creators

filter_requests
set_selected_filter

respond_to do |format|
format.json { render 'webui/shared/bs_requests/index' }
end
# TODO: Temporarily disable list of creators due to performance issues
# @bs_requests_creators = @bs_requests.distinct.pluck(:creator)
@bs_requests = @bs_requests.order('number DESC').page(params[:page])
@bs_requests = @bs_requests.includes(:bs_request_actions, :comments, :reviews)
@bs_requests = @bs_requests.includes(:labels) if Flipper.enabled?(:labels, User.session)
else
index_legacy
end
end

private

def filter_requests
if params[:requests_search_text].present?
initial_bs_requests = filter_by_text(params[:requests_search_text])
params[:ids] = filter_by_users_involvement(@filter_involvement).ids
else
initial_bs_requests = filter_by_users_involvement(@filter_involvement)
end

params[:creator] = @filter_creators if @filter_creators.present?
params[:states] = @filter_state if @filter_state.present?
params[:types] = @filter_action_type if @filter_action_type.present?

@bs_requests = BsRequest::FindFor::Query.new(params, initial_bs_requests).all
end

def filter_by_users_involvement(filter_involvement)
case filter_involvement
when 'all'
User.session.requests
when 'incoming'
User.session.incoming_requests
when 'outgoing'
User.session.outgoing_requests
end
end

def set_selected_filter
@selected_filter = { involvement: @filter_involvement, action_type: @filter_action_type, search_text: params[:requests_search_text],
state: @filter_state, creators: @filter_creators }
end

def set_user
@user_or_group = User.session
end

def request_method
REQUEST_METHODS[params[:dataTableId]] || :requests
end

# TODO: Remove this old index action when request_index feature is rolled-over
def index_legacy
parsed_params = BsRequest::DataTable::ParamsParser.new(params).parsed_params
requests_query = BsRequest::DataTable::FindForUserOrGroupQuery.new(@user_or_group, request_method, parsed_params)
@requests_data_table = BsRequest::DataTable::Table.new(requests_query, parsed_params[:draw])

respond_to do |format|
format.json { render 'webui/shared/bs_requests/index' }
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- if Flipper.enabled?(:request_index, User.session)
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
Requests
8 changes: 8 additions & 0 deletions src/api/app/views/webui/users/bs_requests/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- @pagetitle = requests_listing_pagetitle(@project)
.row
.px-0.px-md-3.mb-3
.card
= render(partial: 'webui/package/tabs', locals: { project: @project, package: @package })

= render(partial: 'webui/shared/bs_requests/form',
locals: { selected_filter: @selected_filter, bs_requests_creators: @bs_requests_creators, url: @url, bs_requests: @bs_requests })

0 comments on commit 2103735

Please sign in to comment.