fix hidden folder/file counts in files API
test plan: - have a folder that contains only hidden files (that is, Restricted Access / Only available to students with link), with at least one image file in there - as a teacher, make sure the image file shows up in the RCE embed-image dialog fixes CNVS-12834 Change-Id: I7e0c5ddc79f3e026f3471599b868d90044e20885 Reviewed-on: https://gerrit.instructure.com/68337 Tested-by: Jenkins Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
2da91413b9
commit
7a1f597c93
|
@ -33,8 +33,8 @@ module Api::V1::Folders
|
|||
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['files_count'] = can_view_hidden_files ? folder.attachments.not_deleted.count : folder.attachments.active.count
|
||||
json['folders_count'] = can_view_hidden_files ? folder.sub_folders.active.count : folder.sub_folders.active.not_hidden.count
|
||||
json['hidden'] = folder.hidden?
|
||||
json['locked_for_user'] = can_view_hidden_files ? false : !!folder.currently_locked
|
||||
json['hidden_for_user'] = can_view_hidden_files ? false : !!folder.hidden?
|
||||
|
|
|
@ -101,13 +101,26 @@ describe "Folders API", type: :request do
|
|||
end
|
||||
|
||||
describe "#show" do
|
||||
it "should have the file and folder counts" do
|
||||
@root.sub_folders.create!(:name => "folder1", :context => @course)
|
||||
@root.sub_folders.create!(:name => "folder2", :context => @course)
|
||||
Attachment.create!(:filename => 'test.txt', :display_name => "testing.txt", :uploaded_data => StringIO.new('file'), :folder => @root, :context => @course)
|
||||
json = api_call(:get, @folders_path + "/#{@root.id}", @folders_path_options.merge(:action => "show"), {})
|
||||
expect(json['files_count']).to eq 1
|
||||
expect(json['folders_count']).to eq 2
|
||||
describe "file and folder counts" do
|
||||
before(:once) do
|
||||
@root.sub_folders.create!(:name => "folder1", :context => @course)
|
||||
@root.sub_folders.create!(:name => "folder2", :context => @course, :workflow_state => 'hidden')
|
||||
Attachment.create!(:filename => 'test1.txt', :display_name => "test1.txt", :uploaded_data => StringIO.new('file'), :folder => @root, :context => @course)
|
||||
Attachment.create!(:filename => 'test2.txt', :display_name => "test2.txt", :uploaded_data => StringIO.new('file'), :folder => @root, :context => @course).update_attribute(:file_state, 'hidden')
|
||||
end
|
||||
|
||||
it "should count hidden items for teachers" do
|
||||
json = api_call(:get, @folders_path + "/#{@root.id}", @folders_path_options.merge(:action => "show"), {})
|
||||
expect(json['files_count']).to eq 2
|
||||
expect(json['folders_count']).to eq 2
|
||||
end
|
||||
|
||||
it "should not count hidden items for students" do
|
||||
student_in_course :active_all => true
|
||||
json = api_call(:get, @folders_path + "/#{@root.id}", @folders_path_options.merge(:action => "show"), {})
|
||||
expect(json['files_count']).to eq 1
|
||||
expect(json['folders_count']).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
it "should have url to list file and folder listings" do
|
||||
|
|
Loading…
Reference in New Issue