Module: Dradis::Plugins::ContentService::ContentBlocks

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

Instance Method Summary collapse

Instance Method Details

#all_content_blocksObject



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

def all_content_blocks
  case scope
  when :all
    project.content_blocks
  when :published
    project.content_blocks.published
  else
    raise 'Unsupported scope!'
  end
end

#create_content_block(args = {}) ⇒ Object



16
17
18
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
# File 'lib/dradis/plugins/content_service/content_blocks.rb', line 16

def create_content_block(args={})
  block_group    = args.fetch(:block_group, default_content_block_group)
  content        = args.fetch(:content, default_content_block_content)
  state          = args.fetch(:state, :published)
  user_id        = args.fetch(:user_id)

  content_block = ContentBlock.new(
    content: content,
    block_group: block_group,
    project_id: project.id,
    state: state,
    user_id: user_id
  )

  if content_block.valid?
    content_block.save

    return content_block
  else
    try_rescue_from_length_validation(
      model: content_block,
      field: :content,
      text: content,
      msg: 'Error in create_content_block()',
      tail: plugin_details
    )
  end
end