Skip to content

Commit 14591b0

Browse files
Derek DeVriesmaneframe
authored andcommitted
remove non-draft-state features from quizzes
fixes CNVS-16048 test plan: - do regression testing around publishing / unpublishing quizzes - all publishing / unpublishing scenarios should work correctly - make sure to check publishing on: - quizzes#index - quizzes#show - from modules - from module items - make sure that warnings about unpublished quizzes work - make sure that warnings about not being able to unpublish quizzes with submissions work - make sure that the module sequence footer still works on the quizzes page - make sure we can still review published quizzes in speedgrader Change-Id: I1112e3b28ed6388077bfc165056bb1ab0d84b3fd Reviewed-on: https://gerrit.instructure.com/42258 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
1 parent 042dfb3 commit 14591b0

14 files changed

Lines changed: 32 additions & 522 deletions

File tree

app/coffeescripts/models/PublishableModuleItem.coffee

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@ define [
3333
assignment: -> "#{@baseUrl()}/assignments/#{@get('id')}"
3434
discussion_topic: -> "#{@baseUrl()}/discussion_topics/#{@get('id')}"
3535
module: -> "#{@baseUrl()}/modules/#{@get('id')}"
36-
quiz: ->
37-
action = if @get('published') then 'publish' else 'unpublish'
38-
"/courses/#{@get('course_id')}/quizzes/#{action}"
36+
quiz: -> "#{@baseUrl()}/quizzes/#{@get('id')}"
3937

4038
toJSONs:
4139
generic: -> module_item: @attributes
4240
#attachment: -> hidden: !@get('published')
4341
wiki_page: -> wiki_page: @attributes
4442
assignment: -> assignment: @attributes
4543
discussion_topic: -> @attributes
46-
quiz: -> quizzes: [@get('id')]
44+
quiz: -> quiz: @attributes
4745
module: -> module: @attributes
4846

4947
disabledMessages:

app/controllers/quizzes/quizzes_controller.rb

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Quizzes::QuizzesController < ApplicationController
5757
def index
5858
return unless authorized_action(@context, @current_user, :read)
5959
return unless tab_enabled?(@context.class::TAB_QUIZZES)
60-
return index_legacy unless @context.feature_enabled?(:draft_state)
6160

6261
can_manage = is_authorized_action?(@context, @current_user, :manage_assignments)
6362

@@ -131,37 +130,6 @@ def index
131130
log_asset_access("quizzes:#{@context.asset_string}", "quizzes", 'other')
132131
end
133132

134-
# TODO: update non-DS specs to use the DS version and remove this entirely
135-
# as it is no longer available in the UI
136-
def index_legacy
137-
@quizzes = @context.quizzes.active.include_assignment.sort_by do |quiz|
138-
[
139-
(quiz.assignment ? quiz.assignment.due_at : quiz.lock_at) || CanvasSort::Last,
140-
Canvas::ICU.collation_key(quiz.title || CanvasSort::First)
141-
]
142-
end
143-
144-
@unpublished_quizzes = @quizzes.select{|q| !q.available?}
145-
@quizzes = @quizzes.select{|q| q.available?}
146-
@assignment_quizzes = @quizzes.select{|q| q.assignment_id}
147-
@open_quizzes = @quizzes.select{|q| q.quiz_type == 'practice_quiz'}
148-
@surveys = @quizzes.select{|q| q.quiz_type == 'survey' || q.quiz_type == 'graded_survey' }
149-
150-
# needed by _quiz_summary.html.erb
151-
@submissions_hash = if @current_user.present?
152-
@current_user
153-
.quiz_submissions
154-
.where('quizzes.context_id=? AND quizzes.context_type=?', @context, @context.class.to_s)
155-
.includes(:quiz)
156-
.each_with_object({}) { |sub, user_subs| user_subs[sub.quiz_id] = sub }
157-
else
158-
{}
159-
end
160-
161-
log_asset_access("quizzes:#{@context.asset_string}", "quizzes", 'other')
162-
render action: "index_legacy"
163-
end
164-
165133
def show
166134
if @quiz.deleted?
167135
flash[:error] = t('errors.quiz_deleted', "That quiz has been deleted")
@@ -385,9 +353,6 @@ def update
385353
respond_to do |format|
386354
@quiz.transaction do
387355
overrides = delete_override_params
388-
if !@context.feature_enabled?(:draft_state) && params[:activate]
389-
@quiz.with_versioning(true) { @quiz.publish! }
390-
end
391356
notify_of_update = value_to_boolean(params[:quiz][:notify_of_update])
392357
params[:quiz][:notify_of_update] = false
393358

@@ -397,7 +362,7 @@ def update
397362
old_assignment.id = @quiz.assignment.id
398363
end
399364

400-
auto_publish = @context.feature_enabled?(:draft_state) && @quiz.published?
365+
auto_publish = @quiz.published?
401366
@quiz.with_versioning(auto_publish) do
402367
params[:quiz].delete(:only_visible_to_overrides) unless @context.feature_enabled?(:differentiated_assignments)
403368
# using attributes= here so we don't need to make an extra

app/helpers/quizzes_helper.rb

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ module QuizzesHelper
2020
RE_EXTRACT_BLANK_ID = /['"]question_\w+_(.*?)['"]/
2121

2222
def needs_unpublished_warning?(quiz=@quiz, user=@current_user)
23-
if quiz.feature_enabled?(:draft_state)
24-
return false unless can_publish(quiz)
25-
show_unpublished_changes = true
26-
else
27-
return false unless can_read(quiz)
28-
show_unpublished_changes = can_publish(quiz)
29-
end
23+
return false unless can_publish(quiz)
3024

31-
!quiz.available? || (show_unpublished_changes && quiz.unpublished_changes?)
25+
!quiz.available? || quiz.unpublished_changes?
3226
end
3327

3428
def can_read(quiz, user=@current_user)
@@ -46,15 +40,7 @@ def unpublished_quiz_warning
4640
:wrapper => '<strong class=unpublished_quiz_warning>\1</strong>')
4741
end
4842

49-
def unpublished_changes_warning
50-
I18n.t(
51-
'*You have made unpublished changes to this quiz.* '+
52-
'These changes will not appear for students until you publish or ' +
53-
'republish the quiz.',
54-
:wrapper => '<strong class=unpublished_quiz_warning>\1</strong>')
55-
end
56-
57-
def draft_state_unsaved_changes_warning
43+
def unsaved_changes_warning
5844
I18n.t(
5945
'*You have made changes to the questions in this quiz.* '+
6046
'These changes will not appear for students until you ' +
@@ -63,19 +49,11 @@ def draft_state_unsaved_changes_warning
6349
end
6450

6551
def quiz_published_state_warning(quiz=@quiz)
66-
if !quiz.available?
67-
unpublished_quiz_warning
68-
else
69-
if quiz.feature_enabled? :draft_state
70-
draft_state_unsaved_changes_warning
71-
else
72-
unpublished_changes_warning
73-
end
74-
end
52+
!quiz.available? ? unpublished_quiz_warning : unsaved_changes_warning
7553
end
7654

7755
def display_save_button?(quiz=@quiz)
78-
quiz.available? && quiz.feature_enabled?(:draft_state) && can_publish(quiz)
56+
quiz.available? && can_publish(quiz)
7957
end
8058

8159
def render_score(score, precision=2)

app/models/quizzes/quiz.rb

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ def self.polymorphic_names
9999
sanitize_field :description, CanvasSanitize::SANITIZE
100100
copy_authorized_links(:description) { [self.context, nil] }
101101

102-
before_save :generate_quiz_data_on_publish, :if => :needs_republish?
102+
before_save :generate_quiz_data_on_publish, :if => :workflow_state_changed?
103103
before_save :build_assignment
104104
before_save :set_defaults
105-
before_save :flag_columns_that_need_republish
106105
after_save :update_assignment
107106
after_save :touch_context
108107
after_save :regrade_if_published
@@ -179,30 +178,6 @@ def generate_quiz_data_on_publish
179178
end
180179
private :generate_quiz_data_on_publish
181180

182-
# @return [Boolean] Whether the quiz has unsaved changes due for a republish.
183-
def needs_republish?
184-
# TODO: remove this conditional and the non-DS scenario once Draft State is
185-
# permanently turned on
186-
if context.feature_enabled?(:draft_state)
187-
return true if @publishing || workflow_state_changed?
188-
189-
# pre-draft state we need ability to republish things. Since workflow_state
190-
# stays available, we need to flag when we're forcing to publish!
191-
else
192-
return true if @publishing
193-
end
194-
end
195-
196-
# some attributes require us to republish for non-draft state
197-
# We can safely remove this when draft state is permanent
198-
def flag_columns_that_need_republish
199-
return if context.feature_enabled?(:draft_state)
200-
201-
if shuffle_answers_changed? && !shuffle_answers
202-
self.last_edited_at = Time.now.utc
203-
end
204-
end
205-
206181
protected :set_defaults
207182

208183
def new_assignment_id?
@@ -235,14 +210,13 @@ def link_assignment_overrides
235210
end
236211

237212
def build_assignment
238-
if (context.feature_enabled?(:draft_state) || self.available?) &&
239-
!self.assignment_id && self.graded? && ![:assignment, :clone, :migration].include?(@saved_by)
213+
if !self.assignment_id && self.graded? && ![:assignment, :clone, :migration].include?(@saved_by)
240214
assignment = self.assignment
241215
assignment ||= self.context.assignments.build(:title => self.title, :due_at => self.due_at, :submission_types => 'online_quiz')
242216
assignment.assignment_group_id = self.assignment_group_id
243217
assignment.only_visible_to_overrides = self.only_visible_to_overrides
244218
assignment.saved_by = :quiz
245-
if context.feature_enabled?(:draft_state) && !deleted?
219+
unless deleted?
246220
assignment.workflow_state = self.published? ? 'published' : 'unpublished'
247221
end
248222
assignment.save
@@ -445,7 +419,7 @@ def update_assignment
445419
a.assignment_group_id = self.assignment_group_id
446420
a.saved_by = :quiz
447421
a.workflow_state = 'published' if a.deleted?
448-
if context.feature_enabled?(:draft_state) && !deleted?
422+
unless deleted?
449423
a.workflow_state = self.published? ? 'published' : 'unpublished'
450424
end
451425
@notify_of_update ||= a.workflow_state_changed? && a.published?
@@ -1115,8 +1089,7 @@ def self.serialization_excludes
11151089
can :submit
11161090

11171091
given do |user, session|
1118-
(feature_enabled?(:draft_state) ? published? : true) &&
1119-
context.grants_right?(user, session, :read)
1092+
published? && context.grants_right?(user, session, :read)
11201093
end
11211094
can :read
11221095

@@ -1217,10 +1190,8 @@ def unpublish
12171190
end
12181191

12191192
def publish!
1220-
@publishing = true
12211193
publish
12221194
save!
1223-
@publishing = false
12241195
self
12251196
end
12261197

@@ -1305,9 +1276,8 @@ def questions_regraded_since(created_at)
13051276
question_regrades.count
13061277
end
13071278

1308-
# override for draft state
13091279
def available?
1310-
feature_enabled?(:draft_state) ? published? : workflow_state == 'available'
1280+
published?
13111281
end
13121282

13131283
delegate :feature_enabled?, to: :context

app/views/quizzes/quizzes/index_legacy.html.erb

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)