Module: Dradis::Plugins::ContentService::Issues

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

Instance Method Summary collapse

Instance Method Details

#all_issuesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dradis/plugins/content_service/issues.rb', line 5

def all_issues
  issues =
    case scope
    when :all
      project.issues
    when :published
      project.issues.published
    else
      raise 'Unsupported scope!'
    end

  issues.where(category_id: default_issue_category.id)
end

#create_issue(args = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dradis/plugins/content_service/issues.rb', line 19

def create_issue(args={})
  text = args.fetch(:text, default_issue_text)
  # NOTE that ID is the unique issue identifier assigned by the plugin,
  # and is not to be confused with the Issue#id primary key
  id   = args.fetch(:id, default_issue_id)
  state = args.fetch(:state, @state)

  # Bail if we already have this issue in the cache
  uuid      = [plugin::Engine::plugin_name, id]
  cache_key = uuid.join('-')

  return issue_cache[cache_key] if issue_cache.key?(cache_key)

  # we inject the source Plugin and unique ID into the issue's text
  plugin_details =
    "\n\n#[plugin]#\n#{uuid[0]}\n" \
    "\n\n#[plugin_id]#\n#{uuid[1]}\n"
  text << plugin_details

  issue = Issue.new(text: text) do |i|
    i.author = default_author
    i.node = project.issue_library
    i.category = default_issue_category
    i.state = state
  end

  if issue.valid?
    issue.save
  else
    try_rescue_from_length_validation(
      model: issue,
      field: :text,
      text: text,
      msg: 'Error in create_issue()',
      tail: plugin_details
    )
  end

  issue_cache.store(cache_key, issue)
end

#issue_cacheObject

Accesing the library by primary sorting key. Raise an exception unless the issue library cache has been initialized.



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dradis/plugins/content_service/issues.rb', line 77

def issue_cache
  @issue_cache ||= begin
    issues_map = project.issues.map do |issue|
      cache_key = [
        issue.fields['plugin'],
        issue.fields['plugin_id']
      ].join('-')

      [cache_key, issue]
    end
    Hash[issues_map]
  end
end