Bug #16196
closedFilter with Image resource type limited by search to compute resource does not work
Description
Description¶
When you try to create filter that would limit image permissions limited to some compute resource it fails due to bad reference in ruby model.
I Already have a fix here:
https://github.com/theforeman/foreman/compare/1.12-stable...martin-ducar-gd:1.12-stable
However I can't find proper place where to place relevant test as this is highly specific. So some advice would be appreciated
Reproducer¶
#Change these variables to reflect your instalation ROLE_ID=20 HOST=foreman.example.net AUTH="-u test_user:test_pass" SEARCH="compute_resource = test1" curl --fail $AUTH "https://$HOST/api/v2/permissions?per_page=500" >/dev/null 2>&1 ret=$? VIEW_IMAGES_PERM_ID=$(curl --fail $AUTH "https://$HOST/api/v2/permissions?per_page=500" |grep results |sed -e "s/.*view_images\",\"id\":\([0-9][0-9]*\),.*/\1/g") [ -z $VIEW_IMAGES_PERM_ID ] && ret=1 if [ $ret -eq 0 ]; then curl --fail $AUTH -H "Content-Type: application/json" -X POST --data "{\"filter\": {\"role_id\": $ROLE_ID, \"search\": \"$SEARCH\", \"permission_ids\": [$VIEW_IMAGES_PERM_ID]}}" "https://$HOST/api/v2/filters" else echo "ERROR: failed to get view_images permission id" false fi
Expected result¶
{"id":10,"search":"compute_resource = test1","resource_type":"Image","unlimited?":false,"created_at":"2016-08-19T10:00:00Z","updated_at":"2016-08-19T10:00:00Z","role":{"name":"test_role1","id":20},"permissions":[{"name":"view_images","id":75,"resource_type":"Image"}]}
Actual result¶
{ "error": {"id":null,"errors":{"search":["Invalid search query: relation 'compute_resources' not one of audits, operatingsystem, compute_resource, architecture, hosts "]},"full_messages":["Search Invalid search query: relation 'compute_resources' not one of audits, operatingsystem, compute_resource, architecture, hosts "]} }
Updated by Dominic Cleal about 8 years ago
test/unit/image_test.rb would be an appropriate place, calling Image.search_for("..") with some query to check it returns the expected results. Please open a pull request against the develop
branch (https://theforeman.org/contribute.html has more info).
Updated by The Foreman Bot about 8 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3749 added
Updated by Martin Ducar about 8 years ago
Thanks for help here is pull request: https://github.com/theforeman/foreman/pull/3749
Updated by Martin Ducar about 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 96eed04df9ba23e743da161a8afe43cab8e84fcc.
Updated by Dominic Cleal about 8 years ago
- Assignee set to Martin Ducar
- Translation missing: en.field_release set to 175