From a02186c4d2c8e9b3d2da21a4291289bd0eccb2cd Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Mon, 10 Jul 2017 16:25:35 -0400 Subject: [PATCH 1/3] Added support for expression methods --- app/models/miq_ae_method.rb | 6 +++++- spec/support/automation_helper.rb | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/miq_ae_method.rb b/app/models/miq_ae_method.rb index a219f598465..a2d281d27f1 100644 --- a/app/models/miq_ae_method.rb +++ b/app/models/miq_ae_method.rb @@ -16,7 +16,7 @@ class MiqAeMethod < ApplicationRecord AVAILABLE_LANGUAGES = ["ruby", "perl"] # someday, add sh, perl, python, tcl and any other scripting language validates_inclusion_of :language, :in => AVAILABLE_LANGUAGES - AVAILABLE_LOCATIONS = ["builtin", "inline", "uri"] + AVAILABLE_LOCATIONS = %w(builtin inline uri expression).freeze validates_inclusion_of :location, :in => AVAILABLE_LOCATIONS AVAILABLE_SCOPES = ["class", "instance"] validates_inclusion_of :scope, :in => AVAILABLE_SCOPES @@ -33,6 +33,10 @@ def self.available_scopes AVAILABLE_SCOPES end + def self.available_expression_objects + Rbac::Filterer::CLASSES_THAT_PARTICIPATE_IN_RBAC + end + # Validate the syntax of the passed in inline ruby code def self.validate_syntax(code_text) result = MiqSyntaxChecker.check(code_text) diff --git a/spec/support/automation_helper.rb b/spec/support/automation_helper.rb index dc02eb7ca61..ae9b8f6e8c4 100644 --- a/spec/support/automation_helper.rb +++ b/spec/support/automation_helper.rb @@ -35,11 +35,12 @@ def create_ae_model_with_method(attrs = {}) attrs = default_ae_model_attributes(attrs) method_script = attrs.delete(:method_script) method_params = attrs.delete(:method_params) || {} + method_loc = attrs.delete(:method_loc) || "inline" instance_name = attrs.delete(:instance_name) method_name = attrs.delete(:method_name) ae_fields = {'execute' => {:aetype => 'method', :datatype => 'string'}} ae_instances = {instance_name => {'execute' => {:value => method_name}}} - ae_methods = {method_name => {:scope => 'instance', :location => 'inline', + ae_methods = {method_name => {:scope => 'instance', :location => method_loc, :data => method_script, :language => 'ruby', 'params' => method_params}} From 429e702ad58d4a56e0b69cb722516da833ab6d87 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Tue, 11 Jul 2017 15:00:36 -0400 Subject: [PATCH 2/3] Fixed Rubocop warnings --- app/models/miq_ae_method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_ae_method.rb b/app/models/miq_ae_method.rb index a2d281d27f1..d7de9154fcc 100644 --- a/app/models/miq_ae_method.rb +++ b/app/models/miq_ae_method.rb @@ -16,7 +16,7 @@ class MiqAeMethod < ApplicationRecord AVAILABLE_LANGUAGES = ["ruby", "perl"] # someday, add sh, perl, python, tcl and any other scripting language validates_inclusion_of :language, :in => AVAILABLE_LANGUAGES - AVAILABLE_LOCATIONS = %w(builtin inline uri expression).freeze + AVAILABLE_LOCATIONS = %w(builtin inline uri expression).freeze validates_inclusion_of :location, :in => AVAILABLE_LOCATIONS AVAILABLE_SCOPES = ["class", "instance"] validates_inclusion_of :scope, :in => AVAILABLE_SCOPES From aa07b39562d61f64ce0e6a806ed450810018c824 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Mon, 24 Jul 2017 12:23:34 -0400 Subject: [PATCH 3/3] Changed to use MiqExpression.tables --- app/models/miq_ae_method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_ae_method.rb b/app/models/miq_ae_method.rb index d7de9154fcc..961af040c40 100644 --- a/app/models/miq_ae_method.rb +++ b/app/models/miq_ae_method.rb @@ -34,7 +34,7 @@ def self.available_scopes end def self.available_expression_objects - Rbac::Filterer::CLASSES_THAT_PARTICIPATE_IN_RBAC + MiqExpression.base_tables end # Validate the syntax of the passed in inline ruby code