Skip to content

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

return errors on unsupported topic properties

ulferts176019f96f29
diff --git a/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb b/modules/bcf/app/controllers/bcf/api/v2_1/topics_api.rb
index 94a8d032a4e..f891041e5f0 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
@@ -43,9 +43,7 @@ module Bcf::API::V2_1
.result
attributes
- .slice(:stage,
- :index,
- :labels)
+ .slice(*Bcf::Issue::SETTABLE_ATTRIBUTES)
.merge(wp_attributes)
end
diff --git a/modules/bcf/app/models/bcf/issue.rb b/modules/bcf/app/models/bcf/issue.rb
index 4dee1c6f3bc..ba969cb5ad4 100644
--- a/modules/bcf/app/models/bcf/issue.rb
+++ b/modules/bcf/app/models/bcf/issue.rb
@@ -1,6 +1,9 @@
module Bcf
class Issue < ActiveRecord::Base
include InitializeWithUuid
+ include Concerns::VirtualAttribute
+
+ SETTABLE_ATTRIBUTES = %i[stage labels index reference_links bim_snippet].freeze
belongs_to :work_package
has_one :project, through: :work_package
@@ -11,6 +14,17 @@ module Bcf
validates :work_package, presence: true
+ # The virtual attributes are defined so that an API client can attempt to set them.
+ # However, currently such information is not persisted. But adding them fits better into the code
+ # and might later on be replaced by an actual storing..
+ virtual_attribute :reference_links do
+ []
+ end
+
+ virtual_attribute :bim_snippet do
+ {}
+ end
+
class << self
def of_project(project)
includes(:work_package)
diff --git a/modules/bcf/app/representers/bcf/api/v2_1/topics/single_representer.rb b/modules/bcf/app/representers/bcf/api/v2_1/topics/single_representer.rb
index 18353e0d2e6..5578f1fade3 100644
--- a/modules/bcf/app/representers/bcf/api/v2_1/topics/single_representer.rb
+++ b/modules/bcf/app/representers/bcf/api/v2_1/topics/single_representer.rb
@@ -130,6 +130,10 @@ module Bcf::API::V2_1
self.due_date = date
}
+ # Required only so that we can register a user wanting to set the snippets. We do not support setting it though.
+ property :bim_snippet,
+ skip_render: true
+
def datetime_formatter
::API::V3::Utilities::DateTimeFormatter
end
diff --git a/modules/bcf/app/services/bcf/issues/create_service.rb b/modules/bcf/app/services/bcf/issues/create_service.rb
index cd5abb21a35..e09ddb084ab 100644
--- a/modules/bcf/app/services/bcf/issues/create_service.rb
+++ b/modules/bcf/app/services/bcf/issues/create_service.rb
@@ -40,7 +40,7 @@ module Bcf::Issues
if wp_call.success?
issue_params = {
work_package: wp_call.result
- }.merge(params.slice(:stage, :labels, :index))
+ }.merge(params.slice(*Bcf::Issue::SETTABLE_ATTRIBUTES))
super(issue_params)
else
diff --git a/modules/bcf/app/services/bcf/issues/transform_attributes_service.rb b/modules/bcf/app/services/bcf/issues/transform_attributes_service.rb
index bbc2e0c1b28..fa18d84f94b 100644
--- a/modules/bcf/app/services/bcf/issues/transform_attributes_service.rb
+++ b/modules/bcf/app/services/bcf/issues/transform_attributes_service.rb
@@ -145,11 +145,13 @@ module Bcf::Issues
end
def missing_type(type_name, import_options)
+ types = project.types
+
if import_options[:unknown_types_action] == 'use_default'
- project.types.default&.first
+ 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)
+ types.find_by(id: import_options[:unknown_types_chose_ids].first)
elsif type_name
Type::InexistentType.new
end
diff --git a/modules/bcf/app/services/bcf/issues/update_service.rb b/modules/bcf/app/services/bcf/issues/update_service.rb
index f256e58ebc9..ec05eb54b79 100644
--- a/modules/bcf/app/services/bcf/issues/update_service.rb
+++ b/modules/bcf/app/services/bcf/issues/update_service.rb
@@ -40,7 +40,7 @@ module Bcf::Issues
.call(params)
if wp_call.success?
- issue_params = params.slice(:stage, :labels, :index)
+ issue_params = params.slice(*Bcf::Issue::SETTABLE_ATTRIBUTES)
super(issue_params)
else
diff --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.rb
index 1a64ba423b8..2ae78071172 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
@@ -217,6 +217,164 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_ma
end
end
+ shared_examples_for 'topics api write invalid parameters errors' do
+ context 'without a title' do
+ let(:params) do
+ {
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Title can't be blank."
+ end
+ end
+ end
+
+ context 'with an inexistent status' do
+ let(:params) do
+ {
+ title: 'Some title',
+ topic_status: 'Some non existing status'
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Status does not exist."
+ end
+ end
+ end
+
+ context 'with an inexistent priority' do
+ let(:params) do
+ {
+ title: 'Some title',
+ priority: 'Some non existing priority'
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Priority does not exist."
+ end
+ end
+ end
+
+ context 'with an inexistent type' do
+ let(:params) do
+ {
+ title: 'Some title',
+ topic_type: 'Some non existing type'
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Type does not exist."
+ end
+ end
+ end
+
+ context 'with an inexistent assigned_to' do
+ let(:params) do
+ {
+ title: 'Some title',
+ assigned_to: 'Some non existing assignee'
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Assignee does not exist."
+ end
+ end
+ end
+
+ context 'with two inexistent related resources' do
+ let(:params) do
+ {
+ title: 'Some title',
+ assigned_to: 'Some non existing assignee',
+ topic_type: 'Some non existing type'
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Multiple field constraints have been violated. Type does not exist. Assignee does not exist."
+ end
+ end
+ end
+
+ context 'with a label' do
+ let(:params) do
+ {
+ title: 'Some title',
+ labels: ['some label']
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Labels was attempted to be written but is not writable."
+ end
+ end
+ end
+
+ context 'with a stage' do
+ let(:params) do
+ {
+ title: 'Some title',
+ stage: 'some stage'
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Stage was attempted to be written but is not writable."
+ end
+ end
+ end
+
+ context 'with reference links' do
+ let(:params) do
+ {
+ title: 'Some title',
+ reference_links: [
+ "/some/relative/links"
+ ]
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Reference links was attempted to be written but is not writable."
+ end
+ end
+ end
+
+ context 'with bim_snippet' do
+ let(:params) do
+ {
+ title: 'Some title',
+ bim_snippet: {
+ snippet_type: "clash",
+ is_external: true,
+ reference: "https://example.com/bcf/1.0/ADFE23AA11BCFF444122BB",
+ reference_schema: "https://example.com/bcf/1.0/clash.xsd"
+ }
+ }
+ end
+
+ it_behaves_like 'bcf api unprocessable response' do
+ let(:message) do
+ "Bim snippet was attempted to be written but is not writable."
+ end
+ end
+ end
+ end
+
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 }
@@ -333,123 +491,12 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_ma
end
end
- context 'without a title' do
- let(:params) do
- {
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Title can't be blank."
- end
- end
- end
-
- context 'with an inexistent status' do
- let(:params) do
- {
- title: 'Some title',
- topic_status: 'Some non existing status'
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Status does not exist."
- end
- end
- end
-
- context 'with an inexistent priority' do
- let(:params) do
- {
- title: 'Some title',
- priority: 'Some non existing priority'
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Priority does not exist."
- end
- end
- end
-
- context 'with an inexistent type' do
- let(:params) do
- {
- title: 'Some title',
- topic_type: 'Some non existing type'
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Type does not exist."
- end
- end
- end
-
- context 'with an inexistent assigned_to' do
- let(:params) do
- {
- title: 'Some title',
- assigned_to: 'Some non existing assignee'
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Assignee does not exist."
- end
- end
- end
-
- context 'with two inexistent related resources' do
- let(:params) do
- {
- title: 'Some title',
- assigned_to: 'Some non existing assignee',
- topic_type: 'Some non existing type'
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Multiple field constraints have been violated. Type does not exist. Assignee does not exist."
- end
- end
- end
-
- context 'with a label' do
- let(:params) do
- {
- title: 'Some title',
- labels: ['some label']
- }
- end
-
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Labels was attempted to be written but is not writable."
- end
- end
- end
+ it_behaves_like 'topics api write invalid parameters errors'
- context 'with a stage' do
- let(:params) do
- {
- title: 'Some title',
- stage: 'some stage'
- }
- end
+ context 'if not allowed to add topics' do
+ let(:current_user) { view_only_user }
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Stage was attempted to be written but is not writable."
- end
- end
+ it_behaves_like 'bcf api not allowed response'
end
end
@@ -562,18 +609,12 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_ma
end
end
- context 'with the title set to null' do
- let(:params) do
- {
- title: nil
- }
- end
+ it_behaves_like 'topics api write invalid parameters errors'
- it_behaves_like 'bcf api unprocessable response' do
- let(:message) do
- "Title can't be blank."
- end
- end
+ context 'if not allowed to alter topics' do
+ let(:current_user) { view_only_user }
+
+ it_behaves_like 'bcf api not allowed response'
end
end
end
diff --git a/spec/contracts/work_packages/update_contract_spec.rb b/spec/contracts/work_packages/update_contract_spec.rb
index f75a9ddf941..4d804b4bdd2 100644
--- a/spec/contracts/work_packages/update_contract_spec.rb
+++ b/spec/contracts/work_packages/update_contract_spec.rb
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
+
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)