Sha256: 2c7ba0512c61310e2d15e0e032add8e2d32681d28ae21c9723408a197cbc14d1
Contents?: true
Size: 1.23 KB
Versions: 195
Compression:
Stored size: 1.23 KB
Contents
class RemoveDuplicateViewFilters < ActiveRecord::Migration[4.2] class Role < ApplicationRecord end class Filter < ApplicationRecord belongs_to :role has_many :filterings, :dependent => :destroy has_many :permissions, :through => :filterings scope :unlimited, -> { where(:search => nil, :taxonomy_search => nil) } end class Filtering < ApplicationRecord belongs_to :filter belongs_to :permission end class Permission < ApplicationRecord has_many :filterings, :dependent => :destroy has_many :filters, :through => :filterings end def up viewer_role = Role.find_by(:name => "Viewer") permissions = [:view_activation_keys, :view_content_hosts, :view_content_views, :view_gpg_keys, :view_host_collections, :view_lifecycle_environments, :view_products, :view_subscriptions, :view_sync_plans] permissions.each do |perm_name| permission = Permission.find_by(:name => perm_name) next unless permission filters = Filter.unlimited.joins(:permissions).where(:role => viewer_role, "permissions.id" => [permission.id]) filters.drop(1).each(&:destroy) end end end
Version data entries
195 entries across 195 versions & 1 rubygems