diff --git a/app/models/question.rb b/app/models/question.rb index 2f776db8..85ba6157 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -44,6 +44,24 @@ def pick(algorithm = nil) named_scope :created_by, lambda { |id| {:conditions => { :local_identifier => id } } } + REDACTED_TEXT = "Redacted at request of wiki survey owner" + + def redact! + self.name = REDACTED_TEXT + self.save! + self.versions.each do |q_ver| + q_ver.name = REDACTED_TEXT + q_ver.save! + end + choices.each do |choice| + choice.data = REDACTED_TEXT + choice.save! + choice.versions.each do |c_ver| + c_ver.data = REDACTED_TEXT + c_ver.save! + end + end + end def create_choices_from_ideas if ideas && ideas.any? diff --git a/lib/tasks/util.rake b/lib/tasks/util.rake index 468417c6..12a0681c 100644 --- a/lib/tasks/util.rake +++ b/lib/tasks/util.rake @@ -10,4 +10,14 @@ namespace :util do u.save! puts "Added user #{args[:email]} with password: #{args[:password]}" end + + desc "Redact question" + task :redact_question, [:question_id] => [:environment] do |t, args| + q = Question.find(args[:question_id]) + puts "Confirm redaction of #{args[:question_id]}: '#{q.name}' [y/N]" + input = STDIN.gets.chomp + raise "Aborting redaction of #{args[:question_id]}" unless input == "y" + q.redact! + puts "Question #{args[:question_id]} has been redacted" + end end diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb index d4ce7971..7c31e869 100644 --- a/spec/models/question_spec.rb +++ b/spec/models/question_spec.rb @@ -252,6 +252,26 @@ @question.reload.prompts.count.should == 0 end + context "redaction" do + before(:all) do + truncate_all + @q = Factory.create(:aoi_question) + end + + it "should redact all choices and question text" do + @q.redact! + @q.name.should == Question::REDACTED_TEXT + latest = @q.versions.latest + latest.previous.name.should == Question::REDACTED_TEXT + @q.choices.each do |choice| + choice.data.should == Question::REDACTED_TEXT + latest = choice.versions.latest + latest.previous.data.should == Question::REDACTED_TEXT + end + end + end + + context "median response per session" do before(:all) do truncate_all