Add BaseColumnsController for column_types controllers

This commit is contained in:
Urban Rotnik 2019-10-11 09:57:01 +02:00
parent 14b43d516e
commit 4cb3d1b6f0
2 changed files with 29 additions and 20 deletions

View file

@ -0,0 +1,28 @@
# 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

View file

@ -1,9 +1,8 @@
# frozen_string_literal: true
module RepositoryColumns
class StatusColumnsController < ApplicationController
class StatusColumnsController < BaseColumnsController
include InputSanitizeHelper
before_action :load_repository
before_action :load_column, only: %i(update destroy)
before_action :check_create_permissions, only: :create
before_action :check_manage_permissions, only: %i(update destroy)
@ -92,23 +91,5 @@ module RepositoryColumns
def update_repository_column_params
params.require(:repository_column).permit(repository_status_items_attributes: %i(id status icon _destroy))
end
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