Bug 1435777

Summary: error when editing /api/policies/:id resource
Product: Red Hat CloudForms Management Engine Reporter: Martin Kourim <mkourim>
Component: APIAssignee: Mooli Tayer <mtayer>
Status: CLOSED CURRENTRELEASE QA Contact: Martin Kourim <mkourim>
Severity: medium Docs Contact:
Priority: medium    
Version: 5.8.0CC: jhardy, mtayer, obarenbo, simaishi
Target Milestone: GAKeywords: TestOnly
Target Release: 5.9.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: api:rest
Fixed In Version: 5.9.0.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1438420 (view as bug list) Environment:
Last Closed: 2018-03-06 14:54:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1438420    

Description Martin Kourim 2017-03-24 18:01:31 UTC
Description of problem:
When editing /api/policies/:id the action fails with
{
  "error": {
    "kind": "bad_request",
    "message": "Resource conditions_ids, policy_contents needs be specified for creating a new policies",
    "klass": "Api::BadRequestError"
  }
}

The request succeeds when complete data is supplied. However, it's not expected behavior to insist on supplying all the data used for creating the resource just for changing e.g. the description.


Version-Release number of selected component (if applicable):


How reproducible:
Very


Steps to Reproduce:
1. create new policy, e.g. with
POST /api/policies
{
  "action": "create",
  "resources": [{
    "name": "test policy foo",
    "description": "Desc foo",
    "mode": "control",
    "towhat": "ContainerImage",
    "conditions_ids": [ 18, 19 ],
    "policy_contents": [{
      "event_id": 2,
      "actions": [ {"action_id": 1, "opts": { "qualifier": "failure" } } ]
    }]
  }]
}
2. edit the resource
POST /api/policies/:id
{
  "action": "edit",
  "description": "New Desc Bar"
}

Comment 2 Mooli Tayer 2017-03-27 11:25:07 UTC
Note also the error message is wrong since it is talking on creating a resource:
"Resource conditions_ids, policy_contents needs be specified for creating a new policies"

Comment 4 CFME Bot 2017-03-31 21:26:00 UTC
New commit detected on ManageIQ/manageiq/fine:
https://github.com/ManageIQ/manageiq/commit/b402b859f454656abb2dd2d61f1dbb392e6aedf1

commit b402b859f454656abb2dd2d61f1dbb392e6aedf1
Author:     Alberto Bellotti <abellotti.github.com>
AuthorDate: Wed Mar 29 10:19:20 2017 -0400
Commit:     Satoe Imaishi <simaishi>
CommitDate: Fri Mar 31 17:21:07 2017 -0400

    Merge pull request #14518 from moolitayer/policy_edit
    
    Allow partial POST edits on miq policy REST
    (cherry picked from commit 6872ded18179536a845e2e3b26658d1f5a8eb7ad)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1435777

 app/controllers/api/policies_controller.rb | 5 ++---
 spec/requests/api/policies_spec.rb         | 9 +++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

Comment 6 Martin Kourim 2017-10-20 09:26:43 UTC
Verified that the error is not produced on 5.9.0.2