From e256fa0448ab191f754ccc2aed02d63736106fe5 Mon Sep 17 00:00:00 2001 From: Patrick Derichs Date: Wed, 11 Sep 2019 14:49:08 +0200 Subject: Add max issue count to lists Add spec for update of max_issue_count on lists Failing spec Rename migration file Add max_issue_count to schema.rb Add model validation for max_issue_count Add license check for max_issue_count Extract method create_list_attributes Remove validation for max_issue_count Add MR to changelog Remove unnecessary comment Remove unnecessary allow_null: false Remove CE changelog entry Remove possible null value for max_issue_count from schema definitions --- app/controllers/boards/lists_controller.rb | 6 +++++- app/services/boards/lists/create_service.rb | 6 +++++- app/services/boards/lists/update_service.rb | 12 ++++++++++-- db/migrate/20190901174200_add_max_issue_count_to_list.rb | 16 ++++++++++++++++ db/schema.rb | 1 + spec/fixtures/api/schemas/list.json | 3 ++- spec/fixtures/api/schemas/public_api/v4/board.json | 3 ++- spec/lib/gitlab/import_export/safe_model_attributes.yml | 1 + 8 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20190901174200_add_max_issue_count_to_list.rb diff --git a/app/controllers/boards/lists_controller.rb b/app/controllers/boards/lists_controller.rb index 08b4748d7e1..f9c30c95455 100644 --- a/app/controllers/boards/lists_controller.rb +++ b/app/controllers/boards/lists_controller.rb @@ -64,12 +64,16 @@ module Boards %i[label_id] end + def list_update_attrs + %i[collapsed position] + end + def create_list_params params.require(:list).permit(list_creation_attrs) end def update_list_params - params.require(:list).permit(:collapsed, :position) + params.require(:list).permit(list_update_attrs) end def serialize_as_json(resource) diff --git a/app/services/boards/lists/create_service.rb b/app/services/boards/lists/create_service.rb index 48d2d5abaec..695981fbabf 100644 --- a/app/services/boards/lists/create_service.rb +++ b/app/services/boards/lists/create_service.rb @@ -43,7 +43,11 @@ module Boards end def create_list(board, type, target, position) - board.lists.create(type => target, list_type: type, position: position) + board.lists.create(create_list_attributes(type, target, position)) + end + + def create_list_attributes(type, target, position) + { type => target, list_type: type, position: position } end end end diff --git a/app/services/boards/lists/update_service.rb b/app/services/boards/lists/update_service.rb index 2ddeb6f0bd8..35ce81d9968 100644 --- a/app/services/boards/lists/update_service.rb +++ b/app/services/boards/lists/update_service.rb @@ -5,15 +5,23 @@ module Boards class UpdateService < Boards::BaseService def execute(list) return not_authorized if preferences? && !can_read?(list) - return not_authorized if position? && !can_admin?(list) + return not_authorized if list_properties? && !can_admin?(list) - if update_preferences(list) || update_position(list) + if execute_by_params(list) success(list: list) else error(list.errors.messages, 422) end end + def execute_by_params(list) + update_preferences(list) || update_position(list) + end + + def list_properties? + position? + end + def update_preferences(list) return unless preferences? diff --git a/db/migrate/20190901174200_add_max_issue_count_to_list.rb b/db/migrate/20190901174200_add_max_issue_count_to_list.rb new file mode 100644 index 00000000000..59359f28d6a --- /dev/null +++ b/db/migrate/20190901174200_add_max_issue_count_to_list.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddMaxIssueCountToList < ActiveRecord::Migration[4.2] + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column_with_default :lists, :max_issue_count, :integer, default: 0 + end + + def down + remove_column :lists, :max_issue_count + end +end diff --git a/db/schema.rb b/db/schema.rb index 39faf1e651e..8b4a5caf2c9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1972,6 +1972,7 @@ ActiveRecord::Schema.define(version: 2019_09_12_061145) do t.datetime "updated_at", null: false t.integer "milestone_id" t.integer "user_id" + t.integer "max_issue_count", default: 0, null: false t.index ["board_id", "label_id"], name: "index_lists_on_board_id_and_label_id", unique: true t.index ["label_id"], name: "index_lists_on_label_id" t.index ["list_type"], name: "index_lists_on_list_type" diff --git a/spec/fixtures/api/schemas/list.json b/spec/fixtures/api/schemas/list.json index b76ec115293..7603892e198 100644 --- a/spec/fixtures/api/schemas/list.json +++ b/spec/fixtures/api/schemas/list.json @@ -35,7 +35,8 @@ } }, "title": { "type": "string" }, - "position": { "type": ["integer", "null"] } + "position": { "type": ["integer", "null"] }, + "max_issue_count": { "type": "integer" } }, "additionalProperties": true } diff --git a/spec/fixtures/api/schemas/public_api/v4/board.json b/spec/fixtures/api/schemas/public_api/v4/board.json index d667f1d631c..8dc3999baa2 100644 --- a/spec/fixtures/api/schemas/public_api/v4/board.json +++ b/spec/fixtures/api/schemas/public_api/v4/board.json @@ -76,7 +76,8 @@ "name": { "type": "string" } } }, - "position": { "type": ["integer", "null"] } + "position": { "type": ["integer", "null"] }, + "max_issue_count": { "type": "integer" } }, "additionalProperties": false } diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index e9750d23c53..51b8cffb85e 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -716,6 +716,7 @@ List: - updated_at - milestone_id - user_id +- max_issue_count ExternalPullRequest: - id - created_at -- cgit v1.2.3