Project

General

Profile

Revision cc6d0d73

Added by David Davis almost 7 years ago

Fixes #15888 - Remove attr_accessible calls

View differences:

app/controllers/api/v2/registries_controller.rb
1 1
module Api
2 2
  module V2
3 3
    class RegistriesController < ::Api::V2::BaseController
4
      include Foreman::Controller::Parameters::DockerRegistry
4 5
      before_filter :find_resource, :except => %w(index create)
5 6

  
6 7
      resource_description do
......
35 36
      api :POST, '/registries/', N_('Create a docker registry')
36 37
      param_group :registry, :as => :create
37 38
      def create
38
        @registry = DockerRegistry.new(params[:registry])
39
        @registry = DockerRegistry.new(docker_registry_params)
39 40
        process_response @registry.save
40 41
      end
41 42

  
......
43 44
      param :id, :identifier, :required => true
44 45
      param_group :registry, :as => :update
45 46
      def update
46
        process_response @registry.update_attributes(params[:registry])
47
        process_response @registry.update_attributes(docker_registry_params)
47 48
      end
48 49

  
49 50
      api :DELETE, '/registries/:id/', N_('Delete a docker registry')
app/controllers/concerns/foreman/controller/parameters/docker_registry.rb
1
module Foreman::Controller::Parameters::DockerRegistry
2
  extend ActiveSupport::Concern
3

  
4
  class_methods do
5
    def docker_registry_params_filter
6
      Foreman::ParameterFilter.new(::DockerRegistry).tap do |filter|
7
        filter.permit :name, :url, :username, :password, :description,
8
                      :location_ids => [], :organization_ids => []
9
      end
10
    end
11
  end
12

  
13
  def docker_registry_params
14
    param_name = parameter_filter_context.api? ? 'registry' : 'docker_registry'
15
    self.class.docker_registry_params_filter.filter_params(params, parameter_filter_context,
16
                                                           param_name
17
                                                          )
18
  end
19
end
app/controllers/containers/steps_controller.rb
35 35
    end
36 36

  
37 37
    def build_state
38
      s = @state.send(:"build_#{step}", params[:"docker_container_wizard_states_#{step}"])
38
      s = @state.send(:"build_#{step}", state_params)
39 39
      instance_variable_set("@docker_container_wizard_states_#{step}", s)
40 40
    end
41 41

  
42
    def state_params
43
      attrs = case step
44
              when :preliminary
45
                [:wizard_state, :compute_resource_id]
46
              when :image
47
                [:repository_name, :tag, :wizard_state, :registry_id, :capsule_id, :katello]
48
              when :configuration
49
                [:name, :command, :entrypoint, :cpu_set, :cpu_shares, :memory, :wizard_state]
50
              when :environment
51
                [:tty, :docker_container_wizard_state_id,
52
                 :attach_stdin, :attach_stdout, :attach_stderr,
53
                 :exposed_ports_attributes => [], :environment_variables_attributes => [],
54
                 :dns_attributes => []
55
                ]
56
              end
57

  
58
      params.require("docker_container_wizard_states_#{step}").permit(*attrs)
59
    end
60

  
42 61
    def set_form
43 62
      instance_variable_set(
44 63
        "@docker_container_wizard_states_#{step}",
......
46 65
    end
47 66

  
48 67
    def create_container(start = true)
49
      @state.send(:"create_#{step}", params[:"docker_container_wizard_states_#{step}"])
68
      @state.send(:"create_#{step}", state_params)
50 69
      service = Service::Containers.new
51 70
      container = if start.is_a? TrueClass
52 71
                    service.start_container!(@state)
app/controllers/registries_controller.rb
1 1
class RegistriesController < ::ApplicationController
2 2
  include Foreman::Controller::AutoCompleteSearch
3
  include Foreman::Controller::Parameters::DockerRegistry
3 4
  before_filter :find_registry, :only => [:edit, :update, :destroy]
4 5

  
5 6
  def index
......
12 13
  end
13 14

  
14 15
  def create
15
    @registry = DockerRegistry.new(params[:docker_registry])
16
    @registry = DockerRegistry.new(docker_registry_params)
16 17
    if @registry.save
17 18
      process_success
18 19
    else
......
24 25
  end
25 26

  
26 27
  def update
27
    if @registry.update_attributes(params[:docker_registry])
28
    if @registry.update_attributes(docker_registry_params)
28 29
      process_success
29 30
    else
30 31
      process_error
app/models/container.rb
24 24
  accepts_nested_attributes_for :exposed_ports, :allow_destroy => true
25 25
  scoped_search :on => :name
26 26

  
27
  attr_accessible :command, :repository_name, :name, :compute_resource_id, :entrypoint,
28
                  :cpu_set, :cpu_shares, :memory, :tty, :attach_stdin, :registry_id,
29
                  :attach_stdout, :attach_stderr, :tag, :uuid, :environment_variables_attributes,
30
                  :katello, :exposed_ports_attributes, :dns
31

  
32 27
  validates :name, :uniqueness => { :scope => :compute_resource_id }
33 28

  
34 29
  def repository_pull_url
app/models/docker_container_wizard_states/configuration.rb
3 3
    self.table_name_prefix = 'docker_container_wizard_states_'
4 4
    belongs_to :wizard_state, :class_name => DockerContainerWizardState,
5 5
                              :foreign_key => :docker_container_wizard_state_id
6

  
7
    attr_accessible :name, :command, :entrypoint, :cpu_set, :cpu_shares, :memory, :wizard_state
8 6
  end
9 7
end
app/models/docker_container_wizard_states/environment.rb
3 3
    self.table_name_prefix = 'docker_container_wizard_states_'
4 4
    belongs_to :wizard_state, :class_name => DockerContainerWizardState
5 5

  
6
    attr_accessible :tty, :docker_container_wizard_state_id,
7
                    :attach_stdin, :attach_stdout, :attach_stderr,
8
                    :exposed_ports_attributes, :environment_variables_attributes,
9
                    :dns_attributes
10 6
    # Fix me:
11 7
    # Validations are off on this association as there's a bug in ::Parameter
12 8
    # that forces validation of reference_id. This will fail on new records as
app/models/docker_container_wizard_states/image.rb
7 7

  
8 8
    validates :tag,             :presence => true
9 9
    validates :repository_name, :presence => true
10

  
11
    attr_accessible :repository_name, :tag, :wizard_state, :registry_id, :capsule_id, :katello
12 10
  end
13 11
end
app/models/docker_container_wizard_states/preliminary.rb
2 2
  class Preliminary < ActiveRecord::Base
3 3
    include Taxonomix
4 4

  
5
    attr_accessible :wizard_state, :compute_resource_id
6

  
7 5
    self.table_name_prefix = 'docker_container_wizard_states_'
8 6
    belongs_to :wizard_state, :class_name => DockerContainerWizardState,
9 7
                              :foreign_key => :docker_container_wizard_state_id
app/models/docker_registry.rb
12 12
  has_many :containers, :foreign_key => "registry_id", :dependent => :destroy
13 13
  encrypts :password
14 14

  
15
  attr_accessible :name, :url, :username, :password, :locations, :organizations,
16
    :description
17

  
18 15
  validates_lengths_from_database
19 16
  validates :name, :presence => true, :uniqueness => true
20 17
  validates :url,  :presence => true, :uniqueness => true,
app/models/environment_variable.rb
2 2
  belongs_to :container, :foreign_key => :reference_id, :inverse_of => :environment_variables
3 3
  audited :except => [:priority], :associated_with => :container, :allow_mass_assignment => true
4 4
  validates :name, :uniqueness => { :scope => :reference_id }
5
  attr_accessible :priority
6 5
end
app/models/exposed_port.rb
1 1
class ExposedPort < Parameter
2
  attr_accessible :priority
3 2
  # The Parameter class from which ExposedPort class inherits,validates for the
4 3
  # presence of an  associated domain, operating system, host or host group. We
5 4
  # will have to reset those validations for the  ExposedPort class as  they do
app/models/foreman_docker/dns.rb
2 2

  
3 3
module ForemanDocker
4 4
  class Dns < Parameter
5
    attr_accessible :priority
6

  
7 5
    # The Parameter class from which this Dns class inherits,validates for the
8 6
    # presence of an associated domain,  operating system, host or host group.
9 7
    # We will have to reset those validations for the Dns class as they do not
app/models/foreman_docker/docker.rb
2 2

  
3 3
module ForemanDocker
4 4
  class Docker < ::ComputeResource
5
    attr_accessible :email
6

  
7 5
    validates :url, :format => { :with => URI.regexp }
8 6
    validates :email, :format => { :with => /.+@.+\..+/i }, :allow_blank => true
9 7

  
app/models/service/containers.rb
24 24
    end
25 25

  
26 26
    def create_container_object(wizard_state)
27
      container = Container.new(wizard_state.container_attributes) do |r|
27
      container = Container.new do |r|
28
        r.attributes = wizard_state.container_attributes
28 29
        # eagerly load environment variables and exposed ports configuration
29 30
        state = DockerContainerWizardState.includes(
30 31
          :environment => [:environment_variables, :exposed_ports]).find(wizard_state.id)
......
72 73

  
73 74
    def load_environment_variables(state, r)
74 75
      state.environment_variables.each do |environment_variable|
75
        r.environment_variables.build :name     => environment_variable.name,
76
                                      :value    => environment_variable.value,
77
                                      :priority => environment_variable.priority
76
        var = r.environment_variables.build
77
        var.name = environment_variable.name
78
        var.value = environment_variable.value
79
        var.priority = environment_variable.priority
78 80
      end
79 81
    end
80 82

  
81 83
    def load_exposed_ports(state, r)
82 84
      state.exposed_ports.each do |e|
83
        r.exposed_ports.build :name => e.name,
84
                              :value => e.value,
85
                              :priority => e.priority
85
        port = r.exposed_ports.build
86
        port.name = e.name
87
        port.value = e.value
88
        port.priority = e.priority
86 89
      end
87 90
    end
88 91

  
89 92
    def load_dns(state, r)
90 93
      state.dns.each do |e|
91
        r.dns.build :name => e.name,
92
                    :priority => e.priority
94
        dns = r.dns.build
95
        dns.name = e.name
96
        dns.priority = e.priority
93 97
      end
94 98
    end
95 99

  
lib/foreman_docker/engine.rb
103 103
                     :resource_type => 'Docker/ImageSearch'
104 104
        end
105 105

  
106
        parameter_filter ComputeResource, :email
107

  
106 108
        # apipie API documentation
107 109
        # Only available in 1.8, otherwise it has to be in the initializer below
108 110
        if SETTINGS[:version].to_s.include?('develop') ||

Also available in: Unified diff