Skip to content

Commit

Permalink
Support compressed ids in href slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
imtayadeway committed Aug 4, 2017
1 parent 4b46873 commit 195530a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/api/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Utils
def self.build_href_slug(klass, id)
return unless id
collection = Api::CollectionConfig.new.name_for_subclass(klass)
"#{collection}/#{id}" if collection
"#{collection}/#{ApplicationRecord.compress_id(id)}" if collection
end

def self.resource_search_by_href_slug(href_slug, user = User.current_user)
Expand All @@ -16,7 +16,7 @@ def self.resource_search_by_href_slug(href_slug, user = User.current_user)
raise _("User must be defined") unless user

klass = collection_config.klass(collection)
Rbac.filtered_object(klass.find(id), :user => user, :class => klass)
Rbac.filtered_object(klass.find(ApplicationRecord.uncompress_id(id)), :user => user, :class => klass)
end
end
end
11 changes: 11 additions & 0 deletions spec/lib/api/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,16 @@

expect(actual).to eq(nil)
end

it "can interpret slugs with compressed ids" do
owner_tenant = FactoryGirl.create(:tenant)
owner_group = FactoryGirl.create(:miq_group, :tenant => owner_tenant)
owner = FactoryGirl.create(:user, :miq_groups => [owner_group])
vm = FactoryGirl.create(:vm_vmware, :tenant => owner_tenant)

actual = described_class.resource_search_by_href_slug("vms/#{vm.compressed_id}", owner)

expect(actual).to eq(vm)
end
end
end

0 comments on commit 195530a

Please sign in to comment.