mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Adding migration to explicitly grant VO permission where it is currently implicitly granted via managers/owners
In preparation for removing implicitly granted permissions
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
class GrantExplicitVariantOverridePermissions < ActiveRecord::Migration
|
||||
def up
|
||||
hubs = Enterprise.is_distributor
|
||||
|
||||
hubs.each do |hub|
|
||||
next if hub.owner.admin?
|
||||
explicitly_granting_producer_ids = hub.relationships_as_child
|
||||
.with_permission(:create_variant_overrides).map(&:parent_id)
|
||||
|
||||
managed_producer_ids = Enterprise.managed_by(hub.owner).is_primary_producer.pluck(:id)
|
||||
implicitly_granting_producer_ids = managed_producer_ids - explicitly_granting_producer_ids - [hub.id]
|
||||
|
||||
# create explicit VO permissions for producers currently granting implicit permission
|
||||
Enterprise.where(id: implicitly_granting_producer_ids).each do |producer|
|
||||
relationship = producer.relationships_as_parent.find_or_initialize_by_child_id(hub.id)
|
||||
permission = relationship.permissions.find_or_initialize_by_name(:create_variant_overrides)
|
||||
relationship.save! unless permission.persisted?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20160218235221) do
|
||||
ActiveRecord::Schema.define(:version => 20160224034034) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
||||
Reference in New Issue
Block a user