-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate React UI for Resource Quota * Add ResourceQuotaForm, CreateResourceQuotaModal, and UpdateResourceQuotaModal * Add ActionableDetail from katello in webpack/lib * Delete Template webpack/src example files * Rely on local store instead of Redux state handling Integrate Resource Quota Rails components * Add Resource Quota model and concerns * Add db migration * Configure engine and register file * Add Rails and API controller with corresponding templates * Configure resourceful routing Integrate Rails tests * Add controller and API controller tests * Add model and helper tests * Add placeholders for service tests
- Loading branch information
1 parent
ccc6333
commit 4b7fc9b
Showing
111 changed files
with
4,514 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ node_modules | |
package-lock.json | ||
Gemfile.lock | ||
coverage | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,31 @@ | ||
require: | ||
- rubocop-performance | ||
- rubocop-rails | ||
- rubocop-minitest | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.5 | ||
TargetRailsVersion: 6.0 | ||
Exclude: | ||
- 'node_modules/**/*' | ||
inherit_gem: | ||
theforeman-rubocop: | ||
- strictest.yml | ||
|
||
inherit_mode: | ||
merge: | ||
- Exclude | ||
|
||
Layout/ArgumentAlignment: | ||
EnforcedStyle: with_fixed_indentation | ||
IndentationWidth: 2 | ||
|
||
Layout/EmptyLineAfterGuardClause: | ||
Gemspec/RequiredRubyVersion: | ||
Enabled: false | ||
|
||
Layout/LineLength: | ||
Enabled: 111 # TODO: discuss and set this | ||
|
||
Rails: | ||
Enabled: true | ||
|
||
Style/Alias: | ||
EnforcedStyle: prefer_alias_method | ||
|
||
# Don't enforce documentation | ||
Style/Documentation: | ||
Metrics/MethodLength: | ||
Enabled: false | ||
|
||
# Don't enforce frozen string literals | ||
Style/FrozenStringLiteralComment: | ||
Metrics/PerceivedComplexity: | ||
Enabled: false | ||
|
||
# Support both ruby19 and hash_rockets | ||
Style/HashSyntax: | ||
Naming/VariableNumber: | ||
Exclude: | ||
- 'test/**/*.rb' | ||
|
||
Rails/SkipsModelValidations: | ||
Exclude: | ||
- 'db/migrate/**/*' | ||
|
||
Style/FormatStringToken: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
gem 'theforeman-rubocop', '~> 0.1.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/controllers/concerns/foreman/controller/parameters/resource_quota.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Foreman | ||
module Controller | ||
module Parameters | ||
module ResourceQuota | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def resource_quota_params_filter | ||
Foreman::ParameterFilter.new(::ForemanResourceQuota::ResourceQuota).tap do |filter| | ||
filter.permit :name | ||
filter.permit :description | ||
filter.permit :cpu_cores | ||
filter.permit :memory_mb | ||
filter.permit :disk_gb | ||
end | ||
end | ||
end | ||
|
||
def resource_quota_params | ||
param_name = parameter_filter_context.api? ? 'resource_quota' : 'foreman_resource_quota_resource_quota' | ||
self.class.resource_quota_params_filter.filter_params(params, parameter_filter_context, param_name) | ||
end | ||
end | ||
end | ||
end | ||
end |
96 changes: 96 additions & 0 deletions
96
app/controllers/foreman_resource_quota/api/v2/resource_quotas_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanResourceQuota | ||
module Api | ||
module V2 | ||
class ResourceQuotasController < ::Api::V2::BaseController | ||
include ::Api::Version2 | ||
include Foreman::Controller::Parameters::ResourceQuota | ||
|
||
resource_description do | ||
resource_id 'resource_quota' | ||
api_version 'v2' | ||
api_base_url '/foreman_resource_quota/api' | ||
end | ||
|
||
before_action :find_resource, only: %i[show update destroy] | ||
before_action :custom_find_resource, only: %i[utilization hosts users usergroups] | ||
|
||
api :GET, '/resource_quotas', N_('List all resource quotas') | ||
param_group :search_and_pagination, ::Api::V2::BaseController | ||
add_scoped_search_description_for(ForemanResourceQuota::ResourceQuota) | ||
def index | ||
@resource_quotas = resource_scope_for_index | ||
end | ||
|
||
api :GET, '/resource_quotas/:id/', N_('Show resource quota') | ||
param :id, :identifier, required: true | ||
def show | ||
end | ||
|
||
api :GET, '/resource_quotas/:id/utilization', N_('Show used resources of assigned hosts') | ||
param :id, :identifier, required: true | ||
def utilization | ||
@resource_quota.determine_utilization | ||
process_response @resource_quota | ||
end | ||
|
||
api :GET, '/resource_quotas/:id/hosts', N_('Show hosts of a resource quota') | ||
param :id, :identifier, required: true | ||
def hosts | ||
process_response @resource_quota.hosts | ||
end | ||
|
||
api :GET, '/resource_quotas/:id/users', N_('Show users of a resource quota') | ||
param :id, :identifier, required: true | ||
def users | ||
process_response @resource_quota.users | ||
end | ||
|
||
api :GET, '/resource_quotas/:id/usergroups', N_('Show usergroups of a resource quota') | ||
param :id, :identifier, required: true | ||
def usergroups | ||
process_response @resource_quota.usergroups | ||
end | ||
|
||
def_param_group :resource_quota do | ||
param :resource_quota, Hash, required: true, action_aware: true do | ||
param :name, String, required: true | ||
# param :operatingsystem_ids, Array, :desc => N_("Operating system IDs") | ||
end | ||
end | ||
|
||
api :POST, '/resource_quotas/', N_('Create a resource quota') | ||
param_group :resource_quota, as: :create | ||
def create | ||
@resource_quota = ForemanResourceQuota::ResourceQuota.new(resource_quota_params) | ||
process_response @resource_quota.save | ||
end | ||
|
||
api :PUT, '/resource_quotas/:id/', N_('Update a resource quota') | ||
param :id, :identifier, required: true | ||
param_group :resource_quota | ||
def update | ||
process_response @resource_quota.update(resource_quota_params) | ||
end | ||
|
||
api :DELETE, '/resource_quotas/:id/', N_('Delete a resource quota') | ||
param :id, :identifier, required: true | ||
def destroy | ||
process_response @resource_quota.destroy | ||
end | ||
|
||
def resource_class | ||
ForemanResourceQuota::ResourceQuota | ||
end | ||
|
||
private | ||
|
||
def custom_find_resource | ||
@resource_quota = ForemanResourceQuota::ResourceQuota.find_by(id: params[:resource_quota_id]) | ||
not_found unless @resource_quota | ||
end | ||
end | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/controllers/foreman_resource_quota/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanResourceQuota | ||
class ApplicationController < ::ApplicationController | ||
def resource_class | ||
"ForemanResourceQuota::#{controller_name.singularize.classify}".constantize | ||
end | ||
end | ||
end |
50 changes: 50 additions & 0 deletions
50
app/controllers/foreman_resource_quota/resource_quotas_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanResourceQuota | ||
class ResourceQuotasController < ::ForemanResourceQuota::ApplicationController | ||
include Foreman::Controller::AutoCompleteSearch | ||
include Foreman::Controller::Parameters::ResourceQuota | ||
|
||
before_action :find_resource, only: %i[edit update destroy] | ||
|
||
def index | ||
@resource_quotas = resource_base.search_for(params[:search], order: params[:order]).paginate(page: params[:page], | ||
per_page: params[:per_page]) | ||
# TODO: Check necessitiy/purpose of authorizer | ||
# AuthorizerHelper#authorizer uses controller_name as variable name, but it fails with namespaces | ||
# @authorizer = Authorizer.new(User.current, collection: @resource_quotas) | ||
end | ||
|
||
def new | ||
@resource_quota = ResourceQuota.new | ||
end | ||
|
||
def create | ||
@resource_quota = ResourceQuota.new(resource_quota_params) | ||
if @resource_quota.save | ||
process_success | ||
else | ||
process_error | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @resource_quota.update(resource_quota_params) | ||
process_success | ||
else | ||
process_error | ||
end | ||
end | ||
|
||
def destroy | ||
if @resource_quota.destroy | ||
process_success | ||
else | ||
process_error | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module ForemanResourceQuota | ||
module HostsHelper | ||
def resource_quota_select(form, user_quotas) | ||
blank_opt = { include_blank: true } | ||
select_items = user_quotas.order(:name) | ||
select_f form, | ||
:resource_quota_id, | ||
select_items, | ||
:id, | ||
:to_label, | ||
blank_opt, | ||
label: _('Resource Quota'), | ||
help_inline: _('Define the Resource Quota this host counts to.') | ||
end | ||
end | ||
end |
Oops, something went wrong.