metadata_presenter 3.0.1 → 3.0.3

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: 0a31f247a10c6d27dbc9aa98fcaeba77debba7299bdc07ae0a464d5ef2e0acb4
4
- data.tar.gz: 03b6fdf906a24439d474498e86d4c7e0e7978137551cbd7929fd61c06616a3d8
3
+ metadata.gz: bbf82d6e0d0d2d3456a197111c4f9819c7fb67c8d260fc7db6c9c8be24788d30
4
+ data.tar.gz: '052159fc7c7fe9b069586828b56a9b89abb7737a1714da371616faf484af2949'
5
5
  SHA512:
6
- metadata.gz: fc2bc804e2e918de103b68dd0af02a6538f785f49bb4267a74cad8b88f3ed8f6d9d83476df0d2f247bbad44c8121fcbb4941397df1a5189a40e4348bf433b966
7
- data.tar.gz: 559b1ddc0c79e391a0406dd7bba3cfc28758aa64fc7c20cc190790c141a9cb025400c83442cc95886509ca75741bf29a0b7121c79edf315d7cf9138a971ec034
6
+ metadata.gz: 194308706ef13433ad2bebba4bb8c3367e84f0b3d8de4874a67ea0c47065f4a47717c7a29c8564809a0a319d0d381b6122c0203abf0d4fb39d8e618e56ab9cfc
7
+ data.tar.gz: 815a4558475e02b8b32805f2c8d3c3fc7276b33d1b3497d81221332b3a3b46d1f29248d246267209cfe62692f38f00b0c3b937b37d973568cb59d25cbdb9c34d
@@ -42,6 +42,7 @@ module MetadataPresenter
42
42
  @saved_form.secret_question = params['saved_form']['secret_question']
43
43
  @saved_form.populate_service_values(service)
44
44
  @saved_form.populate_session_values(session)
45
+ @saved_form.service_slug = service_slug
45
46
  if @saved_form.valid?
46
47
  # put in session until we have confirmed email address
47
48
  @saved_form.secret_question = @saved_form.secret_question_text
@@ -231,5 +232,11 @@ module MetadataPresenter
231
232
  def label_text(text)
232
233
  "<h2 class='govuk-heading-m'>#{text}</h2>"
233
234
  end
235
+
236
+ private
237
+
238
+ def service_slug
239
+ @service_slug ||= service_slug_config
240
+ end
234
241
  end
235
242
  end
@@ -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
@@ -21,7 +21,7 @@ module MetadataPresenter
21
21
  :created_at,
22
22
  :updated_at
23
23
 
24
- validates :secret_question, :secret_answer, :service_slug, :page_slug, :service_version, :user_id, :user_token, presence: { message: 'Enter an answer for "%{attribute}"' }, allow_blank: false
24
+ validates :secret_question, :secret_answer, :page_slug, :service_version, :user_id, :user_token, presence: { message: 'Enter an answer for "%{attribute}"' }, allow_blank: false
25
25
 
26
26
  def initialize; end
27
27
 
@@ -38,7 +38,6 @@ module MetadataPresenter
38
38
  end
39
39
 
40
40
  def populate_service_values(service)
41
- self.service_slug = service.service_slug
42
41
  self.service_version = service.version_id
43
42
  end
44
43
 
@@ -38,8 +38,6 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
38
38
  end
39
39
 
40
40
  def service_slug
41
- return service_slug_config if service_slug_config.present?
42
-
43
41
  service_name.gsub(/['’]/, '').parameterize
44
42
  end
45
43
 
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '3.0.3'.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.1
4
+ version: 3.0.3
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-25 00:00:00.000000000 Z
11
+ date: 2023-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder