aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/deprecated/base.rb
blob: 5d9cfb153ab49c74c118632a3bcb45dc862d53ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
module ActionController
  class Base
    class << self
      def deprecated_config_accessor(option, message = nil)
        deprecated_config_reader(option, message)
        deprecated_config_writer(option, message)
      end

      def deprecated_config_reader(option, message = nil)
        message ||= "Reading #{option} directly from ActionController::Base is deprecated. " \
                    "Please read it from config.#{option}"

        self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{option}
            ActiveSupport::Deprecation.warn #{message.inspect}, caller
            config.#{option}
          end
        RUBY
      end

      def deprecated_config_writer(option, message = nil)
        message ||= "Setting #{option} directly on ActionController::Base is deprecated. " \
                    "Please set it on config.action_controller.#{option}"

        self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def #{option}=(val)
            ActiveSupport::Deprecation.warn #{message.inspect}, caller
            config.#{option} = val
          end
        RUBY
      end

      def consider_all_requests_local
        ActiveSupport::Deprecation.warn "ActionController::Base.consider_all_requests_local is deprecated, " <<
          "use Rails.application.config.consider_all_requests_local instead", caller
        Rails.application.config.consider_all_requests_local
      end

      def consider_all_requests_local=(value)
        ActiveSupport::Deprecation.warn "ActionController::Base.consider_all_requests_local= is deprecated. " <<
          "Please configure it on your application with config.consider_all_requests_local=", caller
        Rails.application.config.consider_all_requests_local = value
      end

      def allow_concurrency
        ActiveSupport::Deprecation.warn "ActionController::Base.allow_concurrency is deprecated, " <<
          "use Rails.application.config.allow_concurrency instead", caller
        Rails.application.config.allow_concurrency
      end

      def allow_concurrency=(value)
        ActiveSupport::Deprecation.warn "ActionController::Base.allow_concurrency= is deprecated. " <<
          "Please configure it on your application with config.allow_concurrency=", caller
        Rails.application.config.allow_concurrency = value
      end

      def ip_spoofing_check=(value)
        ActiveSupport::Deprecation.warn "ActionController::Base.ip_spoofing_check= is deprecated. " <<
          "Please configure it on your application with config.action_dispatch.ip_spoofing_check=", caller
        Rails.application.config.action_dispatch.ip_spoofing_check = value
      end

      def ip_spoofing_check
        ActiveSupport::Deprecation.warn "ActionController::Base.ip_spoofing_check is deprecated. " <<
          "Configuring ip_spoofing_check on the application configures a middleware.", caller
        Rails.application.config.action_dispatch.ip_spoofing_check
      end

      def cookie_verifier_secret=(value)
        ActiveSupport::Deprecation.warn "ActionController::Base.cookie_verifier_secret= is deprecated. " <<
          "Please configure it on your application with config.secret_token=", caller
      end

      def cookie_verifier_secret
        ActiveSupport::Deprecation.warn "ActionController::Base.cookie_verifier_secret is deprecated.", caller
      end

      def trusted_proxies=(value)
        ActiveSupport::Deprecation.warn "ActionController::Base.trusted_proxies= is deprecated. " <<
          "Please configure it on your application with config.action_dispatch.trusted_proxies=", caller
        Rails.application.config.action_dispatch.ip_spoofing_check = value
      end

      def trusted_proxies
        ActiveSupport::Deprecation.warn "ActionController::Base.trusted_proxies is deprecated. " <<
          "Configuring trusted_proxies on the application configures a middleware.", caller
        Rails.application.config.action_dispatch.ip_spoofing_check = value
      end

      def session(*args)
        ActiveSupport::Deprecation.warn(
          "Disabling sessions for a single controller has been deprecated. " +
          "Sessions are now lazy loaded. So if you don't access them, " +
          "consider them off. You can still modify the session cookie " +
          "options with request.session_options.", caller)
      end

      def session=(value)
        ActiveSupport::Deprecation.warn "ActionController::Base.session= is deprecated. " <<
          "Please configure it on your application with config.session_store :cookie_store, :key => '....'", caller
        if value.delete(:disabled)
          Rails.application.config.session_store :disabled
        else
          store = Rails.application.config.session_store
          Rails.application.config.session_store store, value
        end
      end

      # Controls the resource action separator
      def resource_action_separator
        @resource_action_separator ||= "/"
      end

      def resource_action_separator=(val)
        ActiveSupport::Deprecation.warn "ActionController::Base.resource_action_separator is deprecated and only " \
                                        "works with the deprecated router DSL."
        @resource_action_separator = val
      end

      def use_accept_header
        ActiveSupport::Deprecation.warn "ActionController::Base.use_accept_header doesn't do anything anymore. " \
                                        "The accept header is always taken into account."
      end

      def use_accept_header=(val)
        use_accept_header
      end
    end

    module DeprecatedBehavior
      # This method has been moved to ActionDispatch::Request.filter_parameters
      def filter_parameter_logging(*args, &block)
        ActiveSupport::Deprecation.warn("Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead", caller)
        filter = Rails.application.config.filter_parameters
        filter.concat(args)
        filter << block if block
        filter
      end

      # This was moved to a plugin
      def verify(*args)
        ActiveSupport::Deprecation.warn "verify was removed from Rails and is now available as a plugin. " <<
          "Please install it with `rails plugin install git://github.com/rails/verification.git`.", caller
      end
    end

    extend DeprecatedBehavior

    deprecated_config_writer :session_store
    deprecated_config_writer :session_options
    deprecated_config_accessor :relative_url_root, "relative_url_root is ineffective. Please stop using it"
    deprecated_config_accessor :assets_dir
    deprecated_config_accessor :javascripts_dir
    deprecated_config_accessor :stylesheets_dir

    delegate :consider_all_requests_local, :consider_all_requests_local=,
             :allow_concurrency, :allow_concurrency=, :to => :"self.class"
  end
end