Class: Textus::Application::Writes::Reject

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/application/writes/reject.rb

Instance Method Summary collapse

Constructor Details

#initialize(ctx:, manifest:, file_store:, envelope_io:, bus:, authorizer:, hook_context:) ⇒ Reject

rubocop:disable Metrics/ParameterLists



5
6
7
8
9
10
11
12
13
# File 'lib/textus/application/writes/reject.rb', line 5

def initialize(ctx:, manifest:, file_store:, envelope_io:, bus:, authorizer:, hook_context:) # rubocop:disable Metrics/ParameterLists
  @ctx          = ctx
  @manifest     = manifest
  @file_store   = file_store
  @envelope_io  = envelope_io
  @bus          = bus
  @authorizer   = authorizer
  @hook_context = hook_context
end

Instance Method Details

#call(pending_key) ⇒ Object

Raises:



15
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
# File 'lib/textus/application/writes/reject.rb', line 15

def call(pending_key)
  raise ProposalError.new("only human role can reject proposals; got '#{@ctx.role}'") unless @ctx.role == "human"

  mentry = @manifest.resolver.resolve(pending_key).entry
  unless mentry.in_proposal_zone?
    raise ProposalError.new("reject: '#{pending_key}' is not in a proposal zone (zone=#{mentry.zone})")
  end

  env = Textus::Application::Reads::Get.new(
    ctx: @ctx, manifest: @manifest, file_store: @file_store,
  ).call(pending_key)
  proposal = env.meta&.dig("proposal") or
    raise ProposalError.new("entry has no proposal block: #{pending_key}")
  target_key = proposal["target_key"] or
    raise ProposalError.new("proposal missing target_key")

  Textus::Application::Writes::Delete.new(
    ctx: @ctx, manifest: @manifest, envelope_io: @envelope_io,
    bus: @bus, authorizer: @authorizer, hook_context: @hook_context
  ).call(pending_key, suppress_events: true)

  @bus.publish(:proposal_rejected,
               ctx: @hook_context,
               key: pending_key,
               target_key: target_key)

  { "protocol" => PROTOCOL, "rejected" => pending_key, "target_key" => target_key }
end