debian-mirror-gitlab/app/controllers/projects/boards/lists_controller.rb

87 lines
2.2 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
module Projects
module Boards
class ListsController < Boards::ApplicationController
before_action :authorize_admin_list!, only: [:create, :update, :destroy, :generate]
before_action :authorize_read_list!, only: [:index]
def index
2017-09-10 17:25:29 +05:30
lists = ::Boards::Lists::ListService.new(project, current_user).execute(board)
render json: serialize_as_json(lists)
2016-09-13 17:45:13 +05:30
end
def create
2016-11-03 12:29:30 +05:30
list = ::Boards::Lists::CreateService.new(project, current_user, list_params).execute(board)
2016-09-13 17:45:13 +05:30
if list.valid?
render json: serialize_as_json(list)
else
render json: list.errors, status: :unprocessable_entity
end
end
def update
2016-11-03 12:29:30 +05:30
list = board.lists.movable.find(params[:id])
2016-09-13 17:45:13 +05:30
service = ::Boards::Lists::MoveService.new(project, current_user, move_params)
if service.execute(list)
head :ok
else
head :unprocessable_entity
end
end
def destroy
2016-11-03 12:29:30 +05:30
list = board.lists.destroyable.find(params[:id])
service = ::Boards::Lists::DestroyService.new(project, current_user)
2016-09-13 17:45:13 +05:30
if service.execute(list)
head :ok
else
head :unprocessable_entity
end
end
def generate
service = ::Boards::Lists::GenerateService.new(project, current_user)
2016-11-03 12:29:30 +05:30
if service.execute(board)
render json: serialize_as_json(board.lists.movable)
2016-09-13 17:45:13 +05:30
else
head :unprocessable_entity
end
end
private
def authorize_admin_list!
return render_403 unless can?(current_user, :admin_list, project)
end
def authorize_read_list!
return render_403 unless can?(current_user, :read_list, project)
end
2016-11-03 12:29:30 +05:30
def board
@board ||= project.boards.find(params[:board_id])
end
2016-09-13 17:45:13 +05:30
def list_params
params.require(:list).permit(:label_id)
end
def move_params
params.require(:list).permit(:position)
end
def serialize_as_json(resource)
resource.as_json(
only: [:id, :list_type, :position],
methods: [:title],
2016-11-03 12:29:30 +05:30
label: true
)
2016-09-13 17:45:13 +05:30
end
end
end
end