Commit f31dbe5b authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'winh-boards-helper-ee' into 'master'

Move current issue board serialization to core

See merge request gitlab-org/gitlab-ee!14609
parents be996ebc e3925530
......@@ -99,8 +99,12 @@ module BoardsHelper
recent_project_boards_path(@project) if current_board_parent.is_a?(Project)
end
def serializer
CurrentBoardSerializer.new
end
def current_board_json
board.to_json
serializer.represent(board).as_json
end
end
......
......@@ -3,10 +3,6 @@
class CurrentBoardEntity < Grape::Entity
expose :id
expose :name
expose :milestone_id
expose :weight
expose :label_ids
expose :milestone, using: BoardMilestoneEntity
expose :assignee, using: BoardAssigneeEntity
expose :labels, using: BoardLabelEntity
end
CurrentBoardEntity.prepend(EE::CurrentBoardEntity)
......@@ -4,10 +4,6 @@ module EE
module BoardsHelper
extend ::Gitlab::Utils::Override
def parent
@group || @project
end
override :board_list_data
def board_list_data
super.merge(list_milestone_path: board_milestones_path(board, :json),
......@@ -21,44 +17,27 @@ module EE
!@project.feature_available?(:issue_board_focus_mode)))
data = {
recent_boards_endpoint: recent_boards_path,
board_milestone_title: board.milestone&.name,
board_milestone_id: board.milestone_id,
board_assignee_username: board.assignee&.username,
label_ids: board.label_ids,
labels: board.labels.to_json(only: [:id, :title, :color, :text_color] ),
board_weight: board.weight,
focus_mode_available: parent.feature_available?(:issue_board_focus_mode),
weight_feature_available: parent.feature_available?(:issue_weights).to_s,
focus_mode_available: current_board_parent.feature_available?(:issue_board_focus_mode),
weight_feature_available: current_board_parent.feature_available?(:issue_weights).to_s,
show_promotion: show_feature_promotion,
scoped_labels: parent.feature_available?(:scoped_labels)&.to_s,
scoped_labels: current_board_parent.feature_available?(:scoped_labels)&.to_s,
scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels')
}
super.merge(data)
end
override :recent_boards_path
def recent_boards_path
parent.is_a?(Group) ? recent_group_boards_path(@group) : recent_project_boards_path(@project)
end
def serializer
CurrentBoardSerializer.new
end
def current_board
board = @board || @boards.first
serializer.represent(board).as_json
end
return recent_group_boards_path(@group) if current_board_parent.is_a?(Group)
override :boards_link_text
def boards_link_text
if parent.multiple_issue_boards_available?
s_("IssueBoards|Boards")
else
s_("IssueBoards|Board")
end
super
end
end
end
# frozen_string_literal: true
module EE
module CurrentBoardEntity
extend ActiveSupport::Concern
prepended do
expose :milestone_id
expose :weight
expose :label_ids
expose :milestone, using: BoardMilestoneEntity
expose :assignee, using: BoardAssigneeEntity
expose :labels, using: BoardLabelEntity
end
end
end
......@@ -2,7 +2,7 @@
- milestone_filter_opts = { format: :json }
- milestone_filter_opts = milestone_filter_opts.merge(only_group_milestones: true) if board.group_board?
#js-multiple-boards-switcher.inline.boards-switcher{ data: { current_board: current_board.to_json,
#js-multiple-boards-switcher.inline.boards-switcher{ data: { current_board: current_board_json.to_json,
milestone_path: milestones_filter_path(milestone_filter_opts),
board_base_url: board_base_url,
has_missing_boards: (!multiple_boards_available? && current_board_parent.boards.size > 1).to_s,
......
......@@ -16,8 +16,8 @@ describe BoardsHelper do
end
end
describe '#current_board' do
let(:board_json) { helper.current_board }
describe '#current_board_json' do
let(:board_json) { helper.current_board_json }
let(:user) { create(:user) }
let(:label1) { create(:label, name: "feijoa") }
let(:label2) { create(:label, name: "pineapple") }
......@@ -29,12 +29,5 @@ describe BoardsHelper do
expect(board_json).to match_schema('current-board', dir: 'ee')
end
it 'can serialise with a basic set of attributes' do
board = create(:board, project: project)
assign(:board, board)
expect(board_json).to match_schema('current-board', dir: 'ee')
end
end
end
{
"type": "object",
"allOf": [
{ "$ref": "board.json" },
{
"required" : [
"id",
"name"
],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
}
}
]
}
require 'spec_helper'
describe BoardsHelper do
set(:project) { create(:project) }
describe '#build_issue_link_base' do
context 'project board' do
it 'returns correct path for project board' do
@project = create(:project)
@project = project
@board = create(:board, project: @project)
expect(build_issue_link_base).to eq("/#{@project.namespace.path}/#{@project.path}/issues")
......@@ -31,7 +33,6 @@ describe BoardsHelper do
describe '#board_data' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:board) { create(:board, project: project) }
before do
......@@ -46,4 +47,15 @@ describe BoardsHelper do
expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(board))
end
end
describe '#current_board_json' do
let(:board_json) { helper.current_board_json }
it 'can serialise with a basic set of attributes' do
board = create(:board, project: project)
assign(:board, board)
expect(board_json).to match_schema('current-board')
end
end
end
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