Skip to content

Commit

Permalink
Merge pull request #46 from allourideas/question-redaction
Browse files Browse the repository at this point in the history
Question redaction
  • Loading branch information
lukebaker authored Oct 28, 2020
2 parents 488a424 + 36274d1 commit b908751
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/util.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b908751

Please sign in to comment.