Files
openfoodnetwork/lib/tasks/sample_data/permission_factory.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

38 lines
891 B
Ruby

# frozen_string_literal: true
require "tasks/sample_data/logging"
module SampleData
class PermissionFactory
include Logging
def create_samples(enterprises)
all_permissions = [
:add_to_order_cycle,
:manage_products,
:edit_profile,
:create_variant_overrides
]
enterprises.each do |enterprise|
log "#{enterprise.name} permits everybody to do everything."
enterprise_permits_to(enterprise, enterprises, all_permissions)
end
end
private
def enterprise_permits_to(enterprise, receivers, permissions)
receivers.each do |receiver|
EnterpriseRelationship.where(
parent_id: enterprise,
child_id: receiver
).first_or_create!(
parent: enterprise,
child: receiver,
permissions_list: permissions
)
end
end
end
end