Commit ff1d44fe authored by Simon Knox's avatar Simon Knox

Merge branch '2518-saved-configuration-for-issue-board' of...

Merge branch '2518-saved-configuration-for-issue-board' of gitlab.com:gitlab-org/gitlab-ee into 2518-saved-configuration-for-issue-board
parents db3266f7 71f46a2c
class BoardAssignee < ActiveRecord::Base
belongs_to :board
belongs_to :assignee, class_name: 'User'
validates :board, presence: true
validates :assignee, presence: true
end
class BoardFilterLabel < ActiveRecord::Base
class BoardLabel < ActiveRecord::Base
belongs_to :board
belongs_to :label
......
......@@ -8,7 +8,14 @@ module Boards
params.delete(:weight)
end
set_assignee
board.update(params)
end
def set_assignee
assignee = User.find_by(id: params.delete(:assignee_id))
params.merge!(assignee: assignee)
end
end
end
class AddBoardFilterFields < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column :boards, :weight, :integer, index: true
add_reference :boards, :assignee, index: true
add_concurrent_foreign_key :boards, :users, column: :assignee_id, on_delete: :nullify
end
def down
remove_column :boards, :weight
remove_foreign_key :boards, column: :assignee_id
remove_reference :boards, :assignee
end
end
class AddWeightToBoards < ActiveRecord::Migration
DOWNTIME = false
disable_ddl_transaction!
def change
add_column :boards, :weight, :integer, index: true
end
end
class CreateBoardFilterLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
create_table :board_filter_labels do |t|
t.integer :board_id, null: false, index: true
t.integer :label_id, null: false, index: true
end
add_index :board_filter_labels, [:board_id, :label_id], unique: true
add_concurrent_foreign_key :board_filter_labels, :boards, column: :board_id, on_delete: :cascade
add_concurrent_foreign_key :board_filter_labels, :labels, column: :label_id, on_delete: :cascade
end
def down
drop_table :board_filter_labels
end
end
class CreateBoardLabels < ActiveRecord::Migration
DOWNTIME = false
disable_ddl_transaction!
def change
create_table :board_labels do |t|
t.references :board, index: true, foreign_key: { on_delete: :cascade }, null: false
t.references :label, index: true, foreign_key: { on_delete: :cascade }, null: false
t.index [:board_id, :label_id], unique: true
end
end
end
class CreateBoardAssignees < ActiveRecord::Migration
DOWNTIME = false
disable_ddl_transaction!
def change
create_table :board_assignees do |t|
t.references :board, index: true, foreign_key: { on_delete: :cascade }, null: false
t.integer :assignee_id, null: false, index: true
t.foreign_key :users, column: :assignee_id, on_delete: :cascade
t.index [:board_id, :assignee_id], unique: true
end
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170926203418) do
ActiveRecord::Schema.define(version: 20171010095526) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -214,14 +214,23 @@ ActiveRecord::Schema.define(version: 20170926203418) do
add_index "award_emoji", ["awardable_type", "awardable_id"], name: "index_award_emoji_on_awardable_type_and_awardable_id", using: :btree
add_index "award_emoji", ["user_id", "name"], name: "index_award_emoji_on_user_id_and_name", using: :btree
create_table "board_filter_labels", force: :cascade do |t|
create_table "board_assignees", force: :cascade do |t|
t.integer "board_id", null: false
t.integer "assignee_id", null: false
end
add_index "board_assignees", ["assignee_id"], name: "index_board_assignees_on_assignee_id", using: :btree
add_index "board_assignees", ["board_id", "assignee_id"], name: "index_board_assignees_on_board_id_and_assignee_id", unique: true, using: :btree
add_index "board_assignees", ["board_id"], name: "index_board_assignees_on_board_id", using: :btree
create_table "board_labels", force: :cascade do |t|
t.integer "board_id", null: false
t.integer "label_id", null: false
end
add_index "board_filter_labels", ["board_id", "label_id"], name: "index_board_filter_labels_on_board_id_and_label_id", unique: true, using: :btree
add_index "board_filter_labels", ["board_id"], name: "index_board_filter_labels_on_board_id", using: :btree
add_index "board_filter_labels", ["label_id"], name: "index_board_filter_labels_on_label_id", using: :btree
add_index "board_labels", ["board_id", "label_id"], name: "index_board_labels_on_board_id_and_label_id", unique: true, using: :btree
add_index "board_labels", ["board_id"], name: "index_board_labels_on_board_id", using: :btree
add_index "board_labels", ["label_id"], name: "index_board_labels_on_label_id", using: :btree
create_table "boards", force: :cascade do |t|
t.integer "project_id"
......@@ -231,10 +240,8 @@ ActiveRecord::Schema.define(version: 20170926203418) do
t.integer "milestone_id"
t.integer "group_id"
t.integer "weight"
t.integer "assignee_id"
end
add_index "boards", ["assignee_id"], name: "index_boards_on_assignee_id", using: :btree
add_index "boards", ["group_id"], name: "index_boards_on_group_id", using: :btree
add_index "boards", ["milestone_id"], name: "index_boards_on_milestone_id", using: :btree
add_index "boards", ["project_id"], name: "index_boards_on_project_id", using: :btree
......@@ -2059,11 +2066,12 @@ ActiveRecord::Schema.define(version: 20170926203418) do
add_foreign_key "approvals", "merge_requests", name: "fk_310d714958", on_delete: :cascade
add_foreign_key "approver_groups", "namespaces", column: "group_id", on_delete: :cascade
add_foreign_key "board_filter_labels", "boards", name: "fk_53e44f3a07", on_delete: :cascade
add_foreign_key "board_filter_labels", "labels", name: "fk_91e18fdcee", on_delete: :cascade
add_foreign_key "board_assignees", "boards", on_delete: :cascade
add_foreign_key "board_assignees", "users", column: "assignee_id", on_delete: :cascade
add_foreign_key "board_labels", "boards", on_delete: :cascade
add_foreign_key "board_labels", "labels", on_delete: :cascade
add_foreign_key "boards", "namespaces", column: "group_id", name: "fk_1e9a074a35", on_delete: :cascade
add_foreign_key "boards", "projects", name: "fk_f15266b5f9", on_delete: :cascade
add_foreign_key "boards", "users", column: "assignee_id", name: "fk_2a3450e77c", on_delete: :nullify
add_foreign_key "chat_teams", "namespaces", on_delete: :cascade
add_foreign_key "ci_builds", "ci_pipelines", column: "auto_canceled_by_id", name: "fk_a2141b1522", on_delete: :nullify
add_foreign_key "ci_builds", "ci_stages", column: "stage_id", name: "fk_3a9eaa254d", on_delete: :cascade
......
......@@ -5,10 +5,15 @@ module EE
prepended do
belongs_to :group
belongs_to :milestone
belongs_to :assignee, class_name: 'User'
has_many :board_filter_labels
has_many :labels, through: :board_filter_labels
has_many :board_labels
# These can safely be changed to has_many when we support
# multiple assignees on the board configuration.
has_one :board_assignee
has_one :assignee, through: :board_assignee
has_many :labels, through: :board_labels
validates :name, presence: true
validates :group, presence: true, unless: :project
......
FactoryGirl.define do
factory :board_filter_label do
factory :board_label do
association :board
association :label
end
......
require 'spec_helper'
describe BoardAssignee do
describe 'relationships' do
it { is_expected.to belong_to(:board) }
it { is_expected.to belong_to(:assignee).class_name('User') }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:board) }
it { is_expected.to validate_presence_of(:assignee) }
end
end
......@@ -4,9 +4,10 @@ describe Board do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:milestone) }
it { is_expected.to belong_to(:assignee).class_name('User') }
it { is_expected.to have_many(:board_filter_labels) }
it { is_expected.to have_many(:labels).through(:board_filter_labels) }
it { is_expected.to have_one(:board_assignee) }
it { is_expected.to have_one(:assignee).through(:board_assignee) }
it { is_expected.to have_many(:board_labels) }
it { is_expected.to have_many(:labels).through(:board_labels) }
it { is_expected.to have_many(:lists).order(list_type: :asc, position: :asc).dependent(:delete_all) }
end
......
......@@ -25,24 +25,33 @@ describe Boards::UpdateService do
expect(service.execute(board)).to eq false
end
it 'updates the milestone with issue board milestones enabled' do
it 'updates the configuration params when scoped issue board is enabled' do
stub_licensed_features(scoped_issue_board: true)
assignee = create(:user)
milestone = create(:milestone, project: project)
label = create(:label, project: project)
service = described_class.new(project, double, milestone_id: milestone.id)
service = described_class.new(project, double,
milestone_id: milestone.id,
assignee_id: assignee.id,
label_ids: [label.id])
service.execute(board)
expect(board.reload.milestone).to eq(milestone)
expect(board.reload).to have_attributes(milestone: milestone,
assignee: assignee,
labels: [label])
end
it 'filters unpermitted params when scoped issue board is not enabled' do
stub_licensed_features(scoped_issue_board: false)
params = { milestone_id: double, assignee_id: double, label_ids: double, weight: double }
expect(board).to receive(:update).with({})
service = described_class.new(project, double, params)
service.execute(board)
expect(board.reload).to have_attributes(milestone: nil,
assignee: nil,
labels: [])
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