Sha256: 38fd61c5f985e0c6ff77ae7a90ec8e03573670f5c5493f0b44302c459f6b6137

Contents?: true

Size: 1.13 KB

Versions: 195

Compression:

Stored size: 1.13 KB

Contents

class FixViewerRole < ActiveRecord::Migration[4.2]
  class Role < ApplicationRecord
    has_many :filters
  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) }

    def resource_type
      type = @resource_type || permissions.first.try(:resource_type)
      type.blank? ? nil : type
    end
  end

  class Filtering < ApplicationRecord
    belongs_to :filter
    belongs_to :permission
  end

  class Permission < ApplicationRecord
  end

  def change
    viewer = Role.find_by name: 'Viewer'
    view_permission = Permission.find_by name: 'view_content_views'

    unless viewer.nil?
      filters = viewer.filters.unlimited.select { |filter| filter.resource_type == 'Katello::ContentView' }
      unless filters.empty?
        filters.each do |filter|
          unwanted_filterings = filter.filterings.select { |filtering| filtering.permission_id != view_permission.id }
          filter.filterings.delete(unwanted_filterings)
        end
      end
    end
  end
end

Version data entries

195 entries across 195 versions & 1 rubygems

Version Path
katello-4.14.2 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.15.0 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.15.0.rc2 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.15.0.rc1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.14.1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.14.0 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.14.0.rc3 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.14.0.rc2 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.14.0.rc1.1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.14.0.rc1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.13.1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.13.0 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.12.1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.13.0.rc1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.12.0 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.12.0.rc3 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.12.0.rc2 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.12.0.rc1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.11.1 db/migrate/20160619223332_fix_viewer_role.rb
katello-4.11.0 db/migrate/20160619223332_fix_viewer_role.rb