Class: Decidim::Proposals::InviteCoauthorsController

Inherits:
ApplicationController show all
Includes:
ControllerHelpers
Defined in:
decidim-proposals/app/controllers/decidim/proposals/invite_coauthors_controller.rb

Instance Method Summary collapse

Methods included from ControllerHelpers

#expose, included, #present, #presenter

Methods inherited from ApplicationController

#proposal_limit, #proposal_limit_reached?, #proposals

Methods inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #set_component_breadcrumb_item

Methods included from RegistersPermissions

register_permissions

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#cancelObject

author cancels invitation



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'decidim-proposals/app/controllers/decidim/proposals/invite_coauthors_controller.rb', line 30

def cancel
  enforce_permission_to :cancel, :proposal_coauthor_invites, { proposal:, coauthor: }

  CancelCoauthorship.call(proposal, coauthor) do
    on(:ok) do
      flash[:notice] = I18n.t("cancel.success", scope: "decidim.proposals.invite_coauthors", author_name: coauthor.name)
    end

    on(:invalid) do
      flash[:alert] = I18n.t("cancel.error", scope: "decidim.proposals.invite_coauthors")
    end
  end

  redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path
end

#createObject

author invites coauthor



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'decidim-proposals/app/controllers/decidim/proposals/invite_coauthors_controller.rb', line 13

def create
  enforce_permission_to :invite, :proposal_coauthor_invites, { proposal:, coauthor: }

  InviteCoauthor.call(proposal, coauthor) do
    on(:ok) do
      flash[:notice] = I18n.t("create.success", scope: "decidim.proposals.invite_coauthors", author_name: coauthor.name)
    end

    on(:invalid) do
      flash[:alert] = I18n.t("create.error", scope: "decidim.proposals.invite_coauthors")
    end
  end

  redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path
end

#destroyObject

coauthor declines invitation



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'decidim-proposals/app/controllers/decidim/proposals/invite_coauthors_controller.rb', line 62

def destroy
  enforce_permission_to :decline, :proposal_coauthor_invites, { proposal:, coauthor: }

  RejectCoauthorship.call(proposal, current_user) do
    on(:ok) do
      render json: { message: I18n.t("destroy.success", scope: "decidim.proposals.invite_coauthors") }
    end

    on(:invalid) do
      render json: { message: I18n.t("destroy.error", scope: "decidim.proposals.invite_coauthors") }, status: :unprocessable_entity
    end
  end
end

#updateObject

coauthor accepts invitation



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'decidim-proposals/app/controllers/decidim/proposals/invite_coauthors_controller.rb', line 47

def update
  enforce_permission_to :accept, :proposal_coauthor_invites, { proposal:, coauthor: }

  AcceptCoauthorship.call(proposal, current_user) do
    on(:ok) do
      render json: { message: I18n.t("update.success", scope: "decidim.proposals.invite_coauthors") }
    end

    on(:invalid) do
      render json: { message: I18n.t("update.error", scope: "decidim.proposals.invite_coauthors") }, status: :unprocessable_entity
    end
  end
end