mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Migration: Revoke variant overrides without permissions
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
class RevokeVariantOverrideswithoutPermissions < ActiveRecord::Migration
|
||||
def up
|
||||
# This process was executed when the permission_revoked_at colum was created (see AddPermissionRevokedAtToVariantOverrides)
|
||||
# It needs to be repeated due to #2739
|
||||
variant_override_hubs = Enterprise.where(id: VariantOverride.all.map(&:hub_id).uniq)
|
||||
|
||||
variant_override_hubs.each do |hub|
|
||||
permitting_producer_ids = hub.relationships_as_child
|
||||
.with_permission(:create_variant_overrides).map(&:parent_id)
|
||||
|
||||
variant_overrides_with_revoked_permissions = VariantOverride.for_hubs(hub)
|
||||
.joins(variant: :product).where("spree_products.supplier_id NOT IN (?)", permitting_producer_ids)
|
||||
|
||||
variant_overrides_with_revoked_permissions.update_all(permission_revoked_at: Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20181010093850) do
|
||||
ActiveRecord::Schema.define(:version => 20181020103501) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
||||
Reference in New Issue
Block a user