Allow user to create a board list based on a group label

parent 398ab263
......@@ -25,7 +25,10 @@ class Projects::IssuesController < Projects::ApplicationController
def index
@issues = issues_collection
@issues = @issues.page(params[:page])
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute if params[:label_name].presence
if params[:label_name].presence
@labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute
end
respond_to do |format|
format.html
......
......@@ -3,7 +3,7 @@ module Boards
class CreateService < BaseService
def execute(board)
List.transaction do
label = project.labels.find(params[:label_id])
label = available_labels.find(params[:label_id])
position = next_position(board)
create_list(board, label, position)
......@@ -12,6 +12,10 @@ module Boards
private
def available_labels
LabelsFinder.new(current_user, project_id: project.id).execute
end
def next_position(board)
max_position = board.lists.movable.maximum(:position)
max_position.nil? ? 0 : max_position.succ
......
......@@ -9,6 +9,10 @@ describe Boards::Lists::CreateService, services: true do
subject(:service) { described_class.new(project, user, label_id: label.id) }
before do
project.team << [user, :developer]
end
context 'when board lists is empty' do
it 'creates a new list at beginning of the list' do
list = service.execute(board)
......
......@@ -8,6 +8,10 @@ describe Boards::Lists::GenerateService, services: true do
subject(:service) { described_class.new(project, user) }
before do
project.team << [user, :developer]
end
context 'when board lists is empty' do
it 'creates the default lists' do
expect { service.execute(board) }.to change(board.lists, :count).by(2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment