Skip to content

Commit

Permalink
Merge pull request #247 from jntullo/bz_1518803
Browse files Browse the repository at this point in the history
Return property method actions on Generic Object subresources
(cherry picked from commit 78fc3b6)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1530714
  • Loading branch information
abellotti authored and simaishi committed Jan 3, 2018
1 parent c07b0ee commit a5cc345
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def add_actions(json, aspecs, type)
def expand_resource_custom_actions(resource, json, type, physical_attrs)
return unless render_actions(physical_attrs) && collection_config.custom_actions?(type)

href = json.attributes!["href"]
href = @req.subcollection.present? ? normalize_url("#{@req.subcollection}/#{resource.id}") : json.attributes!["href"]
json.actions do |js|
resource_custom_action_names(resource).each do |action|
add_child js, "name" => action, "method" => :post, "href" => href
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/api/generic_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def edit_resource(type, id, data)

private

def resource_custom_action_names(resource)
(property_method_names(resource) << super).flatten
end

def invoke_custom_action(type, resource, action, data)
return super(type, resource.reload, action, data) if resource_custom_action_button(resource, action)
result = begin
Expand All @@ -44,11 +40,6 @@ def invoke_custom_action(type, resource, action, data)
log_result(result)
result
end

def property_method_names(resource)
resource.respond_to?(:property_methods) ? Array(resource.property_methods) : []
end

def method_description(resource, action)
"Invoked method #{resource.generic_object_definition.name}##{action} for Generic Object id: #{resource.id} name: #{resource.name}"
end
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/api/mixins/generic_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ module GenericObjects

private

def resource_custom_action_names(resource)
(property_method_names(resource) << super).flatten
end

def property_method_names(resource)
resource.respond_to?(:property_methods) ? Array(resource.property_methods) : []
end

def create_generic_object(object_definition, data)
data['generic_object_definition'] = object_definition
GenericObject.new(data.except(*ADDITIONAL_ATTRS)).tap do |generic_object|
Expand Down
6 changes: 4 additions & 2 deletions spec/requests/generic_object_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@
object.add_to_property_association('vms', [vm])
end

it 'returns the generic object with property attributes by default' do
it 'returns the generic object with property attributes and custom method actions by default' do
object_def.add_property_method('foo')
api_basic_authorize subcollection_action_identifier(:generic_object_definitions, :generic_objects, :read, :get)

get(api_generic_object_definition_generic_object_url(nil, object_def.id, object.id))
Expand All @@ -143,7 +144,8 @@
'href' => api_generic_object_definition_generic_object_url(nil, object_def, object),
'id' => object.id.to_s,
'name' => 'bar',
'property_attributes' => { 'is_something' => true }
'property_attributes' => { 'is_something' => true },
'actions' => [{'name' => 'foo', 'method' => 'post', 'href' => api_generic_object_url(nil, object.id)}]
}
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
Expand Down

0 comments on commit a5cc345

Please sign in to comment.