Disable autofill in dashboard

Hi,

In the doc, it’s indicated that dashboard remains previous values in form. This is a problem if you want to initialize dynamicaly some value with erb scripts inside the «initializers» of the dashboard.
Question : is there any way to disable the autofill mechanism into the dashboard ?

Thanks

Jean-Marie

@jms27000 I hope your vacations are going well. Another response for you:

I think that you are asking about the Batch Connect forms? The auto fill mechanism is built around a file named context.json. By preventing the creation and reading of that file we can prevent the auto fill from occurring.

We can patch this feature in by adding a custom initializer to the Dashboard’s configuration by adding a file like: /etc/ood/config/apps/dashboard/initializers/bc_app_context_cache_buster.rb.

An example implementation follows:

# /etc/ood/config/apps/dashboard/initializers/bc_app_context_cache_buster.rb
require 'batch_connect/session_contexts_controller'

class BatchConnect::SessionContextsController
  # Implements a portion of the Pathname interface
  # 
  # ...that BatchConnect::SessionContextsController uses for interacting with context.json
  class CacheDenier
    # Prevent loading pre-existing context.json
    def file?
      false
    end

    # Prevent creating new context.json
    def write(*args, **kwargs)
      # Do nothing
    end
  end

  ##
  # Override default cache file handler
  # 
  # Add logic to the unless block to control whether the 
  def cache_file
    unless should_skip_cache
      # Perform the normal action
      BatchConnect::Session.dataroot(@app.token).tap { |p| p.mkpath unless p.exist? }.join("context.json")
    else
      # Do not use the context cache file
      CacheDenier.new
    end
  end

  ##
  # Custom logic to determine if caching the context should be skipped
  # 
  # Works by comparing a Set of identifiers of apps that should not have their
  # context saved to a Set of attributes that provide those identifiers
  # 
  # - Note that this is only an example; add your own list of apps to skip saving the context for here or any other test that makes sense
  # - Note that @app is an instance of [BatchConnect::App](https://github.com/OSC/ood-dashboard/blob/master/app/models/batch_connect/app.rb)
  def should_skip_cache
    # A list of app names or sub_apps we want to skip saving the context for
    Set.new([
      'app_that_should_not_have_its_context_cached',
      'another_special_app',
      # Examples for copy/paste testing at OSC
      'bc_osc_jupyter',  # an app
      'vdi-owens'        # a sub_app
    ]).intersect? Set.new([
      @app.router.name,  # matches the app directory
      @app.sub_app
    ])
  end
end