-
Notifications
You must be signed in to change notification settings - Fork 21.4k
/
permissions_policy.rb
38 lines (35 loc) · 1.09 KB
/
permissions_policy.rb
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
# frozen_string_literal: true
# :markup: markdown
module ActionController # :nodoc:
module PermissionsPolicy
extend ActiveSupport::Concern
module ClassMethods
# Overrides parts of the globally configured `Feature-Policy` header:
#
# class PagesController < ApplicationController
# permissions_policy do |policy|
# policy.geolocation "https://example.com"
# end
# end
#
# Options can be passed similar to `before_action`. For example, pass `only:
# :index` to override the header on the index action only:
#
# class PagesController < ApplicationController
# permissions_policy(only: :index) do |policy|
# policy.camera :self
# end
# end
#
def permissions_policy(**options, &block)
before_action(options) do
if block_given?
policy = request.permissions_policy.clone
instance_exec(policy, &block)
request.permissions_policy = policy
end
end
end
end
end
end