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

correctly parse FileLink datetime information

Christophe Bliardc6312508be2b
diff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
index f7079fa8e94..b4dbfaffb07 100644
--- a/modules/storages/lib/api/v3/file_links/file_link_representer.rb
+++ b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
@@ -35,9 +35,9 @@ module API
property :id
- date_time_property :created_at
+ date_time_property :created_at, writeable: false
- date_time_property :updated_at
+ date_time_property :updated_at, writeable: false
property :originData,
exec_context: :decorator,
@@ -113,8 +113,11 @@ module API
origin_name: origin_data["name"],
origin_mime_type: origin_data["mimeType"],
origin_created_by_name: origin_data["createdByName"],
- origin_last_modified_by_name: origin_data["lastModifiedByName"]
- # createdAt and lastModifiedAt to be done
+ origin_last_modified_by_name: origin_data["lastModifiedByName"],
+ origin_created_at: ::API::V3::Utilities::DateTimeFormatter.parse_datetime(origin_data["createdAt"],
+ 'originData.createdAt'),
+ origin_updated_at: ::API::V3::Utilities::DateTimeFormatter.parse_datetime(origin_data["lastModifiedAt"],
+ 'originData.lastModifiedAt')
}
end
end
diff --git a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rb b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rb
index a1e003994fd..f73eb88c4cb 100644
--- a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rb
+++ b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rb
@@ -42,34 +42,44 @@ describe ::API::V3::FileLinks::FileLinkRepresenter, 'parsing' do
described_class.create(file_link, current_user: current_user)
end
- context 'with originData given' do
- let(:parsed_hash) do
- {
- "_type" => "FileLink",
- "createdAt" => "2022-02-09T10:03:37Z",
- "updatedAt" => "2022-02-09T10:03:37Z",
- "originData" => {
- "id" => 5503,
- "name" => "logo.png",
- "mimeType" => "image/png",
- "createdAt" => "2021-12-19T09:42:10.170Z",
- "lastModifiedAt" => "2021-12-20T14:00:13.987Z",
- "createdByName" => "Luke Skywalker",
- "lastModifiedByName" => "Anakin Skywalker"
- }
+ let(:parsed_hash) do
+ {
+ "_type" => "FileLink",
+ "createdAt" => "2022-02-09T10:03:37Z",
+ "updatedAt" => "2022-02-09T10:03:37Z",
+ "originData" => {
+ "id" => 5503,
+ "name" => "logo.png",
+ "mimeType" => "image/png",
+ "createdAt" => "2021-12-19T09:42:10.170Z",
+ "lastModifiedAt" => "2021-12-20T14:00:13.987Z",
+ "createdByName" => "Luke Skywalker",
+ "lastModifiedByName" => "Anakin Skywalker"
}
+ }
+ end
+
+ describe 'createdAt and updatedAt' do
+ it 'are not set by the parsing' do
+ expect(parsed).not_to have_attributes(
+ created_at: DateTime.parse(parsed_hash["createdAt"]).in_time_zone,
+ updated_at: DateTime.parse(parsed_hash["updatedAt"]).in_time_zone
+ )
end
+ end
- it 'parses correctly', pending: "work in progress" do
+ describe 'originData' do
+ it 'is parsed correctly' do
expect(parsed).to have_attributes(
origin_id: "5503",
origin_name: "logo.png",
origin_mime_type: "image/png",
origin_created_by_name: "Luke Skywalker",
origin_last_modified_by_name: "Anakin Skywalker",
- origin_created_at: "to be done",
- orig_updated_at: "to be done"
+ origin_created_at: DateTime.new(2021, 12, 19, 9, 42, 10.17, '+00:00').in_time_zone,
+ origin_updated_at: DateTime.new(2021, 12, 20, 14, 0, 13.987, '+00:00').in_time_zone
)
+ pp parsed
end
end
end