diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 181bacd5..66940486 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -17,10 +17,10 @@ class SubmissionsController < ApplicationController def show @submission = Submissions.preload_with_pages(@submission) - @available_ats_fields = extract_ats_prefill_fields + @available_prefill_fields = extract_prefill_fields # Optional: store in session for persistence across requests - session[:ats_prefill_fields] = @available_ats_fields if @available_ats_fields.any? + session[:prefill_fields] = @available_prefill_fields if @available_prefill_fields.any? unless @submission.submitters.all?(&:completed_at?) ActiveRecord::Associations::Preloader.new( diff --git a/app/controllers/submit_form_controller.rb b/app/controllers/submit_form_controller.rb index 4cd0b7d3..955b14a4 100644 --- a/app/controllers/submit_form_controller.rb +++ b/app/controllers/submit_form_controller.rb @@ -28,8 +28,8 @@ class SubmitFormController < ApplicationController Submitters::MaybeUpdateDefaultValues.call(@submitter, current_user) - # Fetch ATS prefill values if task_assignment_id is provided - @ats_prefill_values = fetch_ats_prefill_values_if_available + # Fetch prefill values if available + @prefill_values = fetch_prefill_values_if_available @attachments_index = build_attachments_index(submission) @@ -102,23 +102,23 @@ class SubmitFormController < ApplicationController .preload(:blob).index_by(&:uuid) end - def fetch_ats_prefill_values_if_available - # ATS passes values directly as Base64-encoded JSON parameters - return {} if params[:ats_values].blank? + def fetch_prefill_values_if_available + # External system passes values directly as Base64-encoded JSON parameters + return {} if params[:prefill_values].blank? # Security: Limit input size to prevent DoS attacks (64KB limit) - return {} if params[:ats_values].bytesize > 65_536 + return {} if params[:prefill_values].bytesize > 65_536 begin - decoded_json = Base64.urlsafe_decode64(params[:ats_values]) + decoded_json = Base64.urlsafe_decode64(params[:prefill_values]) # Security: Limit decoded JSON size as well return {} if decoded_json.bytesize > 32_768 - ats_values = JSON.parse(decoded_json) + prefill_values = JSON.parse(decoded_json) # Validate that we got a hash - ats_values.is_a?(Hash) ? ats_values : {} + prefill_values.is_a?(Hash) ? prefill_values : {} rescue StandardError {} end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 2e2e5919..180b082e 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -42,8 +42,8 @@ class TemplatesController < ApplicationController associations: [schema_documents: [:blob, { preview_images_attachments: :blob }]] ).call - # Process ATS fields for template editing - @available_ats_fields = extract_ats_prefill_fields + # Process prefill fields for template editing + @available_prefill_fields = extract_prefill_fields @template_data = @template.as_json.merge( @@ -51,7 +51,7 @@ class TemplatesController < ApplicationController methods: %i[metadata signed_uuid], include: { preview_images: { methods: %i[url metadata filename] } } ), - available_ats_fields: @available_ats_fields + available_prefill_fields: @available_prefill_fields ).to_json render :edit, layout: 'plain' diff --git a/app/helpers/prefill_fields_helper.rb b/app/helpers/prefill_fields_helper.rb index 011baec9..663163e2 100644 --- a/app/helpers/prefill_fields_helper.rb +++ b/app/helpers/prefill_fields_helper.rb @@ -1,53 +1,53 @@ # frozen_string_literal: true module PrefillFieldsHelper - # Extracts and validates ATS prefill field names from Base64-encoded parameters + # Extracts and validates prefill field names from Base64-encoded parameters # - # This method decodes the ats_fields parameter, validates the field names against + # This method decodes the prefill_fields parameter, validates the field names against # allowed patterns, and caches the results to improve performance on repeated requests. # - # @return [Array] Array of valid ATS field names, empty array if none found or on error + # @return [Array] Array of valid prefill field names, empty array if none found or on error # # @example - # # With params[:ats_fields] = Base64.urlsafe_encode64(['employee_first_name', 'employee_email'].to_json) - # extract_ats_prefill_fields + # # With params[:prefill_fields] = Base64.urlsafe_encode64(['employee_first_name', 'employee_email'].to_json) + # extract_prefill_fields # # => ['employee_first_name', 'employee_email'] - def extract_ats_prefill_fields - AtsPrefill.extract_fields(params) + def extract_prefill_fields + Prefill.extract_fields(params) end - # Merges ATS prefill values with existing submitter values + # Merges prefill values with existing submitter values # - # This method combines ATS-provided prefill values with values already entered by submitters. - # Existing submitter values always take precedence over ATS values to prevent overwriting + # This method combines externally-provided prefill values with values already entered by submitters. + # Existing submitter values always take precedence over prefill values to prevent overwriting # user input. Uses optimized field lookup caching for better performance. # # @param submitter_values [Hash] Existing values entered by submitters, keyed by field UUID - # @param ats_values [Hash] Prefill values from ATS system, keyed by ATS field name + # @param prefill_values [Hash] Prefill values from external system, keyed by prefill field name # @param template_fields [Array, nil] Template field definitions containing UUID and prefill mappings - # @return [Hash] Merged values with submitter values taking precedence over ATS values + # @return [Hash] Merged values with submitter values taking precedence over prefill values # # @example # submitter_values = { 'field-uuid-1' => 'John' } - # ats_values = { 'employee_first_name' => 'Jane', 'employee_last_name' => 'Doe' } + # prefill_values = { 'employee_first_name' => 'Jane', 'employee_last_name' => 'Doe' } # template_fields = [ # { 'uuid' => 'field-uuid-1', 'prefill' => 'employee_first_name' }, # { 'uuid' => 'field-uuid-2', 'prefill' => 'employee_last_name' } # ] # - # merge_ats_prefill_values(submitter_values, ats_values, template_fields) + # merge_prefill_values(submitter_values, prefill_values, template_fields) # # => { 'field-uuid-1' => 'John', 'field-uuid-2' => 'Doe' } # # Note: 'John' is preserved over 'Jane' because submitter value takes precedence - def merge_ats_prefill_values(submitter_values, ats_values, template_fields = nil) - AtsPrefill.merge_values(submitter_values, ats_values, template_fields) + def merge_prefill_values(submitter_values, prefill_values, template_fields = nil) + Prefill.merge_values(submitter_values, prefill_values, template_fields) end - # Finds field UUID by matching ATS field name to template field's prefill attribute + # Finds field UUID by matching prefill field name to template field's prefill attribute # # This method provides backward compatibility and is now optimized to use # the cached lookup when possible. # - # @param field_name [String] ATS field name to look up + # @param field_name [String] Prefill field name to look up # @param template_fields [Array, nil] Template field definitions # @return [String, nil] Field UUID if found, nil otherwise # @@ -55,22 +55,22 @@ module PrefillFieldsHelper # find_field_uuid_by_name('employee_first_name', template_fields) # # => 'field-uuid-123' def find_field_uuid_by_name(field_name, template_fields = nil) - AtsPrefill.find_field_uuid(field_name, template_fields) + Prefill.find_field_uuid(field_name, template_fields) end - # Clears ATS fields cache (useful for testing or manual cache invalidation) + # Clears prefill fields cache (useful for testing or manual cache invalidation) # # Since Rails cache doesn't provide easy enumeration of keys, this method # relies on TTL for automatic cleanup. This method is provided for potential # future use or testing scenarios where immediate cache invalidation is needed. # # @return [void] - def clear_ats_fields_cache - AtsPrefill.clear_cache + def clear_prefill_fields_cache + Prefill.clear_cache end # Legacy method aliases for backward compatibility - alias build_field_lookup_cache merge_ats_prefill_values + alias build_field_lookup_cache merge_prefill_values private @@ -78,33 +78,33 @@ module PrefillFieldsHelper # These now delegate to the service layer for consistency def read_from_cache(cache_key) - AtsPrefill::CacheManager.read_from_cache(cache_key) + Prefill::CacheManager.read_from_cache(cache_key) end - def parse_ats_fields_param(ats_fields_param) + def parse_prefill_fields_param(prefill_fields_param) # This is now handled internally by FieldExtractor # Kept for backward compatibility but not recommended for direct use - AtsPrefill::FieldExtractor.send(:parse_encoded_fields, ats_fields_param) + Prefill::FieldExtractor.send(:parse_encoded_fields, prefill_fields_param) end def validate_and_filter_field_names(field_names) # This is now handled internally by FieldExtractor # Kept for backward compatibility but not recommended for direct use - AtsPrefill::FieldExtractor.send(:validate_field_names, field_names) + Prefill::FieldExtractor.send(:validate_field_names, field_names) end - def valid_ats_field_name?(name) + def valid_prefill_field_name?(name) # This is now handled internally by FieldExtractor # Kept for backward compatibility but not recommended for direct use - AtsPrefill::FieldExtractor.send(:valid_ats_field_name?, name) + Prefill::FieldExtractor.send(:valid_prefill_field_name?, name) end - def ats_fields_cache_key(ats_fields_param) - AtsPrefill::CacheManager.generate_cache_key('ats_fields', ats_fields_param) + def prefill_fields_cache_key(prefill_fields_param) + Prefill::CacheManager.generate_cache_key('prefill_fields', prefill_fields_param) end def cache_result(cache_key, value, ttl) - AtsPrefill::CacheManager.write_to_cache(cache_key, value, ttl) + Prefill::CacheManager.write_to_cache(cache_key, value, ttl) end def cache_and_return_empty(cache_key) @@ -113,7 +113,7 @@ module PrefillFieldsHelper end def field_lookup_cache_key(template_fields) - signature = AtsPrefill::FieldMapper.send(:build_cache_signature, template_fields) - AtsPrefill::CacheManager.generate_cache_key('field_mapping', signature) + signature = Prefill::FieldMapper.send(:build_cache_signature, template_fields) + Prefill::CacheManager.generate_cache_key('field_mapping', signature) end end diff --git a/app/javascript/template_builder/field_settings.vue b/app/javascript/template_builder/field_settings.vue index b9b2c0ba..6320de94 100644 --- a/app/javascript/template_builder/field_settings.vue +++ b/app/javascript/template_builder/field_settings.vue @@ -256,14 +256,14 @@