Skip to content

Commit

Permalink
Merge pull request #14518 from moolitayer/policy_edit
Browse files Browse the repository at this point in the history
Allow partial POST edits on miq policy REST
  • Loading branch information
abellotti authored Mar 29, 2017
2 parents b7933dc + 8cb8017 commit 6872ded
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/controllers/api/policies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ def create_resource(type, _id, data = {})

def edit_resource(type, id = nil, data = {})
raise BadRequestError, "Must specify an id for editing a #{type} resource" unless id
assert_all_required_fields_exists(data, type, %w(conditions_ids policy_contents))
policy = resource_search(id, type, collection_class(:policies))
begin
add_policies_content(data, policy)
add_policies_content(data, policy) if data["policy_contents"]
policy.conditions = Condition.where(:id => data.delete("conditions_ids")) if data["conditions_ids"]
policy.update_attributes(data)
rescue => err
Expand Down Expand Up @@ -46,7 +45,7 @@ def add_policies_content(data, policy)
policy.miq_policy_contents.destroy_all
data.delete("policy_contents").each do |policy_content|
add_policy_content(policy_content, policy)
end if data["policy_contents"]
end
end

def add_policy_content(policy_content, policy)
Expand Down
9 changes: 9 additions & 0 deletions spec/requests/api/policies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,14 @@ def test_policy_profile_query(object, object_policy_profiles_url)
expect(policy.events.count).to eq(1)
expect(miq_policy.conditions.count).to eq(0)
end

it "edits just the description" do
api_basic_authorize collection_action_identifier(:policies, :edit)
expect(miq_policy.description).to_not eq("BAR")
run_post(policies_url(miq_policy.id), gen_request(:edit, :description => "BAR"))
policy = MiqPolicy.find(response.parsed_body["id"])
expect(response).to have_http_status(:ok)
expect(policy.description).to eq("BAR")
end
end
end

0 comments on commit 6872ded

Please sign in to comment.