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

add schema for Values resource

ulferts36d1728217b6
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a85533c9715..57b937b5352 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3132,6 +3132,7 @@ en:
api_v3:
attributes:
lock_version: "Lock Version"
+ property: 'Property'
errors:
code_400: "Bad request: %{message}"
code_401: "You need to be authenticated to access this resource."
diff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rb
index db5199e7807..8cbf58a123e 100644
--- a/lib/api/v3/root.rb
+++ b/lib/api/v3/root.rb
@@ -53,6 +53,7 @@ module API
mount ::API::V3::CustomActions::CustomActionsAPI
mount ::API::V3::CustomOptions::CustomOptionsAPI
mount ::API::V3::Days::DaysAPI
+ mount ::API::V3::Grids::GridsAPI
mount ::API::V3::Notifications::NotificationsAPI
mount ::API::V3::HelpTexts::HelpTextsAPI
mount ::API::V3::Memberships::MembershipsAPI
@@ -74,11 +75,11 @@ module API
mount ::API::V3::PlaceholderUsers::PlaceholderUsersAPI
mount ::API::V3::UserPreferences::UserPreferencesAPI
mount ::API::V3::Groups::GroupsAPI
+ mount ::API::V3::Values::ValuesAPI
mount ::API::V3::Versions::VersionsAPI
mount ::API::V3::Views::ViewsAPI
mount ::API::V3::WorkPackages::WorkPackagesAPI
mount ::API::V3::WikiPages::WikiPagesAPI
- mount ::API::V3::Grids::GridsAPI
get '/' do
RootRepresenter.new({}, current_user:)
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 2ccc898adf5..04a0fab2e14 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -445,6 +445,10 @@ module API
index :group
show :group
+ def self.value_schema(property)
+ "#{root}/values/schemas/#{property}"
+ end
+
resources :version
index :view
diff --git a/lib/api/v3/values/schemas/model.rb b/lib/api/v3/values/schemas/model.rb
new file mode 100644
index 00000000000..568e82e8ac8
--- /dev/null
+++ b/lib/api/v3/values/schemas/model.rb
@@ -0,0 +1,44 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+module API::V3::Values::Schemas
+ class Model
+ attr_reader :name,
+ :type
+
+ def initialize(name, type)
+ @name = name
+ @type = type
+ end
+
+ def ==(other)
+ name == other.name &&
+ type == other.type
+ end
+ end
+end
diff --git a/lib/api/v3/values/schemas/property_schema_representer.rb b/lib/api/v3/values/schemas/property_schema_representer.rb
new file mode 100644
index 00000000000..cb729725c3d
--- /dev/null
+++ b/lib/api/v3/values/schemas/property_schema_representer.rb
@@ -0,0 +1,39 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+module API::V3::Values::Schemas
+ class PropertySchemaRepresenter < ::API::Decorators::SchemaRepresenter
+ schema :property,
+ type: 'String',
+ name_source: ->(*) { I18n.t(:'api_v3.attributes.property') }
+
+ schema :value,
+ type: ->(*) { represented.type },
+ name_source: ->(*) { represented.name }
+ end
+end
diff --git a/lib/api/v3/values/schemas/value_schema_api.rb b/lib/api/v3/values/schemas/value_schema_api.rb
new file mode 100644
index 00000000000..04333d9b711
--- /dev/null
+++ b/lib/api/v3/values/schemas/value_schema_api.rb
@@ -0,0 +1,39 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+module API::V3::Values::Schemas
+ class ValueSchemaAPI < ::API::OpenProjectAPI
+ resources :schemas do
+ get ':property' do
+ ValueSchemaFactory.for(params[:property]).tap do |representer|
+ raise API::Errors::NotFound unless representer
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/v3/values/schemas/value_schema_factory.rb b/lib/api/v3/values/schemas/value_schema_factory.rb
new file mode 100644
index 00000000000..3956acb91ed
--- /dev/null
+++ b/lib/api/v3/values/schemas/value_schema_factory.rb
@@ -0,0 +1,68 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+module API::V3::Values::Schemas
+ module ValueSchemaFactory
+ extend ::API::V3::Utilities::PathHelper
+
+ module_function
+
+ def for(property)
+ return nil unless supported?(property)
+
+ ::API::V3::Values::Schemas::PropertySchemaRepresenter
+ .new(model_for(property),
+ current_user: nil,
+ self_link: api_v3_paths.value_schema(property))
+ end
+
+ def supported?(property)
+ # This is but a stub. Currently, only 'start_date' and 'due_date'
+ # need to be supported so this simple approach works.
+ %w(start_date due_date).include?(property)
+ end
+
+ def model_for(property)
+ API::V3::Values::Schemas::Model
+ .new(i18n_for(property),
+ type_for(property))
+ end
+
+ def i18n_for(property)
+ # This is but a stub. Currently, only 'start_date' and 'due_date'
+ # need to be supported so this simple approach works.
+ I18n.t("attributes.#{property}")
+ end
+
+ def type_for(_property)
+ # This is but a stub. Currently, only 'start_date' and 'due_date'
+ # need to be supported so this simple approach works.
+ 'Date'
+ end
+ end
+end
diff --git a/lib/api/v3/values/values_api.rb b/lib/api/v3/values/values_api.rb
new file mode 100644
index 00000000000..403f01cc3fe
--- /dev/null
+++ b/lib/api/v3/values/values_api.rb
@@ -0,0 +1,35 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+module API::V3::Values
+ class ValuesAPI < ::API::OpenProjectAPI
+ resources :values do
+ mount API::V3::Values::Schemas::ValueSchemaAPI
+ end
+ end
+end
diff --git a/spec/lib/api/v3/notifications/details_factory_spec.rb b/spec/lib/api/v3/notifications/details_factory_spec.rb
index 6191bac87d2..fcdca8039d5 100644
--- a/spec/lib/api/v3/notifications/details_factory_spec.rb
+++ b/spec/lib/api/v3/notifications/details_factory_spec.rb
@@ -37,9 +37,6 @@ describe ::API::V3::Notifications::DetailsFactory do
reason:
end
- let(:embed_links) { false }
- let(:read_ian) { false }
-
describe '.for' do
context 'for a date_alert_start_date notification' do
let(:reason) { :date_alert_start_date }
diff --git a/spec/lib/api/v3/utilities/path_helper_spec.rb b/spec/lib/api/v3/utilities/path_helper_spec.rb
index 902d8dabadd..0484db06b6d 100644
--- a/spec/lib/api/v3/utilities/path_helper_spec.rb
+++ b/spec/lib/api/v3/utilities/path_helper_spec.rb
@@ -483,6 +483,14 @@ describe ::API::V3::Utilities::PathHelper do
it_behaves_like 'show', :group
end
+ describe 'values paths' do
+ describe '#values_schema' do
+ subject { helper.value_schema('bogus_value') }
+
+ it_behaves_like 'api v3 path', '/values/schemas/bogus_value'
+ end
+ end
+
describe 'version paths' do
it_behaves_like 'resource', :version
diff --git a/spec/lib/api/v3/values/schemas/property_schema_representer_rendering_spec.rb b/spec/lib/api/v3/values/schemas/property_schema_representer_rendering_spec.rb
new file mode 100644
index 00000000000..ea2cc986ce9
--- /dev/null
+++ b/spec/lib/api/v3/values/schemas/property_schema_representer_rendering_spec.rb
@@ -0,0 +1,90 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+require 'spec_helper'
+
+describe ::API::V3::Values::Schemas::PropertySchemaRepresenter, 'rendering' do
+ include API::V3::Utilities::PathHelper
+
+ let(:current_user) { build_stubbed(:user) }
+
+ let(:self_link) { '/a/self/link' }
+
+ let(:model) do
+ API::V3::Values::Schemas::Model
+ .new('The start date to that object',
+ 'ADate')
+ end
+
+ let(:representer) do
+ described_class.create(model,
+ self_link:,
+ current_user:)
+ end
+
+ subject(:generated) { representer.to_json }
+
+ describe '_type' do
+ it 'is indicated as Schema' do
+ expect(subject)
+ .to be_json_eql('Schema'.to_json)
+ .at_path('_type')
+ end
+ end
+
+ describe 'property' do
+ let(:path) { 'property' }
+
+ it_behaves_like 'has basic schema properties' do
+ let(:type) { 'String' }
+ let(:name) { I18n.t(:'api_v3.attributes.property') }
+ let(:required) { true }
+ let(:writable) { false }
+ end
+ end
+
+ describe 'value' do
+ let(:path) { 'value' }
+
+ it_behaves_like 'has basic schema properties' do
+ let(:type) { model.type }
+ let(:name) { model.name }
+ let(:required) { true }
+ let(:writable) { false }
+ end
+ end
+
+ describe '_links' do
+ describe 'self' do
+ it_behaves_like 'has an untitled link' do
+ let(:link) { 'self' }
+ let(:href) { self_link }
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb b/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb
new file mode 100644
index 00000000000..5e2b0e07071
--- /dev/null
+++ b/spec/lib/api/v3/values/schemas/value_schema_factory_spec.rb
@@ -0,0 +1,91 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+require 'spec_helper'
+
+describe ::API::V3::Values::Schemas::ValueSchemaFactory do
+ include ::API::V3::Utilities::PathHelper
+
+ describe '.for' do
+ let!(:representer_instance) do
+ instance_double(::API::V3::Values::Schemas::PropertySchemaRepresenter)
+ end
+ let!(:representer_class) do
+ allow(::API::V3::Values::Schemas::PropertySchemaRepresenter)
+ .to receive(:new)
+ .and_return(representer_instance)
+ end
+
+ context 'for the start_date property' do
+ let(:property) { 'start_date' }
+
+ it 'returns a schema representer' do
+ expect(described_class.for(property))
+ .to eq representer_instance
+ end
+
+ it 'instantiates the representer with the proper params' do
+ described_class.for(property)
+
+ expect(::API::V3::Values::Schemas::PropertySchemaRepresenter)
+ .to have_received(:new)
+ .with(API::V3::Values::Schemas::Model.new(I18n.t('attributes.start_date'), 'Date'),
+ current_user: nil,
+ self_link: api_v3_paths.value_schema(property))
+ end
+ end
+
+ context 'for the due_date property' do
+ let(:property) { 'due_date' }
+
+ it 'returns a schema representer' do
+ expect(described_class.for(property))
+ .to eq representer_instance
+ end
+
+ it 'instantiates the representer with the proper params' do
+ described_class.for(property)
+
+ expect(::API::V3::Values::Schemas::PropertySchemaRepresenter)
+ .to have_received(:new)
+ .with(API::V3::Values::Schemas::Model.new(I18n.t('attributes.due_date'), 'Date'),
+ current_user: nil,
+ self_link: api_v3_paths.value_schema(property))
+ end
+ end
+
+ context 'for another property' do
+ let(:property) { 'bogus' }
+
+ it 'returns nil' do
+ expect(described_class.for(property))
+ .to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb b/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb
new file mode 100644
index 00000000000..c57f6411482
--- /dev/null
+++ b/spec/requests/api/v3/values/schemas/value_schema_resource_spec.rb
@@ -0,0 +1,76 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+# ++
+
+require 'spec_helper'
+
+describe ::API::V3::Values::Schemas::ValueSchemaAPI,
+ 'show',
+ content_type: :json,
+ type: :request do
+ include API::V3::Utilities::PathHelper
+
+ current_user { build_stubbed(:user) }
+
+ let(:path) { api_v3_paths.value_schema(schema_id) }
+ let(:schema_id) { 'bogus' }
+
+ before do
+ get path
+ end
+
+ context 'for a logged in user' do
+ context 'for a property' do
+ let(:schema_id) { 'start_date' }
+
+ it 'returns the schema', :aggregate_failures do
+ expect(last_response.status)
+ .to eq 200
+
+ expect(last_response.body)
+ .to be_json_eql('Schema'.to_json)
+ .at_path('_type')
+
+ expect(last_response.body)
+ .to be_json_eql('Date'.to_json)
+ .at_path('value/type')
+
+ expect(last_response.body)
+ .to be_json_eql('Start date'.to_json)
+ .at_path('value/name')
+ end
+ end
+ end
+
+ context 'for a logged in user and a non existing property' do
+ context 'for a property' do
+ let(:schema_id) { 'bogus' }
+
+ it_behaves_like 'not found'
+ end
+ end
+end