diff --git a/app/controllers/repository_columns/asset_columns_controller.rb b/app/controllers/repository_columns/asset_columns_controller.rb index 38fa56fce..0944921d0 100644 --- a/app/controllers/repository_columns/asset_columns_controller.rb +++ b/app/controllers/repository_columns/asset_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class AssetColumnsController < BaseColumnsController + class AssetColumnsController < RepositoryColumnsController include InputSanitizeHelper before_action :load_column, only: :update before_action :check_create_permissions, only: :create diff --git a/app/controllers/repository_columns/base_columns_controller.rb b/app/controllers/repository_columns/base_columns_controller.rb deleted file mode 100644 index 29b46d3d1..000000000 --- a/app/controllers/repository_columns/base_columns_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module RepositoryColumns - class BaseColumnsController < ApplicationController - include InputSanitizeHelper - before_action :load_repository - - private - - def load_repository - @repository = Repository.accessible_by_teams(current_team).find_by(id: params[:repository_id]) - render_404 unless @repository - end - - def load_column - @repository_column = @repository.repository_columns.find_by(id: params[:id]) - render_404 unless @repository_column - end - - def check_create_permissions - render_403 unless can_create_repository_columns?(@repository) - end - - def check_manage_permissions - render_403 unless can_manage_repository_column?(@repository_column) - end - end -end diff --git a/app/controllers/repository_columns/checklist_columns_controller.rb b/app/controllers/repository_columns/checklist_columns_controller.rb index 3978ee446..12e3c43e2 100644 --- a/app/controllers/repository_columns/checklist_columns_controller.rb +++ b/app/controllers/repository_columns/checklist_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class ChecklistColumnsController < BaseColumnsController + class ChecklistColumnsController < RepositoryColumnsController before_action :load_column, only: %i(update items) before_action :check_create_permissions, only: :create before_action :check_manage_permissions, only: :update diff --git a/app/controllers/repository_columns/date_time_columns_controller.rb b/app/controllers/repository_columns/date_time_columns_controller.rb index 21f43e7a7..c1a9ecbc1 100644 --- a/app/controllers/repository_columns/date_time_columns_controller.rb +++ b/app/controllers/repository_columns/date_time_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class DateTimeColumnsController < BaseColumnsController + class DateTimeColumnsController < RepositoryColumnsController include InputSanitizeHelper before_action :load_column, only: :update before_action :check_create_permissions, only: :create diff --git a/app/controllers/repository_columns/list_columns_controller.rb b/app/controllers/repository_columns/list_columns_controller.rb index cb605a33a..3bae9466d 100644 --- a/app/controllers/repository_columns/list_columns_controller.rb +++ b/app/controllers/repository_columns/list_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class ListColumnsController < BaseColumnsController + class ListColumnsController < RepositoryColumnsController before_action :load_column, only: %i(update items) before_action :check_create_permissions, only: :create before_action :check_manage_permissions, only: :update diff --git a/app/controllers/repository_columns/number_columns_controller.rb b/app/controllers/repository_columns/number_columns_controller.rb index 516bad56e..ba3dc3469 100644 --- a/app/controllers/repository_columns/number_columns_controller.rb +++ b/app/controllers/repository_columns/number_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class NumberColumnsController < BaseColumnsController + class NumberColumnsController < RepositoryColumnsController include InputSanitizeHelper before_action :load_column, only: :update before_action :check_create_permissions, only: :create diff --git a/app/controllers/repository_columns/status_columns_controller.rb b/app/controllers/repository_columns/status_columns_controller.rb index b174f5c3c..940c228e5 100644 --- a/app/controllers/repository_columns/status_columns_controller.rb +++ b/app/controllers/repository_columns/status_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class StatusColumnsController < BaseColumnsController + class StatusColumnsController < RepositoryColumnsController include InputSanitizeHelper before_action :load_column, only: %i(update items) before_action :check_create_permissions, only: :create diff --git a/app/controllers/repository_columns/text_columns_controller.rb b/app/controllers/repository_columns/text_columns_controller.rb index 2908059f3..efb35da93 100644 --- a/app/controllers/repository_columns/text_columns_controller.rb +++ b/app/controllers/repository_columns/text_columns_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module RepositoryColumns - class TextColumnsController < BaseColumnsController + class TextColumnsController < RepositoryColumnsController include InputSanitizeHelper before_action :load_column, only: :update before_action :check_create_permissions, only: :create diff --git a/app/controllers/repository_columns_controller.rb b/app/controllers/repository_columns_controller.rb index 1a95cff1b..1b1f94036 100644 --- a/app/controllers/repository_columns_controller.rb +++ b/app/controllers/repository_columns_controller.rb @@ -2,18 +2,13 @@ class RepositoryColumnsController < ApplicationController include InputSanitizeHelper include RepositoryColumnsHelper - ACTIONS = %i( - create index_html create_html available_asset_type_columns available_columns - ).freeze - before_action :load_vars, - except: ACTIONS - before_action :load_vars_nested, - only: ACTIONS - before_action :check_manage_permissions, - except: ACTIONS + before_action :load_repository + before_action :load_column, only: %i(edit destroy_html destroy) + before_action :check_create_permissions, only: :new + before_action :check_manage_permissions, only: %i(edit destroy_html destroy) before_action :load_asset_type_columns, only: :available_asset_type_columns - def index_html + def index render json: { id: @repository.id, html: render_to_string( @@ -22,7 +17,7 @@ class RepositoryColumnsController < ApplicationController } end - def create_html + def new @repository_column = RepositoryColumn.new respond_to do |format| format.json do @@ -35,8 +30,12 @@ class RepositoryColumnsController < ApplicationController end end - def edit_html - render json: { html: render_to_string(partial: 'repository_columns/manage_column_modal_content.html.erb') } + def edit + render json: { + html: render_to_string( + partial: 'repository_columns/manage_column_modal_content.html.erb' + ) + } end def destroy_html @@ -96,16 +95,14 @@ class RepositoryColumnsController < ApplicationController include StringUtility AvailableRepositoryColumn = Struct.new(:id, :name) - def load_vars - @repository = Repository.accessible_by_teams(current_team).find_by_id(params[:repository_id]) + def load_repository + @repository = Repository.accessible_by_teams(current_team).find_by(id: params[:repository_id]) render_404 unless @repository - @repository_column = @repository.repository_columns.find_by_id(params[:id]) - render_404 unless @repository_column end - def load_vars_nested - @repository = Repository.accessible_by_teams(current_team).find_by_id(params[:repository_id]) - render_404 unless @repository + def load_column + @repository_column = @repository.repository_columns.find_by(id: params[:id]) + render_404 unless @repository_column end def load_asset_type_columns @@ -113,6 +110,10 @@ class RepositoryColumnsController < ApplicationController @asset_columns = load_asset_columns(search_params[:q]) end + def check_create_permissions + render_403 unless can_create_repository_columns?(@repository) + end + def check_manage_permissions render_403 unless can_manage_repository_column?(@repository_column) end diff --git a/app/views/my_modules/repository.html.erb b/app/views/my_modules/repository.html.erb index f1bfdb29c..03f7a17b8 100644 --- a/app/views/my_modules/repository.html.erb +++ b/app/views/my_modules/repository.html.erb @@ -19,7 +19,7 @@
diff --git a/app/views/repository_columns/_delete_column_modal_body.html.erb b/app/views/repository_columns/_delete_column_modal_body.html.erb index cbea4cade..b84a5b088 100644 --- a/app/views/repository_columns/_delete_column_modal_body.html.erb +++ b/app/views/repository_columns/_delete_column_modal_body.html.erb @@ -1,7 +1,7 @@