Sha256: 72476d7425649fab18ae1ccf111618bc8dfcb3ac1defe0b18f2d182f8092cf96

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

module Katello
  module Authorization::ContentView
    extend ActiveSupport::Concern

    include Authorizable

    def readable?
      authorized?(:view_content_views)
    end

    def editable?
      authorized?(:edit_content_views)
    end

    def deletable?
      authorized?(:destroy_content_views)
    end

    def publishable?
      authorized?(:publish_content_views)
    end

    def promotable_or_removable?
      authorized?(:promote_or_remove_content_views) && Katello::KTEnvironment.any_promotable?
    end

    module ClassMethods
      def readable
        authorized(:view_content_views)
      end

      def readable?
        ::User.current.can?(:view_content_views)
      end

      def editable
        authorized(:edit_content_views)
      end

      def deletable
        authorized(:destroy_content_views)
      end

      def deletable
        authorized(:publish_content_views)
      end

      def readable_repositories(repo_ids = nil)
        query = Katello::Repository.scoped
        content_views = Katello::ContentView.readable

        if repo_ids
          query.where(:id => repo_ids)
        else
          content_views = content_views.where(:default => false)
        end

        query.joins(:content_view_version)
             .where("#{Katello::ContentViewVersion.table_name}.content_view_id" => content_views.pluck(:id))
      end

      def readable_products(product_ids = nil)
        query = Katello::Product.scoped
        query = query.where(:id => product_ids) if product_ids

        query.joins(:repositories => :content_view_version)
             .where("#{Katello::ContentViewVersion.table_name}.content_view_id" => ContentView.readable.pluck(:id))
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/models/katello/authorization/content_view.rb
katello-2.4.4 app/models/katello/authorization/content_view.rb
katello-2.4.3 app/models/katello/authorization/content_view.rb
katello-2.4.2 app/models/katello/authorization/content_view.rb
katello-2.4.1 app/models/katello/authorization/content_view.rb
katello-2.4.0 app/models/katello/authorization/content_view.rb
katello-2.4.0.rc3 app/models/katello/authorization/content_view.rb
katello-2.4.0.rc2 app/models/katello/authorization/content_view.rb
katello-2.4.0.rc1 app/models/katello/authorization/content_view.rb