Module: Dradis::Plugins::ContentService::Evidence

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/dradis/plugins/content_service/evidence.rb

Instance Method Summary collapse

Instance Method Details

#create_evidence(args = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dradis/plugins/content_service/evidence.rb', line 5

def create_evidence(args={})
  content = args.fetch(:content, default_evidence_content)
  node    = args.fetch(:node, default_node_parent)
  issue   = args[:issue] || default_evidence_issue

  # Using node.evidence.new would result in some evidence being saved later on.
  evidence = ::Evidence.new(issue_id: issue.id, content: content, node_id: node.id)

  if evidence.valid?
    evidence = ::Evidence.find_or_create_by(issue_id: issue.id, node_id: node.id, content: content)
  else
    try_rescue_from_length_validation(
      model: evidence,
      field: :content,
      text: content,
      msg: 'Error in create_evidence()'
    )
  end

  evidence
end