Commit 274987d5 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Fatih Acet

Reuse endpoint to list issues for a list instead of create a new one

parent 7f58fc0e
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
}).then((res) => { }).then((res) => {
const data = res.json(); const data = res.json();
data.forEach((issueObj) => { data.issues.forEach((issueObj) => {
const issue = new ListIssue(issueObj); const issue = new ListIssue(issueObj);
const foundSelectedIssue = ModalStore.findSelectedIssue(issue); const foundSelectedIssue = ModalStore.findSelectedIssue(issue);
issue.selected = foundSelectedIssue !== undefined; issue.selected = foundSelectedIssue !== undefined;
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
class BoardService { class BoardService {
constructor (root, boardId) { constructor (root, boardId) {
this.boards = Vue.resource(`${root}{/id}.json`, {}, { this.boards = Vue.resource(`${root}{/id}.json`, {}, {
backlog: { issues: {
method: 'GET', method: 'GET',
url: `${root}/${boardId}/backlog.json` url: `${root}/${boardId}/issues.json`
} }
}); });
this.lists = Vue.resource(`${root}/${boardId}/lists{/id}`, {}, { this.lists = Vue.resource(`${root}/${boardId}/lists{/id}`, {}, {
...@@ -73,7 +73,7 @@ class BoardService { ...@@ -73,7 +73,7 @@ class BoardService {
} }
getBacklog(data) { getBacklog(data) {
return this.boards.backlog(data); return this.boards.issues(data);
} }
} }
......
...@@ -59,7 +59,7 @@ module Projects ...@@ -59,7 +59,7 @@ module Projects
end end
def filter_params def filter_params
params.merge(board_id: params[:board_id], id: params[:list_id]) params.merge(board_id: params[:board_id], id: params[:list_id]).compact
end end
def move_params def move_params
......
class Projects::BoardsController < Projects::ApplicationController class Projects::BoardsController < Projects::ApplicationController
include IssuableCollections include IssuableCollections
# before_action :authorize_read_board!, only: [:index, :show, :backlog] before_action :authorize_read_board!, only: [:index, :show]
def index def index
@boards = ::Boards::ListService.new(project, current_user).execute @boards = ::Boards::ListService.new(project, current_user).execute
...@@ -25,27 +25,6 @@ class Projects::BoardsController < Projects::ApplicationController ...@@ -25,27 +25,6 @@ class Projects::BoardsController < Projects::ApplicationController
end end
end end
def backlog
board = project.boards.find(params[:id])
@issues = issues_collection
@issues = @issues.where.not(
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
.where(label_id: board.lists.movable.pluck(:label_id)).limit(1).arel.exists
)
@issues = @issues.page(params[:page]).per(params[:per])
render json: @issues.as_json(
labels: true,
only: [:id, :iid, :title, :confidential, :due_date],
include: {
assignee: { only: [:id, :name, :username], methods: [:avatar_url] },
milestone: { only: [:id, :title] }
},
user: current_user
)
end
private private
def authorize_read_board! def authorize_read_board!
......
...@@ -3,8 +3,8 @@ module Boards ...@@ -3,8 +3,8 @@ module Boards
class ListService < BaseService class ListService < BaseService
def execute def execute
issues = IssuesFinder.new(current_user, filter_params).execute issues = IssuesFinder.new(current_user, filter_params).execute
issues = without_board_labels(issues) unless list.movable? issues = without_board_labels(issues) unless movable_list?
issues = with_list_label(issues) if list.movable? issues = with_list_label(issues) if movable_list?
issues issues
end end
...@@ -15,7 +15,13 @@ module Boards ...@@ -15,7 +15,13 @@ module Boards
end end
def list def list
@list ||= board.lists.find(params[:id]) return @list if defined?(@list)
@list = board.lists.find(params[:id]) if params.key?(:id)
end
def movable_list?
@movable_list ||= list.present? && list.movable?
end end
def filter_params def filter_params
...@@ -40,7 +46,7 @@ module Boards ...@@ -40,7 +46,7 @@ module Boards
end end
def set_state def set_state
params[:state] = list.done? ? 'closed' : 'opened' params[:state] = list && list.done? ? 'closed' : 'opened'
end end
def board_label_ids def board_label_ids
......
...@@ -266,10 +266,8 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -266,10 +266,8 @@ constraints(ProjectUrlConstrainer.new) do
end end
resources :boards, only: [:index, :show] do resources :boards, only: [:index, :show] do
get :backlog, on: :member
scope module: :boards do scope module: :boards do
resources :issues, only: [:update] resources :issues, only: [:index, :update]
resources :lists, only: [:index, :create, :update, :destroy] do resources :lists, only: [:index, :create, :update, :destroy] do
collection do collection do
......
...@@ -18,23 +18,7 @@ describe Projects::Boards::IssuesController do ...@@ -18,23 +18,7 @@ describe Projects::Boards::IssuesController do
end end
describe 'GET index' do describe 'GET index' do
context 'with valid list id' do let(:johndoe) { create(:user, avatar: fixture_file_upload(File.join(Rails.root, 'spec/fixtures/dk.png'))) }
it 'returns issues that have the list label applied' do
johndoe = create(:user, avatar: fixture_file_upload(File.join(Rails.root, 'spec/fixtures/dk.png')))
issue = create(:labeled_issue, project: project, labels: [planning])
create(:labeled_issue, project: project, labels: [planning])
create(:labeled_issue, project: project, labels: [development], due_date: Date.tomorrow)
create(:labeled_issue, project: project, labels: [development], assignee: johndoe)
issue.subscribe(johndoe, project)
list_issues user: user, board: board, list: list2
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('issues')
expect(parsed_response.length).to eq 2
end
end
context 'with invalid board id' do context 'with invalid board id' do
it 'returns a not found 404 response' do it 'returns a not found 404 response' do
...@@ -44,11 +28,47 @@ describe Projects::Boards::IssuesController do ...@@ -44,11 +28,47 @@ describe Projects::Boards::IssuesController do
end end
end end
context 'with invalid list id' do context 'when list id is present' do
it 'returns a not found 404 response' do context 'with valid list id' do
list_issues user: user, board: board, list: 999 it 'returns issues that have the list label applied' do
issue = create(:labeled_issue, project: project, labels: [planning])
create(:labeled_issue, project: project, labels: [planning])
create(:labeled_issue, project: project, labels: [development], due_date: Date.tomorrow)
create(:labeled_issue, project: project, labels: [development], assignee: johndoe)
issue.subscribe(johndoe, project)
expect(response).to have_http_status(404) list_issues user: user, board: board, list: list2
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('issues')
expect(parsed_response.length).to eq 2
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
list_issues user: user, board: board, list: 999
expect(response).to have_http_status(404)
end
end
end
context 'when list id is missing' do
it 'returns opened issues without board labels applied' do
bug = create(:label, project: project, name: 'Bug')
create(:issue, project: project)
create(:labeled_issue, project: project, labels: [planning])
create(:labeled_issue, project: project, labels: [development])
create(:labeled_issue, project: project, labels: [bug])
list_issues user: user, board: board
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('issues')
expect(parsed_response.length).to eq 2
end end
end end
...@@ -65,13 +85,17 @@ describe Projects::Boards::IssuesController do ...@@ -65,13 +85,17 @@ describe Projects::Boards::IssuesController do
end end
end end
def list_issues(user:, board:, list:) def list_issues(user:, board:, list: nil)
sign_in(user) sign_in(user)
get :index, namespace_id: project.namespace.to_param, params = {
project_id: project.to_param, namespace_id: project.namespace.to_param,
board_id: board.to_param, project_id: project.to_param,
list_id: list.to_param board_id: board.to_param,
list_id: list.try(:to_param)
}
get :index, params.compact
end end
end end
......
...@@ -17,6 +17,10 @@ describe Boards::Issues::ListService, services: true do ...@@ -17,6 +17,10 @@ describe Boards::Issues::ListService, services: true do
let!(:list2) { create(:list, board: board, label: testing, position: 1) } let!(:list2) { create(:list, board: board, label: testing, position: 1) }
let!(:done) { create(:done_list, board: board) } let!(:done) { create(:done_list, board: board) }
let!(:opened_issue1) { create(:labeled_issue, project: project, labels: [bug]) }
let!(:opened_issue2) { create(:labeled_issue, project: project, labels: [p2]) }
let!(:reopened_issue1) { create(:issue, :reopened, project: project) }
let!(:list1_issue1) { create(:labeled_issue, project: project, labels: [p2, development]) } let!(:list1_issue1) { create(:labeled_issue, project: project, labels: [p2, development]) }
let!(:list1_issue2) { create(:labeled_issue, project: project, labels: [development]) } let!(:list1_issue2) { create(:labeled_issue, project: project, labels: [development]) }
let!(:list1_issue3) { create(:labeled_issue, project: project, labels: [development, p1]) } let!(:list1_issue3) { create(:labeled_issue, project: project, labels: [development, p1]) }
...@@ -40,6 +44,14 @@ describe Boards::Issues::ListService, services: true do ...@@ -40,6 +44,14 @@ describe Boards::Issues::ListService, services: true do
end end
context 'sets default order to priority' do context 'sets default order to priority' do
it 'returns opened issues when list id is missing' do
params = { board_id: board.id }
issues = described_class.new(project, user, params).execute
expect(issues).to eq [opened_issue2, reopened_issue1, opened_issue1]
end
it 'returns closed issues when listing issues from Done' do it 'returns closed issues when listing issues from Done' do
params = { board_id: board.id, id: done.id } params = { board_id: board.id, id: done.id }
......
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