Sha256: 0dbc549f0cf388710ce4606d41c7859da7ae82dfc1c80facccb97a6973aefe11

Contents?: true

Size: 695 Bytes

Versions: 2

Compression:

Stored size: 695 Bytes

Contents

# frozen_string_literal: true

module ApiAuthorizer
  extend ActiveSupport::Concern

  included do
    before_action :hosts_permission
  end

  private

  def hosts_permission
    return if User.current.can?('view_hosts')

    render_error 'access_denied', status: :forbidden,
      locals: { details: N_('Missing one of the required permissions: view_hosts'),
                missing_permissions: 'view_hosts' }
  end

  def resource_scope(_options = {})
    @resource_scope ||= begin
      scope = PreupgradeReport.joins(:host).merge(Host.authorized(:view_hosts, Host))
      scope = scope.where(job_invocation_id: params[:id]) if action_name == 'job_invocation'
      scope
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_leapp-2.0.1 app/controllers/api/v2/concerns/api_authorizer.rb
foreman_leapp-2.0.0 app/controllers/api/v2/concerns/api_authorizer.rb