OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
wip - bcf api topic#create
ulfertsdccd6c0b92d9
diff --git a/app/contracts/work_packages/create_contract.rb b/app/contracts/work_packages/create_contract.rbindex 2ac6bfa863d..f191c547693 100644--- a/app/contracts/work_packages/create_contract.rb+++ b/app/contracts/work_packages/create_contract.rb@@ -32,8 +32,6 @@ require 'work_packages/base_contract'module WorkPackagesclass CreateContract < BaseContract- # TODO: Think about whether this can be removed- # as it is unwriteable. So why bother checking for the correct authorattribute :author_id,writeable: false doerrors.add :author_id, :invalid if model.author != userdiff --git a/app/services/work_packages/create_service.rb b/app/services/work_packages/create_service.rbindex c8e35756bc4..ca4b6951210 100644--- a/app/services/work_packages/create_service.rb+++ b/app/services/work_packages/create_service.rb@@ -74,7 +74,7 @@ class WorkPackages::CreateServiceenddef set_attributes(attributes, wp)- WorkPackages::SetAttributesService+ attributes_service_class.new(user: user,model: wp,contract_class: contract_class)@@ -96,4 +96,8 @@ class WorkPackages::CreateServiceresultend++ def attributes_service_class+ ::WorkPackages::SetAttributesService+ endenddiff --git a/modules/bcf/app/contracts/bcf/issues/base_contract.rb b/modules/bcf/app/contracts/bcf/issues/base_contract.rbnew file mode 100644index 00000000000..cb5f6930dec--- /dev/null+++ b/modules/bcf/app/contracts/bcf/issues/base_contract.rb@@ -0,0 +1,42 @@+#-- 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++ def validate+ validate_user_allowed_to_manage++ super+ end+ end+enddiff --git a/modules/bcf/app/contracts/bcf/issues/create_contract.rb b/modules/bcf/app/contracts/bcf/issues/create_contract.rbnew file mode 100644index 00000000000..dc46229c0b3--- /dev/null+++ b/modules/bcf/app/contracts/bcf/issues/create_contract.rb@@ -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+enddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/create.rb b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/create.rbnew file mode 100644index 00000000000..f8e346cc0d9--- /dev/null+++ b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/create.rb@@ -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+ class Create < API::Utilities::Endpoints::Create+ include ModifyMixin++ def present_success(_current_user, call)+ render_representer+ .new(call.result)+ end++ private++ def deduce_process_service+ "::Bcf::#{deduce_backend_namespace}::#{update_or_create}Service".constantize+ end+ end+enddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/modify_mixin.rb b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/modify_mixin.rbnew file mode 100644index 00000000000..7d5fd4fdd1a--- /dev/null+++ b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/modify_mixin.rb@@ -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+enddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/update.rb b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/update.rbindex 537270d9499..dff9c2e14f5 100644--- a/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/update.rb+++ b/modules/bcf/app/controllers/bcf/api/v2_1/endpoints/update.rb@@ -30,22 +30,11 @@module Bcf::API::V2_1::Endpointsclass Update < API::Utilities::Endpoints::Update+ include ModifyMixin+def present_success(_current_user, call)render_representer.new(call.result)end-- 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_representerendenddiff --git a/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rbindex ac5f3dba024..06231a49b43 100644--- a/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb+++ b/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb@@ -47,6 +47,15 @@ module Bcf::API::V2_1scope: -> { topics }).mount+ post &::Bcf::API::V2_1::Endpoints::Create+ .new(model: Bcf::Issue,+ api_name: 'Topics',+ params_modifier: ->(attributes) {+ attributes[:project_id] = @project.id+ attributes+ })+ .mount+route_param :uuid, regexp: /\A[a-f0-9\-]+\z/ doafter_validation do@issue = topics.find_by_uuid!(params[:uuid])diff --git a/modules/bcf/app/models/bcf/issue.rb b/modules/bcf/app/models/bcf/issue.rbindex c7493e1f11d..eefd74f6ac8 100644--- a/modules/bcf/app/models/bcf/issue.rb+++ b/modules/bcf/app/models/bcf/issue.rb@@ -9,6 +9,8 @@ module Bcfafter_update :invalidate_markup_cache+ validates :work_package, presence: true+class << selfdef with_markupselect '*',diff --git a/modules/bcf/app/services/bcf/issues/create_service.rb b/modules/bcf/app/services/bcf/issues/create_service.rbnew file mode 100644index 00000000000..7c44116e796--- /dev/null+++ b/modules/bcf/app/services/bcf/issues/create_service.rb@@ -0,0 +1,47 @@+#-- 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 = Bcf::WorkPackages::CreateService+ .new(user: user)+ .call(params)++ issue_params = {+ work_package: wp_call.result+ }++ super(issue_params)+ end+ end+enddiff --git a/modules/bcf/app/services/bcf/issues/set_attributes_service.rb b/modules/bcf/app/services/bcf/issues/set_attributes_service.rbnew file mode 100644index 00000000000..db50aa742d7--- /dev/null+++ b/modules/bcf/app/services/bcf/issues/set_attributes_service.rb@@ -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+enddiff --git a/modules/bcf/app/services/bcf/work_packages/create_service.rb b/modules/bcf/app/services/bcf/work_packages/create_service.rbnew file mode 100644index 00000000000..fb2fd8c5020--- /dev/null+++ b/modules/bcf/app/services/bcf/work_packages/create_service.rb@@ -0,0 +1,39 @@+#-- 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::WorkPackages+ class CreateService < ::WorkPackages::CreateService+ private++ def attributes_service_class+ ::Bcf::WorkPackages::SetAttributesService+ end+ end+enddiff --git a/modules/bcf/app/services/bcf/work_packages/set_attributes_service.rb b/modules/bcf/app/services/bcf/work_packages/set_attributes_service.rbnew file mode 100644index 00000000000..268f8e2b7c7--- /dev/null+++ b/modules/bcf/app/services/bcf/work_packages/set_attributes_service.rb@@ -0,0 +1,113 @@+#-- 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::WorkPackages+ class SetAttributesService < ::WorkPackages::SetAttributesService+ private++ def set_attributes(attributes)+ super(work_package_attributes(attributes))+ end++ def author(project, attributes)+ find_user_in_project(project, attributes[:author]) || User.system+ end++ def assignee(project, attributes)+ find_user_in_project(project, attributes[:assignee])+ 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(attributes)+ type_name = attributes[:type]+ type = ::Type.find_by(name: type_name)++ return type if type.present?++ import_options = attributes[:import_options]++ return ::Type.default&.first if !import_options || import_options[:unknown_types_action] == 'default'++ if import_options[:unknown_types_action] == 'chose' &&+ import_options[:unknown_types_chose_ids].any?+ ::Type.find_by(id: import_options[:unknown_types_chose_ids].first)+ else+ ServiceResult.new success: false,+ errors: issue.errors,+ result: issue+ end+ end++ def start_date(attributes)+ extractor.creation_date.to_date unless is_update+ 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(attributes),++ # Native attributes from the extractor+ subject: attributes[:title],+ description: attributes[:description],+ due_date: attributes[:due_date],+ start_date: attributes[:start_date],++ # Mapped attributes+ assigned_to: assignee(project, attributes),+ status_id: statuses.fetch(attributes[:status], statuses[:default]),+ priority_id: priorities.fetch(attributes[:priority], priorities[:default])+ }.compact+ end++ ##+ # Keep a hash map of current status ids for faster lookup+ def statuses+ @statuses ||= Hash[Status.pluck(:name, :id)].merge(default: Status.default.id)+ end++ ##+ # Keep a hash map of current status ids for faster lookup+ def priorities+ @priorities ||= Hash[IssuePriority.pluck(:name, :id)].merge(default: IssuePriority.default.try(:id))+ end+ end+enddiff --git a/modules/bcf/lib/open_project/bcf/bcf_xml/issue_reader.rb b/modules/bcf/lib/open_project/bcf/bcf_xml/issue_reader.rbindex d6fbe388aec..71bc8de5f7f 100644--- a/modules/bcf/lib/open_project/bcf/bcf_xml/issue_reader.rb+++ b/modules/bcf/lib/open_project/bcf/bcf_xml/issue_reader.rb@@ -156,9 +156,7 @@ module OpenProject::Bcf::BcfXml.merge(send_notifications: false).symbolize_keys)- if call.success?- force_overwrite(call.result)- end+ force_overwrite(call.result) if call.success?callenddiff --git a/modules/bcf/lib/open_project/bcf/bcf_xml/issue_writer.rb b/modules/bcf/lib/open_project/bcf/bcf_xml/issue_writer.rbindex 63bfd94ee10..1304f642677 100644--- a/modules/bcf/lib/open_project/bcf/bcf_xml/issue_writer.rb+++ b/modules/bcf/lib/open_project/bcf/bcf_xml/issue_writer.rb@@ -250,7 +250,7 @@ module OpenProject::Bcf::BcfXmldef find_or_initialize_issue::Bcf::Issue.find_or_initialize_by(work_package: work_package)end-+def to_bcf_datetime(date_time)date_time.utc.iso8601enddiff --git a/modules/bcf/spec/contracts/bcf/issues/create_contract_spec.rb b/modules/bcf/spec/contracts/bcf/issues/create_contract_spec.rbnew file mode 100644index 00000000000..fec0fe166b7--- /dev/null+++ b/modules/bcf/spec/contracts/bcf/issues/create_contract_spec.rb@@ -0,0 +1,48 @@+#-- 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)+ end+ let(:permissions) { [:manage_bcf] }+ let!(:allowed_to) do+ allow(current_user)+ .to receive(:allowed_to?) do |permission, project|+ permissions.include?(permission) && project == project+ end+ end++ subject(:contract) { described_class.new(issue, current_user) }+ end+enddiff --git a/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rb b/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rbnew file mode 100644index 00000000000..a7a4d6ce4d4--- /dev/null+++ b/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rb@@ -0,0 +1,98 @@+#-- 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++ 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+enddiff --git a/modules/bcf/spec/factories/bcf_issue_factory.rb b/modules/bcf/spec/factories/bcf_issue_factory.rbindex d5cac7d2784..27aa0c267f3 100644--- a/modules/bcf/spec/factories/bcf_issue_factory.rb+++ b/modules/bcf/spec/factories/bcf_issue_factory.rb@@ -1,20 +1,15 @@+#-- encoding: UTF-8+#-- copyright-# OpenProject Backlogs Plugin-#-# Copyright (C)2013-2014 the OpenProject Foundation (OPF)-# Copyright (C)2011 Stephan Eckardt, Tim Felgentreff, Marnen Laibow-Koser, Sandro Munda-# Copyright (C)2010-2011 friflaj-# Copyright (C)2010 Maxime Guilbot, Andrew Vit, Joakim Kolsjö, ibussieres, Daniel Passos, Jason Vasquez, jpic, Emiliano Heyns-# Copyright (C)2009-2010 Mark Maglana-# Copyright (C)2009 Joe Heck, Nate Lowrie+# 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.+# 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 Backlogs is a derivative work based on ChiliProject Backlogs.-# The copyright follows:-# Copyright (C) 2010-2011 - Emiliano Heyns, Mark Maglana, friflaj-# Copyright (C) 2011 - Jens Ulferts, Gregor Schmidt - Finn GmbH - Berlin, Germany+# 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@@ -30,7 +25,7 @@# 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.+# See docs/COPYRIGHT.rdoc for more details.#++FactoryBot.define dodiff --git a/modules/bcf/spec/requests/api/bcf/v2_1/shared_responses.rb b/modules/bcf/spec/requests/api/bcf/v2_1/shared_responses.rbindex bf22d087bc7..5eabcdfb2db 100644--- a/modules/bcf/spec/requests/api/bcf/v2_1/shared_responses.rb+++ b/modules/bcf/spec/requests/api/bcf/v2_1/shared_responses.rb@@ -27,9 +27,9 @@#++shared_examples_for 'bcf api successful response' do- it 'responds 200 OK' do+ it 'has a successful status' doexpect(subject.status)- .to eql 200+ .to eql(defined?(expected_status) ? expected_status : 200)endit 'returns the resource' dodiff --git a/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rbindex 5d79bdf1c2c..35661febd35 100644--- a/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb+++ b/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb@@ -38,20 +38,25 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_malet(:view_only_user) doFactoryBot.create(:user,member_in_project: project,- member_with_permissions: [:view_linked_issues])+ member_with_permissions: %i[view_linked_issues view_work_packages])endlet(:only_member_user) doFactoryBot.create(:user,member_in_project: project,member_with_permissions: [])end+ let(:edit_member_user) do+ FactoryBot.create(:user,+ member_in_project: project,+ member_with_permissions: %i[manage_bcf add_work_packages view_linked_issues])+ endlet(:non_member_user) doFactoryBot.create(:user)endlet(:project) doFactoryBot.create(:project,- enabled_module_names: [:bcf])+ enabled_module_names: %i[bcf work_package_tracking])endlet(:work_package) { FactoryBot.create(:work_package, project: project) }let(:bcf_issue) { FactoryBot.create(:bcf_issue, work_package: work_package) }@@ -165,4 +170,60 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_mait_behaves_like 'bcf api not allowed response'endend++ describe 'POST /api/bcf/2.1/projects/:project_id/topics' do+ let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics" }+ let(:current_user) { edit_member_user }+ let(:type) do+ FactoryBot.create(:type).tap do |t|+ project.types << t+ end+ end+ let(:status) do+ FactoryBot.create(:status)+ end+ let!(:default_status) do+ FactoryBot.create(:default_status)+ end+ let!(:priority) do+ FactoryBot.create(:priority)+ end+ let!(:default_priority) do+ FactoryBot.create(:default_priority)+ end+ let(:params) do+ {+ topic_type: type.name,+ topic_status: status.name,+ title: 'BCF topic 101',+ labels: [],+ assigned_to: view_only_user+ }+ end++ before do+ login_as(current_user)+ post path, params.to_json+ end++ it_behaves_like 'bcf api successful response' do+ let(:expected_status) { 201 }+ let(:expected_body) do+ issue = Bcf::Issue.last+ work_package = WorkPackage.last++ {+ guid: issue.uuid,+ topic_type: type.name,+ topic_status: status.name,+ title: 'BCF topic 101',+ labels: [],+ reference_links: [+ api_v3_paths.work_package(work_package.id)+ ],+ assigned_to: view_only_user.name+ }+ end+ end+ endenddiff --git a/spec/services/projects/set_attributes_service_spec.rb b/spec/services/projects/set_attributes_service_spec.rbindex 9e1574c6d4f..fa51b5ebe9c 100644--- a/spec/services/projects/set_attributes_service_spec.rb+++ b/spec/services/projects/set_attributes_service_spec.rb@@ -69,11 +69,11 @@ describe Projects::SetAttributesService, type: :model dobefore doallow(project).to receive(:valid?)- .and_return(project_valid)+ .and_return(project_valid)expect(contract_instance).to receive(:validate)- .and_return(contract_valid)+ .and_return(contract_valid)endsubject { instance.call(call_attributes) }diff --git a/spec/support/matchers/be_html_eql.rb b/spec/support/matchers/be_html_eql.rbindex b8004b8c6d1..f0d4af5c989 100644--- a/spec/support/matchers/be_html_eql.rb+++ b/spec/support/matchers/be_html_eql.rb@@ -56,11 +56,11 @@@path = path + ' > *'end- should_message = -> (actual) do+ should_message = ->(actual) do['expected:', expected.to_s, 'got:', actual.to_s].join("\n")end- should_not_message = -> (actual) do+ should_not_message = ->(actual) do['expected:', actual.to_s, 'not to be equivalent to:', expected.to_s].join("\n")end