Class: Decidim::Plans::RespondToAccessRequest

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/plans/respond_to_access_request.rb

Overview

Common functionality for Accept,RejectAccessToPlan.

Direct Known Subclasses

AcceptAccessToPlan, RejectAccessToPlan

Instance Method Summary collapse

Constructor Details

#initialize(form, current_user) ⇒ RespondToAccessRequest

Public: Initializes the command.

form - A form object with the params. plan - A Decidim::Plans::Plan object. current_user - The current user. requester_user - The user that requested to collaborate.



13
14
15
16
17
18
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 13

def initialize(form, current_user)
  @form = form
  @plan = form.plan
  @current_user = current_user
  @requester_user = form.requester_user
end

Instance Method Details

#authors_eventObject



67
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 67

def authors_event; end

#authors_event_classObject



69
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 69

def authors_event_class; end

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if it wasn’t valid and we couldn’t proceed.

Returns nothing.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 26

def call
  return broadcast(:invalid) if @form.invalid?
  return broadcast(:invalid) if @current_user.nil?

  transaction do
    @plan.requesters.delete @requester_user

    Decidim::Coauthorship.create(
      coauthorable: @plan,
      author: @requester_user
    )
  end

  notify_plan_requester
  notify_plan_authors
  broadcast(:ok, @requester_user)
end

#notify_plan_authorsObject



44
45
46
47
48
49
50
51
52
53
54
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 44

def notify_plan_authors
  Decidim::EventsManager.publish(
    event: authors_event,
    event_class: authors_event_class,
    resource: @plan,
    followers: recipients.uniq,
    extra: {
      requester_id: @requester_user.id
    }
  )
end

#notify_plan_requesterObject



56
57
58
59
60
61
62
63
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 56

def notify_plan_requester
  Decidim::EventsManager.publish(
    event: requester_event,
    event_class: requester_event_class,
    resource: @plan,
    affected_users: [@requester_user]
  )
end

#recipientsObject



65
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 65

def recipients; end

#requester_eventObject



71
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 71

def requester_event; end

#requester_event_classObject



73
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 73

def requester_event_class; end