Bug 1435777 - error when editing /api/policies/:id resource
Summary: error when editing /api/policies/:id resource
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat CloudForms Management Engine
Classification: Red Hat
Component: API
Version: 5.8.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: GA
: 5.9.0
Assignee: Mooli Tayer
QA Contact: Martin Kourim
URL:
Whiteboard: api:rest
Depends On:
Blocks: 1438420
TreeView+ depends on / blocked
 
Reported: 2017-03-24 18:01 UTC by Martin Kourim
Modified: 2018-03-06 14:54 UTC (History)
4 users (show)

Fixed In Version: 5.9.0.1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1438420 (view as bug list)
Environment:
Last Closed: 2018-03-06 14:54:03 UTC
Category: ---
Cloudforms Team: ---
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

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


Note You need to log in before you can comment on or make changes to this bug.