Class: Decidim::GroupInvitesController

Inherits:
ApplicationController show all
Includes:
FormFactory, UserGroups
Defined in:
app/controllers/decidim/group_invites_controller.rb

Overview

The controller to manage user groups invitations

Instance Method Summary collapse

Methods included from UserGroups

#enforce_user_groups_enabled

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

#default_locale?

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/decidim/group_invites_controller.rb', line 18

def create
  enforce_permission_to(:manage, :user_group, user_group:)
  @form = form(InviteUserToGroupForm).from_params(params)

  InviteUserToGroup.call(@form, user_group) do
    on(:ok) do
      flash[:notice] = t("group_invites.invite.success", scope: "decidim")
      redirect_to profile_path(user_group.nickname)
    end

    on(:invalid) do
      flash[:alert] = t("group_invites.invite.error", scope: "decidim")
      render action: :index
    end
  end
end

#destroyObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/decidim/group_invites_controller.rb', line 64

def destroy
  enforce_permission_to :reject, :user_group_invitations

  RejectGroupInvitation.call(inviting_user_group, current_user) do
    on(:ok) do
      respond_to do |format|
        format.json do
          render json: { message: t("group_invites.reject.success", scope: "decidim") }
        end
        format.all do
          flash[:notice] = t("group_invites.reject.success", scope: "decidim")
          redirect_to profile_groups_path(current_user.nickname)
        end
      end
    end

    on(:invalid) do
      respond_to do |format|
        format.json do
          render json: { message: t("group_invites.reject.error", scope: "decidim") }, status: :unprocessable_entity
        end
        format.all do
          flash[:alert] = t("group_invites.reject.error", scope: "decidim")
          redirect_to profile_groups_path(current_user.nickname)
        end
      end
    end
  end
end

#indexObject



13
14
15
16
# File 'app/controllers/decidim/group_invites_controller.rb', line 13

def index
  enforce_permission_to(:manage, :user_group, user_group:)
  @form = form(InviteUserToGroupForm).instance
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/decidim/group_invites_controller.rb', line 35

def update
  enforce_permission_to :accept, :user_group_invitations
  AcceptGroupInvitation.call(inviting_user_group, current_user) do
    on(:ok) do
      respond_to do |format|
        format.json do
          render json: { message: t("group_invites.accept.success", scope: "decidim") }
        end
        format.all do
          flash[:notice] = t("group_invites.accept.success", scope: "decidim")
          redirect_to profile_groups_path(current_user.nickname)
        end
      end
    end

    on(:invalid) do
      respond_to do |format|
        format.json do
          render json: { message: t("group_invites.accept.error", scope: "decidim") }, status: :unprocessable_entity
        end
        format.all do
          flash[:alert] = t("group_invites.accept.error", scope: "decidim")
          redirect_to profile_groups_path(current_user.nickname)
        end
      end
    end
  end
end