Skip to content

Commit ea5ff36

Browse files
committed
Merge pull request #240 from Dantemss/dont_export_parts_of_multiparts
Don't export parts of multiparts
2 parents 4cde8ec + 5ac2131 commit ea5ff36

File tree

2 files changed

+73
-66
lines changed

2 files changed

+73
-66
lines changed

app/controllers/questions_controller.rb

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2011-2012 Rice University. Licensed under the Affero General Public
1+
# Copyright 2011-2012 Rice University. Licensed under the Affero General Public
22
# License version 3 or later. See the COPYRIGHT file for details.
33

44
class QuestionsController < ApplicationController
@@ -13,31 +13,31 @@ class QuestionsController < ApplicationController
1313
before_filter :except => [:index, :new, :get_started, :search] do @use_columns = true end
1414

1515
# before_filter {@include_autocomplete=true}
16-
16+
1717
autocomplete :tag, :name, :class_name => 'ActsAsTaggableOn::Tag'
18-
18+
1919
def index
2020
@where ||= 'Published Questions'
2121
end
2222

2323
def show
2424
@question = Question.from_param(params[:id])
2525
@unfinished_solutions = !@question.solutions.where{(is_visible == false) & (creator_id == my{present_user.id})}.first.nil?
26-
raise SecurityTransgression unless present_user.can_read?(@question) ||
26+
raise SecurityTransgression unless present_user.can_read?(@question) ||
2727
((request.remote_ip == '50.116.31.239'))
28-
28+
2929
start_time = Time.now if logger.info?
30-
30+
3131
@question.variate!(QuestionVariator.new(params[:seed]))
32-
32+
3333
logger.info {"Variated question #{@question.to_param} with seed " +
3434
"#{params[:seed] || '[unset]'}, duration = #{Time.now-start_time}"}
35-
35+
3636
respond_to do |format|
3737
format.json
38-
format.html
39-
format.qti {
40-
render :template => case params[:version]
38+
format.html
39+
format.qti {
40+
render :template => case params[:version]
4141
when "1.2", nil
4242
"#{view_dir(@question)}/show.1p2"
4343
else
@@ -60,18 +60,18 @@ def history
6060

6161
def new
6262
end
63-
63+
6464
def get_started
6565
end
66-
66+
6767
def create_simple
6868
create(SimpleQuestion.new)
6969
end
70-
70+
7171
def create_multipart
7272
create(MultipartQuestion.new)
7373
end
74-
74+
7575
def edit
7676
@question = Question.from_param(params[:id])
7777
raise SecurityTransgression unless present_user.can_update?(@question)
@@ -83,8 +83,8 @@ def edit
8383
respond_with(@question)
8484
end
8585

86-
87-
# We can't use the normal respond_with here b/c the STI we're using confuses it.
86+
87+
# We can't use the normal respond_with here b/c the STI we're using confuses it.
8888
# Rails tries to render simple_questions/edit when there are update errors, but
8989
# we just want it to go to the questions view.
9090
def update
@@ -100,7 +100,7 @@ def update
100100
return
101101
end
102102

103-
respond_to do |format|
103+
respond_to do |format|
104104
if (@updated = @question.update_attributes(params[:question]))
105105
flash[:notice] = "Your draft has been saved.
106106
Until you publish this draft, please remember that only members of " +
@@ -144,46 +144,46 @@ def preview
144144
raise ActiveRecord::Rollback
145145
end
146146
end
147-
147+
148148
def show_part
149149
@multipart_question = Question.from_param(params[:question_id])
150-
150+
151151
parts = @multipart_question.child_question_parts
152152
raise SecurityTransgression unless parts.length >= params[:part_id].to_i
153-
153+
154154
@question = parts[params[:part_id].to_i-1].child_question
155-
155+
156156
raise SecurityTransgression unless present_user.can_read?(@question)
157-
158-
157+
158+
159159
respond_to do |format|
160160
format.html { render 'questions/show' }
161161
end
162162
end
163-
163+
164164
def tags
165165
@tags = Question.tag_counts_on(:tags)
166166
end
167-
167+
168168
def add_tags
169169
@question = Question.from_param(params[:question_id])
170170
raise SecurityTransgression unless present_user.can_tag?(@question)
171-
171+
172172
incoming_tags = params[:tags].split(",").collect{|t| t.strip}.delete_if{|t| t.blank?}
173-
173+
174174
if incoming_tags.empty?
175175
elsif tags_fail_regex?(incoming_tags)
176176
flash[:alert] = "Tags can only contain letters, numbers, spaces, hyphens, and apostrophes. Multiple tags should be separated by commas."
177177
else
178178
tags = @question.tag_list.concat(incoming_tags).join(", ")
179-
@question.update_attribute(:tag_list, tags)
180-
end
181-
179+
@question.update_attribute(:tag_list, tags)
180+
end
181+
182182
respond_to do |format|
183183
format.js { render :template => 'questions/tags_action' }
184-
end
184+
end
185185
end
186-
186+
187187
def remove_tag
188188
@question = Question.from_param(params[:question_id])
189189
raise SecurityTransgression unless present_user.can_tag?(@question)
@@ -194,23 +194,23 @@ def remove_tag
194194
updated_tag_list = @question.tag_list.reject{|t| target_tag == t}
195195
@question.update_attribute(:tag_list, updated_tag_list)
196196
end
197-
197+
198198
respond_to do |format|
199199
@in_remove_state = true
200200
format.js { render :template => 'questions/tags_action' }
201201
end
202202
end
203-
203+
204204
def tagged
205205
@tags = params[:tags].gsub("_"," ").split("+")
206206
@per_page = params[:per_page] || 20
207-
207+
208208
if tags_fail_regex?(@tags)
209209
@questions = []
210210
flash[:alert] = "The provided tags contain invalid characters."
211211
else
212212
@questions = Question.tagged_with(@tags)
213-
.reject{|q| (q.is_published? && !q.is_latest?) ||
213+
.reject{|q| (q.is_published? && !q.is_latest?) ||
214214
!present_user.can_read?(q)}
215215
.paginate(:page => params[:page], :per_page => @per_page)
216216
end
@@ -231,17 +231,17 @@ def preview_publish
231231
run_prepublish_error_checks(@questions)
232232
respond_with(@questions)
233233
end
234-
234+
235235
def publish
236236
@questions = Question.find(params[:question_ids])
237-
237+
238238
@questions.each { |q|
239239
raise SecurityTransgression unless q.can_be_published_by?(present_user)
240240
}
241241

242242
run_prepublish_error_checks(@questions, false)
243243
error_message = combine_base_error_messages(@questions)
244-
244+
245245
if !error_message.blank?
246246
respond_to do |format|
247247
format.html {
@@ -251,38 +251,38 @@ def publish
251251
format.any(:json,:xml) { raise NotYetImplemented }
252252
end
253253
end
254-
254+
255255
if params[:agreement_checkbox]
256256
@questions.each { |q|
257257
q.publish!(present_user)
258258
}
259-
259+
260260
respond_with(@questions) do |format|
261-
format.html {
262-
redirect_to @questions.size == 1 ?
261+
format.html {
262+
redirect_to @questions.size == 1 ?
263263
question_path(@questions.first) :
264264
questions_path
265265
}
266266
end
267267
else
268-
flash[:alert] = "You must accept the license agreement in order to publish " +
268+
flash[:alert] = "You must accept the license agreement in order to publish " +
269269
((@questions.size == 1) ? "this question." : "these questions.")
270270
respond_with(@questions) do |format|
271271
format.html { redirect_to :back }
272272
end
273273
end
274274
end
275-
275+
276276
def source
277277
@question = Question.from_param(params[:question_id])
278278
raise SecurityTransgression unless @question.can_be_read_by?(present_user)
279279
respond_with(@question)
280280
end
281-
281+
282282
def new_version
283283
@source_question = Question.from_param(params[:question_id])
284284
raise SecurityTransgression unless @source_question.can_be_new_versioned_by?(present_user)
285-
285+
286286
begin
287287
@question = @source_question.new_version!(present_user)
288288
respond_to do |format|
@@ -293,7 +293,7 @@ def new_version
293293
flash[:alert] = "We could not create a derived question as requested."
294294
respond_to do |format|
295295
format.html { redirect_to question_path(@source_question) }
296-
end
296+
end
297297
end
298298
end
299299

@@ -306,7 +306,7 @@ def derivation_dialog
306306

307307
respond_to do |format|
308308
format.js
309-
end
309+
end
310310
end
311311

312312
def new_derivation
@@ -315,7 +315,7 @@ def new_derivation
315315
edit_now = params[:edit] == "now"
316316
raise SecurityTransgression unless (@source_question.can_be_derived_by?(present_user) &&
317317
(!list.nil? && list.can_be_updated_by?(present_user)))
318-
318+
319319
begin
320320
@question = @source_question.new_derivation!(present_user, list)
321321
flash[:notice] = "Derived question created.
@@ -343,23 +343,23 @@ def new_derivation
343343
false
344344
end
345345

346-
# Originally, the license was set with the other attributes on the
347-
# new/edit/update pages. However, we decided to break that out into a
348-
# separate page b/c it wasn't super critical (and because we are going to
346+
# Originally, the license was set with the other attributes on the
347+
# new/edit/update pages. However, we decided to break that out into a
348+
# separate page b/c it wasn't super critical (and because we are going to
349349
# start questions with a default license.) These methods support those pages.
350-
350+
351351
def edit_license
352352
@question = Question.from_param(params[:question_id])
353353
raise SecurityTransgression unless present_user.can_update?(@question)
354354
respond_with(@question)
355355
end
356-
356+
357357
def update_license
358358
@question = Question.from_param(params[:question_id])
359359
raise SecurityTransgression unless present_user.can_update?(@question)
360360

361361
@question.license = License.find(params[:question][:license_id])
362-
362+
363363
respond_to do |format|
364364
if @question.save
365365
format.html { redirect_to question_path(@question) }
@@ -370,6 +370,9 @@ def update_license
370370
end
371371

372372
def search
373+
render text: 'Question search has been temporarily disabled.'
374+
return
375+
373376
@type = params[:type]
374377
@location = params[:location]
375378
@part = params[:part]
@@ -403,34 +406,34 @@ def evaluate
403406
end
404407
end
405408
end
406-
409+
407410
protected
408411

409-
def create(question)
412+
def create(question)
410413
@question = question
411414
raise SecurityTransgression unless present_user.can_create?(@question)
412-
415+
413416
begin
414417
@question.create!(current_user)
415-
418+
416419
respond_to do |format|
417420
format.html { redirect_to edit_question_path(@question) }
418421
end
419422
rescue ActiveRecord::RecordInvalid => invalid
420423
logger.error {"An error occurred when creating a question: #{invalid.message}"}
421-
424+
422425
respond_to do |format|
423-
format.html {
426+
format.html {
424427
begin
425428
redirect_to :back
426429
rescue ActionController::RedirectBackError
427-
redirect_to root_path
430+
redirect_to root_path
428431
end
429432
}
430-
end
433+
end
431434
end
432435
end
433-
436+
434437
def tags_fail_regex?(tags)
435438
tags = [tags].flatten
436439
tags.any?{|tag| (tag =~ /^[A-Za-z\d\-' ]+$/).nil?}

lib/tasks/questions/export/json.rake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ namespace :questions do
1515
.where{(question_collaborators.user_id == user_id) | \
1616
(list_questions.list.list_members.user_id == user_id)}
1717

18+
# Remove parts of multipart questions
19+
questions = questions.joins{parent_question_parts.outer}
20+
.where(parent_question_parts: {id: nil})
21+
1822
questions = questions.includes(:taggings => :tag)
1923
.includes(:list_questions => :list)
2024
.includes(:solutions).uniq.to_a

0 commit comments

Comments
 (0)