create "media uploads" folder as hidden

test plan
 - have rcs running
 - in canvas have rce_enhancements flag set to on
 - in a new course in a quiz, use rce to embed an image
 - it should create a new folder in the course
 - it should be set to hidden
 - the image should work for the student when taking a quiz
 - there should not be notifications for the file upload

another simpler way to test this is to just test the api for folders
when calling media_folder it should create the folder as hidden

then in beta or production do the same test above, but manually set the
folder to hidden in the UI or in console to see that users can still see
the files that are in the quiz.

fixes VICE-948
flag=rce_enhancements

Change-Id: I664b08e3918880ec134f5c31fb69efe3886366d8
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/250860
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Matthew Lemon <mlemon@instructure.com>
Product-Review: Matthew Lemon <mlemon@instructure.com>
QA-Review: Matthew Lemon <mlemon@instructure.com>
This commit is contained in:
Rob Orton 2020-10-22 11:44:46 -06:00
parent a636b00cea
commit bb3d27be56
3 changed files with 36 additions and 2 deletions

View File

@ -332,8 +332,11 @@ class Folder < ActiveRecord::Base
folder = nil
context.shard.activate do
Folder.unique_constraint_retry do
folder = context.folders.active.where(:unique_type => unique_type).take
folder ||= context.folders.create!(:unique_type => unique_type, :name => default_name_proc.call, :parent_folder_id => Folder.root_folders(context).first)
folder = context.folders.active.where(unique_type: unique_type).take
folder ||= context.folders.create!(unique_type: unique_type,
name: default_name_proc.call,
parent_folder_id: Folder.root_folders(context).first,
workflow_state: 'hidden')
end
end
folder

View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2020 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
class SetAllMediaUploadFoldersToHidden < ActiveRecord::Migration[5.2]
tag :postdeploy
disable_ddl_transaction!
def up
folders = Folder.where(unique_type: 'media').where.not(workflow_state: 'hidden')
until folders.limit(10_000).update_all(workflow_state: 'hidden') < 10_000 do; end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -232,6 +232,7 @@ describe "Folders API", type: :request do
folder = @course.folders.where(:name => "Uploaded Media").first
expect(folder.unique_type).to eq Folder::MEDIA_TYPE
expect(json['id']).to eq folder.id
expect(json['hidden']).to be_truthy
# get the same one twice
json2 = api_call(:get, "/api/v1/courses/#{@course.id}/folders/media", @folders_path_options.