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



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

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

  string_to_insert = <<-EOS
  include Blacklight::AccessControls::Catalog

  # Apply the blacklight-access_controls
  before_action :enforce_show_permissions, only: :show

  EOS

  insert_into_file 'app/controllers/catalog_controller.rb',
    string_to_insert, after: "include Blacklight::Catalog\n"
end

#add_access_controls_to_search_builderObject



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

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



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

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



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

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

#add_configurationObject



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

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