Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic usage report implementation with reports #10306

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ApplicationRecord < ActiveRecord::Base
end

class Jail < Safemode::Jail
allow :id, :name, :present?
allow :id, :name, :present?, :created_at
end

self.abstract_class = true
Expand Down
2 changes: 1 addition & 1 deletion app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Domain < ApplicationRecord
prop_group :basic_model_props, ApplicationRecord, meta: { example: 'example.com' }
property :fullname, String, desc: 'User name for this domain, e.g. "Primary domain for our company"'
end
class Jail < Safemode::Jail
class Jail < Jail
allow :id, :name, :fullname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're inheriting, I think this is sufficient

Suggested change
allow :id, :name, :fullname
allow :fullname

end

Expand Down
4 changes: 2 additions & 2 deletions app/models/smart_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_features
property :httpboot_https_port, Integer, desc: 'Returns proxy port for HTTPS boot'
property :httpboot_https_port!, Integer, desc: 'Same as httpboot_https_port, but raises Foreman::Exception if no port is set'
end
class Jail < ::Safemode::Jail
allow :id, :name, :hostname, :httpboot_http_port, :httpboot_https_port, :httpboot_http_port!, :httpboot_https_port!, :url
class Jail < Jail
allow :hostname, :httpboot_http_port, :httpboot_https_port, :httpboot_http_port!, :httpboot_https_port!, :url, :feature_details
end
end
3 changes: 2 additions & 1 deletion app/services/foreman/renderer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Configuration
:outofsync_interval,
:default_puppet_environment,
:update_ip_from_built_request,
:lab_features,
]

DEFAULT_ALLOWED_LOADERS = Foreman::Renderer::Scope::Macros::Loaders::LOADERS.map(&:first)
Expand All @@ -138,7 +139,7 @@ def initialize
:allowed_generic_helpers, :allowed_host_helpers, :allowed_loaders

def allowed_helpers
allowed_generic_helpers + allowed_host_helpers + allowed_loaders
allowed_generic_helpers + allowed_host_helpers + allowed_loaders + [:load_any_resource]
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion app/services/foreman/renderer/scope/macros/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ module Loaders
end
end

def load_any_resource(resource:, permission:, search: '', batch: nil)
model = resource.constantize
load_resource(klass: model, search: search, permission: permission, batch: batch)
end

private

# returns a batched relation, use either
Expand All @@ -88,7 +93,8 @@ def load_resource(klass:, search:, permission:, batch: 1_000, includes: nil, lim
base = base.limit(limit) unless limit.nil?
base = base.where(where) unless where.nil?
base = base.select(select) unless select.nil?
base.in_batches(of: batch)
base = base.in_batches(of: batch) unless batch.nil?
base
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions app/views/unattended/report_templates/usage_report.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%#
name: Usage report
snippet: false
model: ReportTemplate
-%>

<%- report_row(item: 'SmartProxy', data: load_smart_proxies(batch: nil).size) -%>
<%- report_row(item: 'SmartProxy_creation', data: load_smart_proxies(batch: nil).map{|p| p.created_at} ) -%>
<%- report_row(item: 'SmartProxy_feature_details', data: load_smart_proxies(batch: nil).map{|p| p.feature_details } ) -%>
<%- report_row(item: 'Experimental', data: global_setting(:lab_features) ) -%>

<%- report_row(item: 'Users', data: load_users(batch: nil).size) -%>
<%- report_row(item: 'Users', data: load_users(batch: nil, search: 'admin = false').size) -%>

<%- report_row(item: 'AnyResource', data: load_any_resource(resource: 'User', permission: 'view_users', batch: nil, search: 'admin = false').size) -%>

<%= report_render -%>
Loading