Project

General

Profile

Bug #16196

Filter with Image resource type limited by search to compute resource does not work

Added by Martin Ducar over 3 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Search
Target version:
Difficulty:
trivial
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

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 "]}
}

Associated revisions

Revision 96eed04d (diff)
Added by Martin Ducar over 3 years ago

fixes #16196 - fix typo in image scoped search

Revision 06a7a9bb (diff)
Added by Martin Ducar over 3 years ago

fixes #16196 - fix typo in image scoped search

(cherry picked from commit 96eed04df9ba23e743da161a8afe43cab8e84fcc)

History

#1 Updated by Dominic Cleal over 3 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).

#2 Updated by The Foreman Bot over 3 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3749 added

#3 Updated by Martin Ducar over 3 years ago

Thanks for help here is pull request: https://github.com/theforeman/foreman/pull/3749

#4 Updated by Martin Ducar over 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#5 Updated by Dominic Cleal over 3 years ago

  • Assignee set to Martin Ducar
  • Legacy Backlogs Release (now unused) set to 175

Also available in: Atom PDF