Module: Exportable

Extended by:
ActiveSupport::Concern
Included in:
Issuable
Defined in:
app/models/concerns/exportable.rb

Instance Method Summary collapse

Instance Method Details

#exportable_association?(association, current_user: nil) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
# File 'app/models/concerns/exportable.rb', line 6

def exportable_association?(association, current_user: nil)
  return false unless respond_to?(association)
  return true if has_many_association?(association)

  readable = try(association)
  return true if readable.nil?

  readable_record?(readable, current_user)
end

#restricted_associations(keys) ⇒ Object



16
17
18
# File 'app/models/concerns/exportable.rb', line 16

def restricted_associations(keys)
  exportable_restricted_associations & keys
end

#to_authorized_json(keys_to_authorize, current_user, options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/concerns/exportable.rb', line 20

def to_authorized_json(keys_to_authorize, current_user, options)
  modified_options = filtered_associations_opts(options, keys_to_authorize)
  record_hash = as_json(modified_options).with_indifferent_access

  keys_to_authorize.each do |key|
    next unless record_hash.key?(key)

    record_hash[key] = authorized_association_records(key, current_user, options)
  end

  record_hash.to_json
end