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

Allow partial POST edits on miq policy REST #14518

Merged
merged 1 commit into from
Mar 29, 2017
Merged
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
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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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