Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Route to query an object based on name.

Change-Id: I3922704ae686c1c3ee40ff2d1ee8cc3385edd940
  • Loading branch information...
commit 8a8c639b7015e1f66db93639d02402e8dba453b4 1 parent baa9ab3
@joeldsa joeldsa authored
View
10 lib/acm/routes/object_controller.rb
@@ -24,6 +24,16 @@ class ApiController < Sinatra::Base
@object_service.read_object(params[:object_id])
end
+ get '/objects/?' do
+ content_type 'application/json', :charset => 'utf-8'
+
+ if params.nil? || params[:name].nil?
+ raise ACM::ObjectNotFound.new("")
+ end
+
+ @object_service.query_object(params)
+ end
+
get '/objects/:object_id/users' do
content_type 'application/json', :charset => 'utf-8'
View
4 lib/acm/services/object_service.rb
@@ -653,6 +653,10 @@ def get_users_for_object(obj_id)
user_permission_entries.to_json
end
+ def query_object(params)
+ ACM::Models::Objects.filter(:name => params[:name]).select(:immutable_id).all().map{|object| object.immutable_id}.to_json
+ end
+
end
end
View
13 spec/functional/object_controller_spec.rb
@@ -427,6 +427,19 @@ def app
body[:description].should include("not found")
end
+ it "should return the set of object ids when queried by name" do
+ basic_authorize "admin", "password"
+
+ get "/objects?name=www_staging", {}, { "CONTENT_TYPE" => "application/json" }
+ last_response.status.should eql(200)
+ last_response.original_headers["Content-Type"].should eql("application/json;charset=utf-8")
+ last_response.original_headers["Content-Length"].should_not eql("0")
+ last_response.original_headers["X-ACM-Schema-Version"].should eql("urn:acm:schemas:1.0")
+
+ body = Yajl::Parser.parse(last_response.body, :symbolize_keys => true)
+ body.should_not be_nil
+ end
+
end
describe "when deleting an object" do
Please sign in to comment.
Something went wrong with that request. Please try again.