Sha256: 1aae470cfda071f6d09d81fbab96c21df5a041852cad93b46fea8132b32e539e

Contents?: true

Size: 1.23 KB

Versions: 24

Compression:

Stored size: 1.23 KB

Contents

class RemoveDuplicateViewFilters < ActiveRecord::Migration
  class Role < ActiveRecord::Base
  end

  class Filter < ActiveRecord::Base
    belongs_to :role
    has_many :filterings, :dependent => :destroy
    has_many :permissions, :through => :filterings

    scope :unlimited, -> { where(:search => nil, :taxonomy_search => nil) }
  end

  class Filtering < ActiveRecord::Base
    belongs_to :filter
    belongs_to :permission
  end

  class Permission < ActiveRecord::Base
    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

24 entries across 24 versions & 1 rubygems

Version Path
katello-3.4.5 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.4 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.2 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.0.2 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.0.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.2 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.0 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.0.rc2 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.4.0.rc1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.1.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.0.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.0 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.0.rc2 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.0.rc1.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.3.0.rc1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.2.1.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.2.1 db/migrate/20160617124149_remove_duplicate_view_filters.rb
katello-3.2.0 db/migrate/20160617124149_remove_duplicate_view_filters.rb