metadata_presenter 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de4803f047828b34c584bbe1a6e3634e55ab62fb7dc5cf84af0e74179fab2bfd
4
- data.tar.gz: 48d367b837b22dae94e57158a1f23471ac5c8f51bac70ece003bcaa528eed909
3
+ metadata.gz: 86ebfbaf7f71c17731ad61596d6fe476f89103aceb9ce630fd8aecf1191dbff2
4
+ data.tar.gz: 120924e797dcbf42e6ef93807471555ba32e13ef0f95c59a30315d109f05c26b
5
5
  SHA512:
6
- metadata.gz: 45740afe9df6c30057f70e6c8c8cd24f913c90f6bb63c49a04c4104abbf65c3a87333f648cb8ff55be537ff754a5cb1e86745dd9762acb2df2201ba03bfeebda
7
- data.tar.gz: dd590ea13e20ce649630a7640e5877d56dca8081e2b8c118c22da9e4f43e62afaa39b3ddbdf185cc1e6b4f244aaafb9b37b1ca4d6995f8bd90a3deb5b95d8a60
6
+ metadata.gz: 49e96e2ca21a0cc70ba8a8d6582ecbad329a398512e93d8007be1bc20ed3dc8a41a95b19d9c23efd6728ec272e0f407b5f0bb5130d3a9f874490eee957046a14
7
+ data.tar.gz: 71a8456b3e0153693efaf08387e5caf043543d2ff970e254f89dec445459ee08415dd68e83de8a354db529e5b6d9b76d15a36b90b82146259fb6b67d5f97e05d
@@ -124,12 +124,15 @@ module MetadataPresenter
124
124
  # Always traverse the route from the start_from uuid. Defaulting to the
125
125
  # start page of the form unless otherwise specified.
126
126
  # Get all the potential routes from any branching points that exist.
127
+ traversed_uuids = []
127
128
  route_from_start.traverse
128
129
  @routes.append(route_from_start)
129
- traversed_routes = route_from_start.routes
130
-
130
+ traversed_uuids.concat(route_from_start.flow_uuids)
131
+ routes_to_traverse = route_from_start.routes
131
132
  index = 0
132
- until traversed_routes.empty?
133
+ Rails.logger.info("Total potential routes: #{total_potential_routes}")
134
+
135
+ until routes_to_traverse.empty?
133
136
  if index > total_potential_routes
134
137
  ActiveSupport::Notifications.instrument(
135
138
  'exceeded_total_potential_routes',
@@ -138,17 +141,22 @@ module MetadataPresenter
138
141
  break
139
142
  end
140
143
 
141
- route = traversed_routes.shift
144
+ route = routes_to_traverse.shift
142
145
  @routes.append(route)
143
146
 
144
- # Every route exiting a branching point needs to be traversed and any
145
- # additional routes from other branching points collected and then also
146
- # traversed.
147
+ # Traverse the route and add any nested routes to the list of routes to
148
+ # traverse.
149
+ # If the first flow_uuid in the route has already been traversed, then
150
+ # this route is looping back, so we don't need to traverse the nested routes.
147
151
  route.traverse
148
- traversed_routes |= route.routes
152
+ unless traversed_uuids.include?(route.flow_uuids.first)
153
+ routes_to_traverse.concat(route.routes)
154
+ end
155
+ traversed_uuids.concat(route.flow_uuids)
149
156
 
150
157
  index += 1
151
158
  end
159
+ Rails.logger.info("Total routes traversed: #{index}")
152
160
  end
153
161
 
154
162
  def set_column_numbers
@@ -441,15 +449,12 @@ module MetadataPresenter
441
449
  branch.all_destination_uuids.reject { |uuid| @traversed.include?(uuid) }
442
450
  end
443
451
 
444
- # Deliberately not including the default next for each branch as when row
445
- # zero is created it takes the first available conditional for each branch.
446
- # The remaining are then used to create route objects. Therefore the total
447
- # number of remaining routes will be the same as the total of all the branch
448
- # conditionals.
449
- # Add 1 additional route as that represents the route_from_start.
452
+ # Calculate an upper limit to prevent infinite traversal
453
+ # Not easy to calculate exactly, aiming for a number that is bigger than
454
+ # total possible routes but not too much bigger.
450
455
  def total_potential_routes
451
- @total_potential_routes ||=
452
- service.branches.sum { |branch| branch.conditionals.size } + 1
456
+ total_conditionals = service.branches.sum { |branch| branch.conditionals.size + 1 }
457
+ @total_potential_routes ||= total_conditionals * total_conditionals
453
458
  end
454
459
  end
455
460
  end
@@ -43,10 +43,10 @@ module MetadataPresenter
43
43
  return {} unless file_details
44
44
 
45
45
  if file_details.is_a?(Hash) || file_details.is_a?(ActionController::Parameters)
46
- file_details.merge('original_filename' => sanitize(filename(file_details['original_filename'])))
46
+ file_details.merge('original_filename' => sanitize(filename(update_filename(file_details['original_filename']))))
47
47
  else
48
48
  {
49
- 'original_filename' => sanitize(filename(file_details.original_filename)),
49
+ 'original_filename' => sanitize(filename(update_filename(file_details.original_filename))),
50
50
  'content_type' => file_details.content_type,
51
51
  'tempfile' => file_details.tempfile.path.to_s
52
52
  }
@@ -85,5 +85,16 @@ module MetadataPresenter
85
85
 
86
86
  filename
87
87
  end
88
+
89
+ def update_filename(answer)
90
+ jfif_or_jpg_extension?(answer) ? "#{File.basename(answer, '.*')}.jpeg" : answer
91
+ end
92
+
93
+ def jfif_or_jpg_extension?(answer)
94
+ return false if answer.nil?
95
+
96
+ file_extension = File.extname(answer)
97
+ %w[.jfif .jpg].include?(file_extension)
98
+ end
88
99
  end
89
100
  end
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '3.0.2'.freeze
2
+ VERSION = '3.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-26 00:00:00.000000000 Z
11
+ date: 2023-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder