Class: ForestAdminAgent::Routes::AbstractAuthenticatedRoute

Inherits:
AbstractRoute
  • Object
show all
Defined in:
lib/forest_admin_agent/routes/abstract_authenticated_route.rb

Instance Method Summary collapse

Methods inherited from AbstractRoute

#add_route, #initialize, #routes, #setup_routes

Constructor Details

This class inherits a constructor from ForestAdminAgent::Routes::AbstractRoute

Instance Method Details

#build(args = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/forest_admin_agent/routes/abstract_authenticated_route.rb', line 4

def build(args = {})
  if args.dig(:headers, 'action_dispatch.remote_ip')
    Facades::Whitelist.check_ip(args[:headers]['action_dispatch.remote_ip'].to_s)
  end

  context = super
  context.caller = Utils::QueryStringParser.parse_caller(args)
  context.permissions = ForestAdminAgent::Services::Permissions.new(context.caller)
  context
end

#format_attributes(args, collection) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/forest_admin_agent/routes/abstract_authenticated_route.rb', line 15

def format_attributes(args, collection)
  record = args[:params][:data][:attributes] || {}

  args[:params][:data][:relationships]&.map do |field, value|
    schema = collection.schema[:fields][field]

    record[schema.foreign_key] = value.dig('data', 'id') if schema.type == 'ManyToOne'
  end

  record || {}
end