lib/aptible/rails/controller.rb in aptible-rails-0.6.11 vs lib/aptible/rails/controller.rb in aptible-rails-0.6.12

- old
+ new

@@ -10,11 +10,11 @@ included do helper_method :current_user, :current_organization, :user_url, :organization_url, :criterion_by_handle, :auth_url, :risk_criterion, :policy_criterion, :security_criterion, :training_criterion, :url_helpers, :compliance_alerts, - :criteria + :criteria, :organization_users, :production_apps end def current_user return unless current_user_url @current_user ||= Aptible::Auth::User.find_by_url(current_user_url, @@ -34,10 +34,25 @@ rescue HyperResource::ClientError => e raise e unless e.body['code'] == 403 @current_organization = default_organization end + def organization_users + @organization_users ||= current_organization.users + end + + def production_apps + return @production_apps if @production_apps + accounts = Aptible::Api::Account.all(token: service_token) + accounts = accounts.select do |account| + next unless account.type == 'production' + next unless account.organization == current_organization + true + end + accounts.map(&:apps).flatten.compact + end + def current_organization=(organization) write_shared_cookie(:organization_url, organization.href) end def current_user_url @@ -87,13 +102,11 @@ ) end def compliance_alerts return @compliance_alerts if @compliance_alerts - @apps = Aptible::Api::App.all(token: service_token) - @users = current_organization.users @compliance_alerts = ComplianceAlertCollection.new( - criteria, @apps, @users + criteria, production_apps, organization_users ).all end def service_token return unless session_token && session_token.session