-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration: Revoke variant overrides without permissions
- Loading branch information
1 parent
9079437
commit d375bb8
Showing
2 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
db/migrate/20181020103501_revoke_variant_overrideswithout_permissions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters