module Dradis::Plugins::ContentService::Issues

Public Instance Methods

all_issues() click to toggle source
# 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={}) click to toggle source
# 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_cache() click to toggle source

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

# 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

Private Instance Methods

default_issue_category() click to toggle source
# File lib/dradis/plugins/content_service/issues.rb, line 94
def default_issue_category
  @default_issue_category ||= Category.issue
end
default_issue_id() click to toggle source
# File lib/dradis/plugins/content_service/issues.rb, line 98
def default_issue_id
  "create_issue() invoked by #{plugin} without an :id parameter"
end
default_issue_text() click to toggle source
# File lib/dradis/plugins/content_service/issues.rb, line 102
def default_issue_text
  "create_issue() invoked by #{plugin} without a :text parameter"
end