diff --git a/app/models/course.rb b/app/models/course.rb index cb6cb11ec0a..91a06b10435 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -325,8 +325,15 @@ class Course < ActiveRecord::Base end tags = DifferentiableAssignment.scope_filter(tags, user, self, is_teacher: user_is_teacher) + return tags if user.blank? || user_is_teacher - tags + path_visible_pages = self.wiki_pages.left_outer_joins(assignment: :submissions). + except(:preload). + where("assignments.id is null or submissions.user_id = ?", user.id). + select(:id) + + tags.where("content_tags.content_type <> 'WikiPage' or + content_tags.content_id in (?)", path_visible_pages) end def sequential_module_item_ids diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 69aebeeddf1..4e4801c0ec9 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -47,6 +47,7 @@ class WikiPage < ActiveRecord::Base belongs_to :user belongs_to :context, polymorphic: [:course, :group] + belongs_to :assignment acts_as_url :title, :sync_url => true diff --git a/spec/apis/v1/context_module_items_api_spec.rb b/spec/apis/v1/context_module_items_api_spec.rb index 97273b00edb..010ae5cc783 100644 --- a/spec/apis/v1/context_module_items_api_spec.rb +++ b/spec/apis/v1/context_module_items_api_spec.rb @@ -70,6 +70,38 @@ describe "Module Items API", type: :request do course_with_teacher(:course => @course, :active_all => true) end + it 'properly shows a wiki page item locked by CYOE from progressions' do + module_with_page = @course.context_modules.create!(name: "new module") + assignment = @course.assignments.create!( + name: "some assignment", + submission_types: ["online_text_entry"], + points_possible: 20 + ) + module_with_page.add_item(:id => assignment.id, :type => 'assignment') + page = @course.wiki_pages.create!(title: "some page") + page.assignment = @course.assignments.create!( + name: "hidden page", + submission_types: ["wiki_page"], + only_visible_to_overrides: true + ) + page.save! + page_tag = module_with_page.add_item(:id => page.id, :type => 'wiki_page') + quiz = @course.quizzes.create!(:title => "some quiz") + quiz.publish! + module_with_page.add_item(:id => quiz.id, :type => 'quiz') + json = api_call( + :get, "/api/v1/courses/#{@course.id}/"\ + "module_item_sequence?asset_type=Assignment&asset_id=#{assignment.id}", + :controller => "context_module_items_api", + :action => "item_sequence", + :format => "json", + :course_id => @course.to_param, + :asset_type => 'Assignment', + :asset_id => assignment.to_param + ) + expect(json['items'][0]['next']['id']).to eq page_tag.id + end + it "should list module items" do @assignment_tag.unpublish json = api_call(:get, "/api/v1/courses/#{@course.id}/modules/#{@module1.id}/items", @@ -1201,6 +1233,38 @@ describe "Module Items API", type: :request do expect(mastery_paths).to be_truthy end + it 'properly omits a wiki page item locked by CYOE from progressions' do + module_with_page = @course.context_modules.create!(name: "new module") + assignment = @course.assignments.create!( + name: "some assignment", + submission_types: ["online_text_entry"], + points_possible: 20 + ) + module_with_page.add_item(:id => assignment.id, :type => 'assignment') + page = @course.wiki_pages.create!(title: "some page") + page.assignment = @course.assignments.create!( + name: "hidden page", + submission_types: ["wiki_page"], + only_visible_to_overrides: true + ) + page.save! + module_with_page.add_item(:id => page.id, :type => 'wiki_page') + quiz = @course.quizzes.create!(:title => "some quiz") + quiz.publish! + quiz_tag = module_with_page.add_item(:id => quiz.id, :type => 'quiz') + json = api_call( + :get, "/api/v1/courses/#{@course.id}/"\ + "module_item_sequence?asset_type=Assignment&asset_id=#{assignment.id}", + :controller => "context_module_items_api", + :action => "item_sequence", + :format => "json", + :course_id => @course.to_param, + :asset_type => 'Assignment', + :asset_id => assignment.to_param + ) + expect(json['items'][0]['next']['id']).to eq quiz_tag.id + end + it "includes model data merge from Canvas" do json = api_call(:get, "/api/v1/courses/#{@course.id}/modules/#{@cyoe_module2.id}/items?include[]=mastery_paths", :controller => "context_module_items_api", :action => "index", :format => "json",