Skip to content

Commit

Permalink
Merge pull request #17069 from opf/bug/57550-custom-field-with-format…
Browse files Browse the repository at this point in the history
…-version-are-ordered-as-strings-3

Bug/57550 custom field with format version are ordered as strings 3
  • Loading branch information
ulferts authored Nov 7, 2024
2 parents c9077ef + 8b88640 commit a1865c7
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 136 deletions.
3 changes: 1 addition & 2 deletions app/models/queries/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Queries::Versions
::Queries::Register.register(VersionQuery) do
filter Filters::SharingFilter

order Orders::NameOrder
order Orders::SemverNameOrder
order Orders::DefaultOrder
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Queries::Versions::Orders::NameOrder < Queries::Orders::Base
class Queries::Versions::Orders::DefaultOrder < Queries::Orders::Base
self.model = Version

def self.key
:name
/\A(id|name|semver_name)\z/
end

private
def initialize(attribute)
if attribute == :semver_name
OpenProject::Deprecation.warn("Sorting by semver_name is deprecated, name should be used instead")

def order
ordered = Version.order(:name)

if direction == :desc
ordered = ordered.reverse_order
super(:name)
else
super
end

ordered
end
end
47 changes: 0 additions & 47 deletions app/models/queries/versions/orders/semver_name_order.rb

This file was deleted.

9 changes: 2 additions & 7 deletions app/models/queries/work_packages/selects/property_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def caption
},
parent: {
association: "ancestors_relations",
default_order: "asc",
sortable: false
},
status: {
Expand Down Expand Up @@ -96,18 +95,14 @@ def caption
version: {
association: "version",
sortable: "name",
default_order: "ASC",
null_handling: "NULLS LAST",
groupable: "#{WorkPackage.table_name}.version_id"
},
start_date: {
sortable: "#{WorkPackage.table_name}.start_date",
null_handling: "NULLS LAST"
sortable: "#{WorkPackage.table_name}.start_date"
},
due_date: {
highlightable: true,
sortable: "#{WorkPackage.table_name}.due_date",
null_handling: "NULLS LAST"
sortable: "#{WorkPackage.table_name}.due_date"
},
estimated_hours: {
sortable: "#{WorkPackage.table_name}.estimated_hours",
Expand Down
141 changes: 77 additions & 64 deletions docs/api/apiv3/paths/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@
---
get:
parameters:
- description: |-
JSON specifying filter conditions.
Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/) endpoint.
Currently supported filters are:
- description: |-
JSON specifying filter conditions.
Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/) endpoint.
Currently supported filters are:
+ sharing: filters versions by how they are shared within the server (*none*, *descendants*, *hierarchy*, *tree*, *system*).
example: '[{ "sharing": { "operator": "*", "values": ["system"] }" }]'
in: query
name: filters
required: false
schema:
type: string
+ sharing: filters versions by how they are shared within the server (*none*, *descendants*, *hierarchy*, *tree*, *system*).
example: '[{ "sharing": { "operator": "*", "values": ["system"] }" }]'
in: query
name: filters
required: false
schema:
type: string
- description: |-
JSON specifying sort criteria.
Accepts the same format as returned by the [queries](https://www.openproject.org/docs/api/endpoints/queries/) endpoint. Currently supported attributes are:
+ id: Sort by the version id
+ name: Sort by the version name using numeric collation, comparing sequences of decimal digits by their numeric value
+ semver_name: Deprecated, use name instead
example: '[["name", "desc"]]'
in: query
name: sortBy
required: false
schema:
type: string
responses:
'200':
content:
Expand All @@ -23,57 +36,57 @@ get:
value:
_embedded:
elements:
- _links:
availableInProjects:
href: "/api/v3/versions/11/projects"
definingProject:
href: "/api/v3/projects/12"
self:
href: "/api/v3/versions/11"
_type: Version
description:
format: plain
html: This version has a description
raw: This version has a description
endDate:
id: 11
name: v3.0 Alpha
startDate: '2014-11-20'
status: Open
- _links:
availableInProjects:
href: "/api/v3/versions/12/projects"
definingProject:
href: "/api/v3/projects/11"
self:
href: "/api/v3/versions/12"
_type: Version
description:
format: plain
html: ''
raw: ''
endDate:
id: 12
name: v2.0
startDate:
status: Closed
- _links:
availableInProjects:
href: "/api/v3/versions/13/projects"
definingProject:
href: "/api/v3/projects/13"
self:
href: "/api/v3/versions/10"
_type: Version
description:
format: plain
html: ''
raw: ''
endDate:
id: 10
name: v1.0
startDate:
status: Open
- _links:
availableInProjects:
href: "/api/v3/versions/11/projects"
definingProject:
href: "/api/v3/projects/12"
self:
href: "/api/v3/versions/11"
_type: Version
description:
format: plain
html: This version has a description
raw: This version has a description
endDate:
id: 11
name: v3.0 Alpha
startDate: '2014-11-20'
status: Open
- _links:
availableInProjects:
href: "/api/v3/versions/12/projects"
definingProject:
href: "/api/v3/projects/11"
self:
href: "/api/v3/versions/12"
_type: Version
description:
format: plain
html: ''
raw: ''
endDate:
id: 12
name: v2.0
startDate:
status: Closed
- _links:
availableInProjects:
href: "/api/v3/versions/13/projects"
definingProject:
href: "/api/v3/projects/13"
self:
href: "/api/v3/versions/10"
_type: Version
description:
format: plain
html: ''
raw: ''
endDate:
id: 10
name: v1.0
startDate:
status: Open
_links:
self:
href: "/api/v3/versions"
Expand All @@ -85,7 +98,7 @@ get:
description: OK
headers: {}
tags:
- Versions
- Versions
description: Returns a collection of versions. The client can choose to filter the
versions similar to how work packages are filtered. In addition to the provided
filters, the server will reduce the result set to only contain versions, for which
Expand Down Expand Up @@ -130,7 +143,7 @@ post:
* a constraint for a property was violated (`PropertyConstraintViolation`)
headers: {}
tags:
- Versions
- Versions
description: |-
Creates a new version applying the attributes provided in the body. Please note that while there is a fixed set of attributes, custom fields can extend a version's attributes and are accepted by the endpoint.
Expand Down
Loading

0 comments on commit a1865c7

Please sign in to comment.