2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-10-15 14:42:47 +05:30
class Groups :: RunnersController < Groups :: ApplicationController
2022-03-02 08:16:31 +05:30
before_action :authorize_read_group_runners! , only : [ :index , :show ]
before_action :authorize_admin_group_runners! , only : [ :edit , :update , :destroy , :pause , :resume ]
2021-10-27 15:23:28 +05:30
before_action :runner_list_group_view_vue_ui_enabled , only : [ :index ]
2018-10-15 14:42:47 +05:30
before_action :runner , only : [ :edit , :update , :destroy , :pause , :resume , :show ]
2021-09-30 23:02:18 +05:30
feature_category :runner
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
def index
2022-04-04 11:22:00 +05:30
finder = Ci :: RunnersFinder . new ( current_user : current_user , params : { group : @group } )
@group_runners_limited_count = finder . execute . except ( :limit , :offset ) . page . total_count_with_limit ( :all , limit : 1000 )
2021-10-27 15:23:28 +05:30
end
def runner_list_group_view_vue_ui_enabled
2022-03-02 08:16:31 +05:30
render_404 unless Feature . enabled? ( :runner_list_group_view_vue_ui , group , default_enabled : :yaml )
2021-10-27 15:23:28 +05:30
end
2018-10-15 14:42:47 +05:30
def show
end
def edit
end
def update
if Ci :: UpdateRunnerService . new ( @runner ) . update ( runner_params )
2019-07-07 11:18:12 +05:30
redirect_to group_runner_path ( @group , @runner ) , notice : _ ( 'Runner was successfully updated.' )
2018-10-15 14:42:47 +05:30
else
render 'edit'
end
end
def destroy
2020-07-28 23:09:34 +05:30
if @runner . belongs_to_more_than_one_project?
redirect_to group_settings_ci_cd_path ( @group , anchor : 'runners-settings' ) , status : :found , alert : _ ( 'Runner was not deleted because it is assigned to multiple projects.' )
else
2022-04-04 11:22:00 +05:30
Ci :: UnregisterRunnerService . new ( @runner ) . execute
2018-10-15 14:42:47 +05:30
2020-07-28 23:09:34 +05:30
redirect_to group_settings_ci_cd_path ( @group , anchor : 'runners-settings' ) , status : :found
end
2018-10-15 14:42:47 +05:30
end
def resume
if Ci :: UpdateRunnerService . new ( @runner ) . update ( active : true )
2019-07-07 11:18:12 +05:30
redirect_to group_settings_ci_cd_path ( @group , anchor : 'runners-settings' ) , notice : _ ( 'Runner was successfully updated.' )
2018-10-15 14:42:47 +05:30
else
2019-07-07 11:18:12 +05:30
redirect_to group_settings_ci_cd_path ( @group , anchor : 'runners-settings' ) , alert : _ ( 'Runner was not updated.' )
2018-10-15 14:42:47 +05:30
end
end
def pause
if Ci :: UpdateRunnerService . new ( @runner ) . update ( active : false )
2019-07-07 11:18:12 +05:30
redirect_to group_settings_ci_cd_path ( @group , anchor : 'runners-settings' ) , notice : _ ( 'Runner was successfully updated.' )
2018-10-15 14:42:47 +05:30
else
2019-07-07 11:18:12 +05:30
redirect_to group_settings_ci_cd_path ( @group , anchor : 'runners-settings' ) , alert : _ ( 'Runner was not updated.' )
2018-10-15 14:42:47 +05:30
end
end
private
def runner
2022-04-04 11:22:00 +05:30
@runner || = Ci :: RunnersFinder . new ( current_user : current_user , params : { group : @group } ) . execute
. except ( :limit , :offset )
. find ( params [ :id ] )
2018-10-15 14:42:47 +05:30
end
def runner_params
params . require ( :runner ) . permit ( Ci :: Runner :: FORM_EDITABLE )
end
end