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

remove string_objects and replace deprecated URI.unescape

ulferts87471d9624ce
diff --git a/docs/api/apiv3/endpoints/string-objects.apib b/docs/api/apiv3/endpoints/string-objects.apib
deleted file mode 100644
index f1daba0f9ae..00000000000
--- a/docs/api/apiv3/endpoints/string-objects.apib
+++ /dev/null
@@ -1,36 +0,0 @@
-# Group String Objects
-
-## Linked Properties
-| Link | Description | Type | Constraints | Supported operations |
-|:-------------:|-------------------------- | ------------- | ----------- | -------------------- |
-| self | This string object | StringObject | not null | READ |
-
-## Local Properties
-| Property | Description | Type | Constraints | Supported operations |
-|:----------------:| ---------------------------------------------- | -------- | ----------- | -------------------- |
-| value | The value of the string | String | | READ |
-
-String objects are a linkable representation of strings. They merely serve the purpose of making links to strings possible,
-e.g. to be able to provide `allowedValues` for a string typed property.
-
-## String Object [/api/v3/string_objects?value={value}]
-
-+ Model
- + Body
-
- {
- "_links": {
- "self": { "href": "/api/v3/string_objects?value=Foo" }
- },
- "_type": "StringObject",
- "value": "Foo"
- }
-
-## View String Object [GET]
-
-+ Parameters
- + value (required, string, `Foo`) ... The string value being resolved
-
-+ Response 200 (application/hal+json)
-
- [String Object][]
diff --git a/docs/api/apiv3/index.apib b/docs/api/apiv3/index.apib
index 41b7a633f70..fb3e594dcbf 100644
--- a/docs/api/apiv3/index.apib
+++ b/docs/api/apiv3/index.apib
@@ -29,7 +29,6 @@
<!-- include(endpoints/root.apib) -->
<!-- include(endpoints/schemas.apib) -->
<!-- include(endpoints/statuses.apib) -->
-<!-- include(endpoints/string-objects.apib) -->
<!-- include(endpoints/time_entries.apib) -->
<!-- include(endpoints/types.apib) -->
<!-- include(endpoints/user-preferences.apib) -->
diff --git a/frontend/src/app/components/wp-query/url-params-helper.spec.ts b/frontend/src/app/components/wp-query/url-params-helper.spec.ts
index 047fd44c748..4fb4be22464 100644
--- a/frontend/src/app/components/wp-query/url-params-helper.spec.ts
+++ b/frontend/src/app/components/wp-query/url-params-helper.spec.ts
@@ -247,7 +247,7 @@ describe('UrlParamsHelper', function() {
expect(_.isEqual(v3Params, expected)).toBeTruthy();
});
- it('decodes string object filters', function() {
+ it('decodes custom options filters', function() {
let filter1 = {
id: 'customField1',
operator: {
@@ -258,14 +258,14 @@ describe('UrlParamsHelper', function() {
},
values: [
{
- _type: "StringObject",
- value: "val2val",
- $href: "/api/v3/string_objects/?value=val2val"
+ _type: "CustomOption",
+ value: "cde",
+ $href: "/api/v3/custom_options/2"
},
{
- _type: "StringObject",
- value: "7val7",
- $href: "/api/v3/string_objects/?value=7val7"
+ _type: "CustomOption",
+ value: "abc",
+ $href: "/api/v3/custom_options/7"
}
]
};
@@ -279,7 +279,7 @@ describe('UrlParamsHelper', function() {
sums: false
};
- additional = {}
+ additional = {};
let v3Params = UrlParamsHelper.buildV3GetQueryFromQueryResource(query, additional);
@@ -289,7 +289,7 @@ describe('UrlParamsHelper', function() {
{
customField1: {
operator: '=',
- values: ['val2val', '7val7']
+ values: ['2', '7']
}
}
]),
diff --git a/frontend/src/app/components/wp-query/url-params-helper.ts b/frontend/src/app/components/wp-query/url-params-helper.ts
index ed5b641d31d..67794a45831 100644
--- a/frontend/src/app/components/wp-query/url-params-helper.ts
+++ b/frontend/src/app/components/wp-query/url-params-helper.ts
@@ -291,8 +291,6 @@ export class UrlParamsHelperService {
return '';
} else if (value.id) {
return value.id.toString();
- } else if (value.$href && value.$href.match(/^\/api\/v3\/string_objects/i)) {
- return value.$href.match(/value=([^&]+)/)[1].toString();
} else if (value.$href) {
return value.$href.split('/').pop().toString();
} else {
diff --git a/frontend/src/app/modules/fields/display/display-field-renderer.ts b/frontend/src/app/modules/fields/display/display-field-renderer.ts
index 72303030a2c..7c526b6efdc 100644
--- a/frontend/src/app/modules/fields/display/display-field-renderer.ts
+++ b/frontend/src/app/modules/fields/display/display-field-renderer.ts
@@ -3,13 +3,12 @@ import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
import {IFieldSchema} from "core-app/modules/fields/field.base";
import {DisplayFieldContext, DisplayFieldService} from "core-app/modules/fields/display/display-field.service";
import {DisplayField} from "core-app/modules/fields/display/display-field.module";
-import {MultipleLinesStringObjectsDisplayField} from "core-app/modules/fields/display/field-types/multiple-lines-string-objects-display-field.module";
+import {MultipleLinesCustomOptionsDisplayField} from "core-app/modules/fields/display/field-types/multiple-lines-custom-options-display-field.module";
import {ProgressTextDisplayField} from "core-app/modules/fields/display/field-types/progress-text-display-field.module";
import {MultipleLinesUserFieldModule} from "core-app/modules/fields/display/field-types/multiple-lines-user-display-field.module";
import {ResourceChangeset} from "core-app/modules/fields/changeset/resource-changeset";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
import {InjectField} from "core-app/helpers/angular/inject-field.decorator";
-import {CombinedDateDisplayField} from "core-app/modules/fields/display/field-types/combined-date-display.field";
import {SchemaCacheService} from "core-components/schemas/schema-cache.service";
import {SchemaResource} from "core-app/modules/hal/resources/schema-resource";
import {ISchemaProxy} from "core-app/modules/hal/schemas/schema-proxy";
@@ -104,7 +103,7 @@ export class DisplayFieldRenderer<T extends HalResource = HalResource> {
// We handle multi value fields differently in the single view context
const isCustomMultiLinesField = ['[]CustomOption'].indexOf(fieldSchema.type) >= 0;
if (this.container === 'single-view' && isCustomMultiLinesField) {
- return new MultipleLinesStringObjectsDisplayField(attributeName, context) as DisplayField;
+ return new MultipleLinesCustomOptionsDisplayField(attributeName, context) as DisplayField;
}
const isUserMultiLinesField = ['[]User'].indexOf(fieldSchema.type) >= 0;
if (this.container === 'single-view' && isUserMultiLinesField) {
diff --git a/frontend/src/app/modules/fields/display/field-types/multiple-lines-string-objects-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/multiple-lines-custom-options-display-field.module.ts
similarity index 97%
rename from frontend/src/app/modules/fields/display/field-types/multiple-lines-string-objects-display-field.module.ts
rename to frontend/src/app/modules/fields/display/field-types/multiple-lines-custom-options-display-field.module.ts
index 645d448693b..8ef0d8fb010 100644
--- a/frontend/src/app/modules/fields/display/field-types/multiple-lines-string-objects-display-field.module.ts
+++ b/frontend/src/app/modules/fields/display/field-types/multiple-lines-custom-options-display-field.module.ts
@@ -29,7 +29,7 @@
import {ResourcesDisplayField} from "./resources-display-field.module";
import {cssClassCustomOption} from "core-app/modules/fields/display/display-field.module";
-export class MultipleLinesStringObjectsDisplayField extends ResourcesDisplayField {
+export class MultipleLinesCustomOptionsDisplayField extends ResourcesDisplayField {
public render(element:HTMLElement, displayText:string):void {
const values = this.value;
diff --git a/lib/api/utilities/resource_link_parser.rb b/lib/api/utilities/resource_link_parser.rb
index 067de239a73..b2ac63e802d 100644
--- a/lib/api/utilities/resource_link_parser.rb
+++ b/lib/api/utilities/resource_link_parser.rb
@@ -35,13 +35,10 @@ module API
SEGMENT_CHARACTER = '(\w|[-~!$&\'\(\)*+\.,:;=@]|%[0-9A-Fa-f]{2})'.freeze
RESOURCE_REGEX =
"/api/v(?<version>\\d)/(?<namespace>[\\w\/]+)/(?<id>#{SEGMENT_CHARACTER}+)\\z".freeze
- SO_REGEX = "/api/v(?<version>\\d)/string_objects/?\\?value=(?<id>\\w*).*\\z".freeze
class << self
def parse(resource_link)
- # string objects have a quite different format from the usual resources (query-parameter)
- # we therefore have a specific regex to deal with them and a generic one for all others
- parse_string_object(resource_link) || parse_resource(resource_link)
+ parse_resource(resource_link)
end
def parse_id(resource_link,
@@ -75,19 +72,7 @@ module API
{
version: match[:version],
namespace: match[:namespace],
- id: ::URI.unescape(match[:id])
- }
- end
-
- def parse_string_object(resource_link)
- match = string_object_matcher.match(resource_link)
-
- return nil unless match
-
- {
- version: match[:version],
- namespace: 'string_objects',
- id: ::URI.unescape(match[:id])
+ id: unescape(match[:id])
}
end
@@ -95,8 +80,10 @@ module API
@resource_matcher ||= Regexp.compile(RESOURCE_REGEX)
end
- def string_object_matcher
- @string_object_matcher ||= Regexp.compile(SO_REGEX)
+ def unescape(string)
+ @unescaper ||= Addressable::Template.new('{+id}')
+
+ @unescaper.extract(string)['id']
end
# returns whether expectation and actual are identical
diff --git a/lib/api/v3/string_objects/string_object_representer.rb b/lib/api/v3/string_objects/string_object_representer.rb
deleted file mode 100644
index 876d73444a2..00000000000
--- a/lib/api/v3/string_objects/string_object_representer.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#-- encoding: UTF-8
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2020 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-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 'roar/decorator'
-require 'roar/json/hal'
-
-module API
- module V3
- module StringObjects
- class StringObjectRepresenter < ::API::Decorators::Single
- # accepting current_user as argument to match common interface, we do not need it though
- def initialize(string, current_user: nil)
- super(string, current_user: current_user)
- end
-
- link :self do
- {
- href: api_v3_paths.string_object(represented)
- }
- end
-
- property :name,
- exec_context: :decorator,
- getter: ->(*) { values.reverse.last || '' }
-
- property :value,
- exec_context: :decorator,
- # empty values sometimes get passed as nil. Thus we make sure that we will always
- # display an empty string
- # (nil values are not supported by a string_objects URL anyway)
- getter: ->(*) { values.last || '' }
-
- def _type
- 'StringObject'
- end
-
- def values
- @values ||= Array(represented).compact
- end
-
- def model_required?
- # the string may also be nil, we are prepared for that
- false
- end
- end
- end
- end
-end
diff --git a/lib/api/v3/string_objects/string_objects_api.rb b/lib/api/v3/string_objects/string_objects_api.rb
index dc777513719..a90893993c8 100644
--- a/lib/api/v3/string_objects/string_objects_api.rb
+++ b/lib/api/v3/string_objects/string_objects_api.rb
@@ -27,8 +27,6 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-require 'api/v3/string_objects/string_object_representer'
-
module API
module V3
module StringObjects
@@ -36,11 +34,10 @@ module API
resources :string_objects do
params do
requires :value, type: String
- optional :name, type: String
end
get do
- StringObjectRepresenter.new([params[:name], params[:value]].compact)
+ status :gone
end
end
end
diff --git a/lib/api/v3/utilities/resource_link_generator.rb b/lib/api/v3/utilities/resource_link_generator.rb
index d719f2fbaff..e13774a5eb9 100644
--- a/lib/api/v3/utilities/resource_link_generator.rb
+++ b/lib/api/v3/utilities/resource_link_generator.rb
@@ -39,8 +39,6 @@ module API
path_method = determine_path_method(record)
record_identifier = record.id
api_v3_paths.send(path_method, record_identifier)
- elsif record.is_a?(String)
- api_v3_paths.string_object(record)
end
rescue NoMethodError
nil
diff --git a/spec/lib/api/utilities/resource_link_parser_spec.rb b/spec/lib/api/utilities/resource_link_parser_spec.rb
index be8c5234d55..d9b76bd0e19 100644
--- a/spec/lib/api/utilities/resource_link_parser_spec.rb
+++ b/spec/lib/api/utilities/resource_link_parser_spec.rb
@@ -62,12 +62,12 @@ describe ::API::Utilities::ResourceLinkParser do
end
end
- describe 'accepts and parses all valid segment characters as id' do
+ describe 'accepts a nested namespace resource' do
it_behaves_like 'accepts resource link' do
- let(:result) { subject.parse '/api/v3/string_object/foo-2_~!$&\'()*+.,:;=@%40' }
+ let(:result) { subject.parse '/api/v3/time_entries/activities/12' }
let(:version) { '3' }
- let(:namespace) { 'string_object' }
- let(:id) { 'foo-2_~!$&\'()*+.,:;=@@' }
+ let(:namespace) { 'time_entries/activities' }
+ let(:id) { '12' }
end
end
@@ -95,41 +95,6 @@ describe ::API::Utilities::ResourceLinkParser do
end
end
end
-
- describe 'string object resource' do
- describe 'accepts a simple string' do
- it_behaves_like 'accepts resource link' do
- let(:result) { subject.parse '/api/v3/string_objects/foobar' }
- let(:version) { '3' }
- let(:namespace) { 'string_objects' }
- let(:id) { 'foobar' }
- end
- end
-
- describe 'accepts and parses all valid segment characters as value' do
- it_behaves_like 'accepts resource link' do
- let(:result) { subject.parse '/api/v3/string_objects?value=foo-2_~!$&\'()*+.,:;=@%40' }
- let(:version) { '3' }
- let(:namespace) { 'string_objects' }
- let(:id) { 'foo' }
- end
- end
-
- describe 'accepts string objects with empty value parameter' do
- it_behaves_like 'accepts resource link' do
- let(:result) { subject.parse '/api/v3/string_objects?value=' }
- let(:version) { '3' }
- let(:namespace) { 'string_objects' }
- let(:id) { '' }
- end
- end
-
- describe 'rejects resource with missing value parameter' do
- it_behaves_like 'rejects resource link' do
- let(:result) { subject.parse '/api/v3/string_objects' }
- end
- end
- end
end
describe '#parse_id' do
@@ -137,8 +102,12 @@ describe ::API::Utilities::ResourceLinkParser do
expect(subject.parse_id('/api/v3/statuses/14', property: 'foo')).to eql('14')
end
- it 'parses an empty value as empty string' do
- expect(subject.parse_id('/api/v3/string_objects?value=', property: 'foo')).to eql('')
+ it 'parses the id with nested namespace' do
+ expect(subject.parse_id('/api/v3/statuses/nested/14', property: 'foo')).to eql('14')
+ end
+
+ it 'parses a non decimal id with nested namespace' do
+ expect(subject.parse_id('/api/v3/statuses/nested/=', property: 'foo')).to eql('=')
end
it 'accepts on matching version' do
diff --git a/spec/lib/api/v3/queries/schemas/filter_dependency_representer_factory_spec.rb b/spec/lib/api/v3/queries/schemas/filter_dependency_representer_factory_spec.rb
index cffd243338a..f6f6ee17b3e 100644
--- a/spec/lib/api/v3/queries/schemas/filter_dependency_representer_factory_spec.rb
+++ b/spec/lib/api/v3/queries/schemas/filter_dependency_representer_factory_spec.rb
@@ -122,7 +122,7 @@ describe ::API::V3::Queries::Schemas::FilterDependencyRepresenterFactory do
context 'type list' do
let(:custom_field) { FactoryBot.build_stubbed(:list_wp_custom_field) }
- it 'is the string object dependency' do
+ it 'is the custom option dependency' do
is_expected.to be_a(::API::V3::Queries::Schemas::CustomOptionFilterDependencyRepresenter)
end
@@ -162,7 +162,7 @@ describe ::API::V3::Queries::Schemas::FilterDependencyRepresenterFactory do
context 'type bool' do
let(:custom_field) { FactoryBot.build_stubbed(:bool_wp_custom_field) }
- it 'is the string object dependency' do
+ it 'is the boolean filter dependency' do
is_expected.to be_a(::API::V3::Queries::Schemas::BooleanFilterDependencyRepresenter)
end
diff --git a/spec/lib/api/v3/string_objects/string_object_representer_spec.rb b/spec/lib/api/v3/string_objects/string_object_representer_spec.rb
deleted file mode 100644
index 16dd16b9e0d..00000000000
--- a/spec/lib/api/v3/string_objects/string_object_representer_spec.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2020 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-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 ::API::V3::StringObjects::StringObjectRepresenter do
- let(:value) { 'foo bar' }
- let(:representer) { described_class.new(value) }
-
- include API::V3::Utilities::PathHelper
-
- context 'generation' do
- subject { representer.to_json }
-
- it 'should indicate its type' do
- is_expected.to be_json_eql('StringObject'.to_json).at_path('_type')
- end
-
- describe 'links' do
- it 'should link to self' do
- path = api_v3_paths.string_object(value)
-
- is_expected.to be_json_eql(path.to_json).at_path('_links/self/href')
- end
- end
-
- describe 'value' do
- it 'should have a value' do
- is_expected.to be_json_eql(value.to_json).at_path('value')
- end
-
- context 'value is nil' do
- let(:value) { nil }
-
- it 'should be the empty string' do
- is_expected.to be_json_eql(''.to_json).at_path('value')
- end
- end
- end
- end
-end
diff --git a/spec/lib/api/v3/utilities/resource_link_generator_spec.rb b/spec/lib/api/v3/utilities/resource_link_generator_spec.rb
index ab524a1eb40..90146915116 100644
--- a/spec/lib/api/v3/utilities/resource_link_generator_spec.rb
+++ b/spec/lib/api/v3/utilities/resource_link_generator_spec.rb
@@ -59,11 +59,6 @@ describe API::V3::Utilities::ResourceLinkGenerator do
expect(subject.make_link record).to be_nil
end
- it 'returns a string object for strings' do
- record = 'a string'
- expect(subject.make_link record).to eql "/api/v3/string_objects?value=a%20string"
- end
-
it 'returns nil for non-AR types' do
record = Object.new
expect(subject.make_link record).to be_nil
diff --git a/spec/requests/api/v3/string_objects_resource_spec.rb b/spec/requests/api/v3/string_objects_resource_spec.rb
index fd9ef463c31..b1fd962876e 100644
--- a/spec/requests/api/v3/string_objects_resource_spec.rb
+++ b/spec/requests/api/v3/string_objects_resource_spec.rb
@@ -42,35 +42,15 @@ describe 'API v3 String Objects resource' do
get path
end
- it 'is successful' do
- expect(subject.status).to eql(200)
- end
-
- it 'returns the value' do
- expect(subject.body).to be_json_eql('foo bar'.to_json).at_path('value')
- end
-
- context 'empty string' do
- let(:path) { api_v3_paths.string_object '' }
-
- it 'is successful' do
- expect(subject.status).to eql(200)
- end
-
- it 'returns the value' do
- expect(subject.body).to be_json_eql(''.to_json).at_path('value')
- end
+ it 'return 410 GONE' do
+ expect(subject.status).to eql(410)
end
context 'nil string' do
let(:path) { '/api/v3/string_objects?value' }
- it 'is successful' do
- expect(subject.status).to eql(200)
- end
-
- it 'returns the empty string' do
- expect(subject.body).to be_json_eql(''.to_json).at_path('value')
+ it 'return 410 GONE' do
+ expect(subject.status).to eql(410)
end
end
end