Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ class ApplicationRecord < ActiveRecord::Base

self.abstract_class = true

def sanitize_fields(*attrs)
attrs.each do |attr|
send("#{attr}=", ActionController::Base.helpers.sanitize(send(attr)))
end
end

end
11 changes: 10 additions & 1 deletion app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ class Plan < ApplicationRecord
end
alias super_settings settings

# =============
# = Callbacks =
# =============

# sanitise html tags e.g remove unwanted 'script'
before_validation lambda { |data|
data.sanitize_fields(:title, :identifier, :description)
}

# =================
# = Class methods =
# =================
Expand All @@ -227,7 +236,7 @@ def self.load_for_phase(plan_id, phase_id)
# Returns Plan
def self.deep_copy(plan)
plan_copy = plan.dup
plan_copy.title = "Copy of " + plan.title
plan_copy.title = "Copy of #{plan.title}"
plan_copy.feedback_requested = false
plan_copy.save!
plan.answers.each do |answer|
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class User < ApplicationRecord
# = Callbacks =
# =============

# sanitise html tags from fields
before_validation ->(data) { data.sanitize_fields(:firstname, :surname) }

after_update :clear_department_id, if: :saved_change_to_org_id?

after_update :delete_perms!, if: :saved_change_to_org_id?, unless: :can_change_org?
Expand Down