Class: Blacklight::AccessControlsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/blacklight/access_controls_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_access_controls_to_catalog_controllerObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/blacklight/access_controls_generator.rb', line 38

def add_access_controls_to_catalog_controller
  say_status('status', 'ADDING ACCESS CONTROLS TO CATALOG CONTROLLER', :yellow)

  string_to_insert = "  include Blacklight::AccessControls::Catalog\n\n  # Apply the blacklight-access_controls\n  before_action :enforce_show_permissions, only: :show\n\n  EOS\n\n  insert_into_file 'app/controllers/catalog_controller.rb',\n    string_to_insert, after: \"include Blacklight::Catalog\\n\"\nend\n"

#add_access_controls_to_search_builderObject



29
30
31
32
33
34
35
36
# File 'lib/generators/blacklight/access_controls_generator.rb', line 29

def add_access_controls_to_search_builder
  say_status('status', 'ADDING ACCESS CONTROLS TO SEARCH BUILDERS', :yellow)
  options[:search_builders].each do |file_path|
    insert_into_file file_path,
      "  include Blacklight::AccessControls::Enforcement\n\n",
      after: "include Blacklight::Solr::SearchBuilderBehavior\n"
  end
end

#add_access_controls_to_userObject



22
23
24
25
26
27
# File 'lib/generators/blacklight/access_controls_generator.rb', line 22

def add_access_controls_to_user
  say_status('status', 'ADDING ACCESS CONTROLS TO USER MODEL', :yellow)
  insert_into_file File.join('app', 'models', "#{options[:user_model].underscore}.rb"),
    "  include Blacklight::AccessControls::User\n\n",
    after: "include Blacklight::User\n"
end

#add_cancan_abilityObject



53
54
55
56
# File 'lib/generators/blacklight/access_controls_generator.rb', line 53

def add_cancan_ability
  say_status('status', 'ADDING CANCAN ABILITY', :yellow)
  copy_file 'ability.rb', 'app/models/ability.rb'
end

#add_configurationObject



58
59
60
61
# File 'lib/generators/blacklight/access_controls_generator.rb', line 58

def add_configuration
  say_status('status', 'ADDING BLACKLIGHT ACCESS CONTROLS CONFIGURATION', :yellow)
  copy_file 'blacklight_access_controls.rb', 'config/initializers/blacklight_access_controls.rb'
end