fix return type for locked_for_user in folders api

fixes #9975

test plan:
 - retrieve a folder using the API
 - locked_for_user should be a single boolean value

Change-Id: I2bd6fcde8554be35ac497700c9e30a714fe96bed
Reviewed-on: https://gerrit.instructure.com/12975
Reviewed-by: Brian Palmer <brianp@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
Jeremy Stanley 2012-08-16 14:25:55 -06:00
parent 8249329f9b
commit 81dbbf02fa
2 changed files with 19 additions and 2 deletions

View File

@ -28,14 +28,15 @@ module Api::V1::Folders
def folder_json(folder, user, session, opts={})
can_manage_files = opts.has_key?(:can_manage_files) ? opts[:can_manage_files] : folder.grants_right?(user, nil, :update)
json = api_json(folder, user, session,
:only => %w(id name full_name position parent_folder_id context_type context_id unlock_at locked lock_at created_at updated_at))
:only => %w(id name full_name position parent_folder_id context_type context_id unlock_at lock_at created_at updated_at))
if folder
json['locked'] = !!folder.locked
json['folders_url'] = api_v1_list_folders_url(folder)
json['files_url'] = api_v1_list_files_url(folder)
json['files_count'] = folder.attachments.active.count
json['folders_count'] = folder.sub_folders.active.count
json['hidden'] = folder.hidden?
json['locked_for_user'] = can_manage_files ? false : !!folder.currently_locked,
json['locked_for_user'] = can_manage_files ? false : !!folder.currently_locked
json['hidden_for_user'] = can_manage_files ? false : !!folder.hidden?
end
json

View File

@ -133,6 +133,22 @@ describe "Folders API", :type => :integration do
raw_api_call(:get, @folders_path + "/#{f1.id}", @folders_path_options.merge(:action => "show", :id => f1.id.to_param), {}, {}, :expected_status => 404)
end
it "should return correct locked values" do
json = api_call(:get, @folders_path + "/#{@root.id}", @folders_path_options.merge(:action => "show"), {})
json["locked_for_user"].should == false
json["locked"].should == false
locked = @root.sub_folders.create!(:name => "locked", :context => @course, :position => 4, :locked => true)
json = api_call(:get, @folders_path + "/#{locked.id}", @folders_path_options.merge(:action => "show", :id => locked.id.to_param), {})
json["locked"].should == true
json["locked_for_user"].should == false
student_in_course(:course => @course, :active_all => true)
json = api_call(:get, @folders_path + "/#{@root.id}/folders", @folders_path_options, {})
json[0]["locked"].should == true
json[0]["locked_for_user"].should == true
end
describe "folder in context" do
it "should get the root folder for a course" do
json = api_call(:get, "/api/v1/courses/#{@course.id}/folders/root", @folders_path_options.merge(:action => "show", :course_id => @course.id.to_param, :id => 'root'), {})