Skip to content

Commit b2bd165

Browse files
author
Derek DeVries
committed
hide unpublished changes notice from students
fixes CNVS-10173 test plan: story 1 - try with both draft state enabled/disabled: - as a teacher - create a new quiz - save and publish the quiz - edit the quiz, and change and update a question, but don't save the quiz - as a student - visit the quiz that the teacher created - you should not see a 'You have made unpublished changes to this quiz' warning story 2: - as a teacher - create a new quiz - save the quiz, don't publish it - as a student - visit the quiz that the teacher created - with draft state enabled - you should get an "Unauthorized" page - without draft state enabled - you should see the quiz page with the notice 'This quiz is unpublished' Change-Id: I0a4933a92ff14e9d1d205219f11846e87a281ee1 Reviewed-on: https://gerrit.instructure.com/27923 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jason Madsen <jmadsen@instructure.com> QA-Review: Myller de Araujo <myller@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
1 parent 8297384 commit b2bd165

3 files changed

Lines changed: 114 additions & 11 deletions

File tree

app/helpers/quizzes_helper.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@
1717
#
1818

1919
module QuizzesHelper
20-
def needs_unpublished_warning?(quiz=@quiz)
20+
def needs_unpublished_warning?(quiz=@quiz, user=@current_user)
2121
if quiz.feature_enabled?(:draft_state)
22-
return false unless quiz.grants_right?(@current_user, session, :read)
22+
return false unless can_publish(quiz)
23+
show_unpublished_changes = true
2324
else
24-
return false unless quiz.grants_right?(@current_user, session, :manage)
25+
return false unless can_read(quiz)
26+
show_unpublished_changes = can_publish(quiz)
2527
end
2628

27-
!quiz.available? || quiz.unpublished_changes?
29+
!quiz.available? || (show_unpublished_changes && quiz.unpublished_changes?)
2830
end
2931

30-
def can_publish(quiz)
31-
can_do(quiz, @current_user, :update) || can_do(quiz, @current_user, :manage)
32+
def can_read(quiz, user=@current_user)
33+
can_do(quiz, user, :read)
34+
end
35+
36+
def can_publish(quiz, user=@current_user)
37+
can_do(quiz, user, :update) || can_do(quiz, user, :manage)
3238
end
3339

3440
def unpublished_quiz_warning

spec/helpers/quizzes_helper_spec.rb

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,93 @@
2323
include ApplicationHelper
2424
include QuizzesHelper
2525

26+
describe "#needs_unpublished_warning" do
27+
before do
28+
course_with_teacher
29+
end
30+
31+
context "with draft state enabled" do
32+
before do
33+
@course.account.enable_feature!(:draft_state)
34+
end
35+
36+
it "is false if quiz not manageable" do
37+
quiz = Quiz.new(:context => @course)
38+
39+
def can_publish(quiz); false; end
40+
needs_unpublished_warning?(quiz, User.new).should be_false
41+
end
42+
43+
it "is false if quiz is available with no unpublished changes" do
44+
quiz = Quiz.new(:context => @course)
45+
quiz.workflow_state = 'available'
46+
quiz.last_edited_at = 10.minutes.ago
47+
quiz.published_at = Time.now
48+
49+
def can_publish(quiz); true; end
50+
needs_unpublished_warning?(quiz, User.new).should be_false
51+
end
52+
53+
it "is true if quiz is not available" do
54+
quiz = Quiz.new(:context => @course)
55+
quiz.workflow_state = 'created'
56+
57+
def can_publish(quiz); true; end
58+
needs_unpublished_warning?(quiz, User.new).should be_true
59+
end
60+
61+
it "is true if quiz has unpublished changes" do
62+
quiz = Quiz.new(:context => @course)
63+
quiz.workflow_state = 'available'
64+
quiz.last_edited_at = Time.now
65+
quiz.published_at = 10.minutes.ago
66+
67+
def can_publish(quiz); true; end
68+
needs_unpublished_warning?(quiz, User.new).should be_true
69+
end
70+
end
71+
72+
context "with draft state disabled" do
73+
74+
it "is false if quiz is not readable" do
75+
quiz = Quiz.new(:context => @course)
76+
77+
def can_read(quiz); false; end
78+
needs_unpublished_warning?(quiz, User.new).should be_false
79+
end
80+
81+
it "is false if quiz is available with no unpublished changes" do
82+
quiz = Quiz.new(:context => @course)
83+
quiz.workflow_state = 'available'
84+
quiz.last_edited_at = 10.minutes.ago
85+
quiz.published_at = Time.now
86+
87+
def can_publish(quiz); true; end
88+
needs_unpublished_warning?(quiz, User.new).should be_false
89+
end
90+
91+
it "is true if quiz is not available" do
92+
quiz = Quiz.new(:context => @course)
93+
quiz.workflow_state = 'created'
94+
95+
def can_read(quiz); true; end
96+
def can_publish(quiz); false; end
97+
needs_unpublished_warning?(quiz, User.new).should be_true
98+
end
99+
100+
it "is true if quiz has unpublished changes" do
101+
quiz = Quiz.new(:context => @course)
102+
quiz.workflow_state = 'available'
103+
quiz.last_edited_at = Time.now
104+
quiz.published_at = 10.minutes.ago
105+
106+
def can_read(quiz); true; end
107+
def can_publish(quiz); true; end
108+
needs_unpublished_warning?(quiz, User.new).should be_true
109+
end
110+
end
111+
end
112+
26113
describe "#attachment_id_for" do
27114

28115
it "returns the attachment id if attachment exists" do
@@ -130,7 +217,7 @@
130217
context 'fill_in_multiple_blanks_question' do
131218
before(:each) do
132219
@question_text = %q|<input name="question_1" 'value={{question_1}}' />|
133-
@answer_list = []
220+
@answer_list = []
134221
@answers = []
135222

136223
def user_content(stuff); stuff; end # mock #user_content
@@ -146,13 +233,13 @@ def user_content(stuff); stuff; end # mock #user_content
146233

147234
html.should == %q|<input name="question_1" 'value=&#39;&gt;&lt;script&gt;alert(&#39;ha!&#39;)&lt;/script&gt;&lt;img' readonly="readonly" aria-label='Fill in the blank, read surrounding text' />|
148235
end
149-
236+
150237
it 'should add an appropriate label' do
151238
html = fill_in_multiple_blanks_question(
152239
:question => {:question_text => @question_text},
153240
:answer_list => @answer_list,
154241
:answers => @answers
155-
)
242+
)
156243

157244
html.should =~ /aria\-label/
158245
html.should =~ /Fill in the blank/

spec/views/quizzes/show.html.erb_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,25 @@
5151
true
5252
end
5353

54-
it "doesn't warn students if quiz is unpublished" do
54+
it "doesn't warn students if quiz is published" do
5555
course_with_student_logged_in(:active_all => true)
56-
quiz = @course.quizzes.create!
56+
quiz = @course.quizzes.build
57+
quiz.publish!
5758
assigns[:quiz] = quiz
5859
view_context
5960
render "quizzes/show"
6061
response.should_not have_tag ".unpublished_warning"
6162
end
6263

64+
it "warns students if quiz is unpublished" do
65+
course_with_student_logged_in(:active_all => true)
66+
quiz = @course.quizzes.create!
67+
assigns[:quiz] = quiz
68+
view_context
69+
render "quizzes/show"
70+
response.should have_tag ".unpublished_warning"
71+
end
72+
6373
it "should show header bar and publish button if draft state enabled" do
6474
Account.default.enable_feature!(:draft_state)
6575

0 commit comments

Comments
 (0)