Merge pull request #7893 from opf/bim/feature/bcf_api_topics_create
Bim/feature/bcf api topics create [ci skip]pull/7897/head
commit
3fc6c302dd
@ -0,0 +1,31 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Priority::InexistentPriority < IssuePriority; end |
@ -0,0 +1,31 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Status::InexistentStatus < Status; end |
@ -0,0 +1,32 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Type::InexistentType < Type |
||||
end |
@ -0,0 +1,31 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class User::InexistentUser < User; end |
@ -0,0 +1,43 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class BaseContract < ::ModelContract |
||||
attribute :uuid |
||||
attribute :work_package |
||||
attribute :index |
||||
|
||||
def validate |
||||
validate_user_allowed_to_manage |
||||
|
||||
super |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class CreateContract < BaseContract |
||||
private |
||||
|
||||
def validate_user_allowed_to_manage |
||||
unless model.project && user.allowed_to?(:manage_bcf, model.project) |
||||
errors.add :base, :error_unauthorized |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,50 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1::Endpoints |
||||
class Create < API::Utilities::Endpoints::Create |
||||
include ModifyMixin |
||||
|
||||
def present_success(_current_user, call) |
||||
render_representer |
||||
.new(call.result) |
||||
end |
||||
|
||||
def postprocess_errors(call) |
||||
Bcf::API::V2_1::Errors::ErrorMapper.map(super) |
||||
end |
||||
|
||||
private |
||||
|
||||
def deduce_process_service |
||||
"::Bcf::#{deduce_backend_namespace}::#{update_or_create}Service".constantize |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,46 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1::Endpoints |
||||
module ModifyMixin |
||||
private |
||||
|
||||
def deduce_parse_service |
||||
Bcf::API::V2_1::ParseResourceParamsService |
||||
end |
||||
|
||||
def deduce_in_and_out_representer |
||||
"::Bcf::API::V2_1::#{deduce_api_namespace}::SingleRepresenter".constantize |
||||
end |
||||
|
||||
alias_method :deduce_parse_representer, :deduce_in_and_out_representer |
||||
alias_method :deduce_render_representer, :deduce_in_and_out_representer |
||||
end |
||||
end |
@ -0,0 +1,64 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1::Errors |
||||
class ErrorMapper |
||||
extend ActiveModel::Naming |
||||
extend ActiveModel::Translation |
||||
|
||||
def read_attribute_for_validation(_attr) |
||||
nil |
||||
end |
||||
|
||||
def self.lookup_ancestors |
||||
[::Bcf::Issue] |
||||
end |
||||
|
||||
def self.map(original_errors) |
||||
mapped_errors = ActiveModel::Errors.new(new) |
||||
|
||||
original_errors.send(:error_symbols).each do |key, errors| |
||||
errors.map(&:first).each do |error| |
||||
mapped_errors.add(error_key_mapper(key), error) |
||||
end |
||||
end |
||||
|
||||
mapped_errors |
||||
end |
||||
|
||||
def self.i18n_scope |
||||
:activerecord |
||||
end |
||||
|
||||
def self.error_key_mapper(key) |
||||
{ subject: :title }[key] || key |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,51 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class CreateService < ::BaseServices::Create |
||||
private |
||||
|
||||
def before_perform(params) |
||||
wp_call = WorkPackages::CreateService |
||||
.new(user: user) |
||||
.call(params) |
||||
|
||||
if wp_call.success? |
||||
issue_params = { |
||||
work_package: wp_call.result |
||||
}.merge(params.slice(:stage, :labels, :index)) |
||||
|
||||
super(issue_params) |
||||
else |
||||
wp_call |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,34 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class SetAttributesService < ::BaseServices::SetAttributes |
||||
end |
||||
end |
@ -0,0 +1,162 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class TransformAttributesService |
||||
def call(attributes) |
||||
ServiceResult.new success: true, |
||||
result: work_package_attributes(attributes) |
||||
end |
||||
|
||||
private |
||||
|
||||
## |
||||
# BCF issues might have empty titles. OP needs one. |
||||
def title(attributes) |
||||
if attributes[:title] |
||||
attributes[:title] |
||||
elsif attributes[:import_options] |
||||
'(Imported BCF issue contained no title)' |
||||
end |
||||
end |
||||
|
||||
def author(project, attributes) |
||||
find_user_in_project(project, attributes[:author]) || User.system |
||||
end |
||||
|
||||
def assignee(project, attributes) |
||||
assignee = find_user_in_project(project, attributes[:assignee]) |
||||
|
||||
return assignee if assignee.present? |
||||
|
||||
missing_assignee(attributes[:assignee], attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Try to find the given user by mail in the project |
||||
def find_user_in_project(project, mail) |
||||
project.users.find_by(mail: mail) |
||||
end |
||||
|
||||
def type(project, attributes) |
||||
type_name = attributes[:type] |
||||
type = project.types.find_by(name: type_name) |
||||
|
||||
return type if type.present? |
||||
|
||||
missing_type(project, type_name, attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Handle unknown statuses during import |
||||
def status(attributes) |
||||
status_name = attributes[:status] |
||||
status = ::Status.find_by(name: status_name) |
||||
|
||||
return status if status.present? |
||||
|
||||
missing_status(status_name, attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Handle unknown priorities during import |
||||
def priority(attributes) |
||||
priority_name = attributes[:priority] |
||||
priority = ::IssuePriority.find_by(name: priority_name) |
||||
|
||||
return priority if priority.present? |
||||
|
||||
missing_priority(priority_name, attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Get mapped and raw attributes from MarkupExtractor |
||||
# and return all values that are non-nil |
||||
def work_package_attributes(attributes) |
||||
project = Project.find(attributes[:project_id]) |
||||
|
||||
{ |
||||
# Fixed attributes we know |
||||
project: project, |
||||
type: type(project, attributes), |
||||
|
||||
# Native attributes from the extractor |
||||
subject: title(attributes), |
||||
description: attributes[:description], |
||||
due_date: attributes[:due_date], |
||||
start_date: attributes[:start_date], |
||||
|
||||
# Mapped attributes |
||||
assigned_to: assignee(project, attributes), |
||||
status: status(attributes), |
||||
priority: priority(attributes) |
||||
}.compact |
||||
end |
||||
|
||||
def missing_status(status_name, import_options) |
||||
if import_options[:unknown_statuses_action] == 'use_default' |
||||
::Status.default |
||||
elsif import_options[:unknown_statuses_action] == 'chose' && |
||||
import_options[:unknown_statuses_chose_ids].any? |
||||
::Status.find_by(id: import_options[:unknown_statuses_chose_ids].first) |
||||
elsif status_name |
||||
Status::InexistentStatus.new |
||||
end |
||||
end |
||||
|
||||
def missing_priority(priority_name, import_options) |
||||
if import_options[:unknown_priorities_action] == 'use_default' |
||||
# NOP The 'use_default' case gets already covered by OP. |
||||
elsif import_options[:unknown_priorities_action] == 'chose' && |
||||
import_options[:unknown_priorities_chose_ids].any? |
||||
::IssuePriority.find_by(id: import_options[:unknown_priorities_chose_ids].first) |
||||
elsif priority_name |
||||
Priority::InexistentPriority.new |
||||
end |
||||
end |
||||
|
||||
def missing_type(project, type_name, import_options) |
||||
if import_options[:unknown_types_action] == 'use_default' |
||||
project.types.default&.first |
||||
elsif import_options[:unknown_types_action] == 'chose' && |
||||
import_options[:unknown_types_chose_ids].any? |
||||
project.types.find_by(id: import_options[:unknown_types_chose_ids].first) |
||||
elsif type_name |
||||
Type::InexistentType.new |
||||
end |
||||
end |
||||
|
||||
def missing_assignee(assignee_name, import_options) |
||||
if import_options[:invalid_people_action] != 'anonymize' && assignee_name |
||||
User::InexistentUser.new |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,9 @@ |
||||
class AddIssueColumns < ActiveRecord::Migration[6.0] |
||||
def change |
||||
change_table :bcf_issues do |i| |
||||
i.string :stage |
||||
i.integer :index |
||||
i.text :labels, array: true, default: [] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,45 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require_relative './shared_contract_examples' |
||||
|
||||
describe Bcf::Issues::CreateContract do |
||||
it_behaves_like 'issues contract' do |
||||
let(:issue) do |
||||
Bcf::Issue.new(uuid: issue_uuid, |
||||
work_package: issue_work_package, |
||||
stage: issue_stage, |
||||
index: issue_index, |
||||
labels: issue_labels) |
||||
end |
||||
let(:permissions) { [:manage_bcf] } |
||||
|
||||
subject(:contract) { described_class.new(issue, current_user) } |
||||
end |
||||
end |
@ -0,0 +1,129 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
shared_examples_for 'issues contract' do |
||||
let(:current_user) do |
||||
FactoryBot.build_stubbed(:user) |
||||
end |
||||
let!(:allowed_to) do |
||||
allow(current_user) |
||||
.to receive(:allowed_to?) do |permission, permission_project| |
||||
permissions.include?(permission) && project == permission_project |
||||
end |
||||
end |
||||
let(:issue_uuid) { 'issue uuid' } |
||||
let(:project) { FactoryBot.build_stubbed(:project) } |
||||
let(:issue_work_package) { FactoryBot.build_stubbed(:stubbed_work_package, project: project) } |
||||
let(:issue_work_package_id) do |
||||
id = 5 |
||||
|
||||
allow(WorkPackage) |
||||
.to receive(:find) |
||||
.with(id) |
||||
.and_return(issue_work_package) |
||||
|
||||
id |
||||
end |
||||
let(:issue_stage) { nil } |
||||
let(:issue_labels) { [] } |
||||
let(:issue_index) { 8 } |
||||
|
||||
before do |
||||
allow(issue) |
||||
.to receive(:project) |
||||
.and_return(project) |
||||
end |
||||
|
||||
def expect_valid(valid, symbols = {}) |
||||
expect(contract.validate).to eq(valid) |
||||
|
||||
symbols.each do |key, arr| |
||||
expect(contract.errors.symbols_for(key)).to match_array arr |
||||
end |
||||
end |
||||
|
||||
shared_examples 'is valid' do |
||||
it 'is valid' do |
||||
expect_valid(true) |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'is valid' |
||||
|
||||
context 'if the uuid is nil' do |
||||
let(:issue_uuid) { nil } |
||||
|
||||
it_behaves_like 'is valid' # as the uuid will be set |
||||
end |
||||
|
||||
context 'if the work_package_id is nil' do |
||||
let(:issue_work_package) { nil } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, work_package: %i(blank)) |
||||
end |
||||
end |
||||
|
||||
context 'if the user lacks permission' do |
||||
let(:permissions) { [] } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, base: %i(error_unauthorized)) |
||||
end |
||||
end |
||||
|
||||
context 'if the stage is nil' do |
||||
let(:issue_stage) { nil } |
||||
|
||||
it_behaves_like 'is valid' |
||||
end |
||||
|
||||
context 'if the stage is written' do |
||||
let(:issue_stage) { 'some stage' } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, stage: %i(error_readonly)) |
||||
end |
||||
end |
||||
|
||||
context 'if labels is written' do |
||||
let(:issue_labels) { %w(some labels) } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, labels: %i(error_readonly)) |
||||
end |
||||
end |
||||
|
||||
context 'if index is nil' do |
||||
let(:issue_index) { nil } |
||||
|
||||
it_behaves_like 'is valid' |
||||
end |
||||
end |
@ -0,0 +1,173 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Bcf::Issues::CreateService, type: :model do |
||||
let(:user) { FactoryBot.build_stubbed(:user) } |
||||
let(:contract_class) do |
||||
double('contract_class', '<=': true) |
||||
end |
||||
let(:issue_valid) { true } |
||||
let(:instance) do |
||||
described_class.new(user: user, |
||||
contract_class: contract_class) |
||||
end |
||||
let(:call_attributes) { { subject: 'Some name' } } |
||||
let(:set_attributes_success) do |
||||
true |
||||
end |
||||
let(:set_attributes_errors) do |
||||
double('set_attributes_errors') |
||||
end |
||||
let(:set_attributes_result) do |
||||
ServiceResult.new result: created_issue, |
||||
success: set_attributes_success, |
||||
errors: set_attributes_errors |
||||
end |
||||
let!(:created_work_package) do |
||||
FactoryBot.build_stubbed(:work_package) |
||||
end |
||||
let(:wp_create_errors) do |
||||
double('wp_create_errors') |
||||
end |
||||
let(:wp_create_result) do |
||||
ServiceResult.new result: created_work_package, |
||||
success: true, |
||||
errors: wp_create_errors |
||||
end |
||||
let!(:wp_create_service) do |
||||
wp_service = double('wp create service') |
||||
|
||||
allow(WorkPackages::CreateService) |
||||
.to receive(:new) |
||||
.with(user: user) |
||||
.and_return(wp_service) |
||||
|
||||
allow(wp_service) |
||||
.to receive(:call) |
||||
.and_return(wp_create_result) |
||||
|
||||
wp_service |
||||
end |
||||
let!(:created_issue) do |
||||
issue = FactoryBot.build_stubbed(:bcf_issue) |
||||
|
||||
allow(Bcf::Issue) |
||||
.to receive(:new) |
||||
.and_return(issue) |
||||
|
||||
allow(issue) |
||||
.to receive(:save) |
||||
.and_return(issue_valid) |
||||
|
||||
issue |
||||
end |
||||
let!(:set_attributes_service) do |
||||
service = double('set_attributes_service_instance') |
||||
|
||||
allow(Bcf::Issues::SetAttributesService) |
||||
.to receive(:new) |
||||
.with(user: user, |
||||
model: created_issue, |
||||
contract_class: contract_class) |
||||
.and_return(service) |
||||
|
||||
allow(service) |
||||
.to receive(:call) |
||||
.and_return(set_attributes_result) |
||||
end |
||||
|
||||
describe '#call' do |
||||
subject { instance.call(call_attributes) } |
||||
|
||||
it 'is successful' do |
||||
expect(subject.success?).to be_truthy |
||||
end |
||||
|
||||
it 'returns the result of the SetAttributesService' do |
||||
expect(subject) |
||||
.to eql set_attributes_result |
||||
end |
||||
|
||||
it 'persists the issue' do |
||||
expect(created_issue) |
||||
.to receive(:save) |
||||
.and_return(issue_valid) |
||||
|
||||
subject |
||||
end |
||||
|
||||
it 'creates a issue' do |
||||
expect(subject.result) |
||||
.to eql created_issue |
||||
end |
||||
|
||||
context 'if the SetAttributeService is unsuccessful' do |
||||
let(:set_attributes_success) { false } |
||||
|
||||
it 'is unsuccessful' do |
||||
expect(subject.success?).to be_falsey |
||||
end |
||||
|
||||
it 'returns the result of the SetAttributesService' do |
||||
expect(subject) |
||||
.to eql set_attributes_result |
||||
end |
||||
|
||||
it 'does not persist the changes' do |
||||
expect(created_issue) |
||||
.to_not receive(:save) |
||||
|
||||
subject |
||||
end |
||||
|
||||
it "exposes the contract's errors" do |
||||
subject |
||||
|
||||
expect(subject.errors).to eql set_attributes_errors |
||||
end |
||||
end |
||||
|
||||
context 'when the issue is invalid' do |
||||
let(:issue_valid) { false } |
||||
|
||||
it 'is unsuccessful' do |
||||
expect(subject.success?).to be_falsey |
||||
end |
||||
|
||||
it "exposes the issue's errors" do |
||||
subject |
||||
|
||||
expect(subject.errors).to eql created_issue.errors |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue