membership_actions.rb 1.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
module MembershipActions
  extend ActiveSupport::Concern

  def request_access
    membershipable.request_access(current_user)

    redirect_to polymorphic_path(membershipable),
                notice: 'Your request for access has been queued for review.'
  end

  def approve_access_request
12
    Members::ApproveAccessRequestService.new(membershipable, current_user, params).execute
13
14
15
16
17

    redirect_to polymorphic_url([membershipable, :members])
  end

  def leave
18
    Members::DestroyService.new(membershipable, current_user, user_id: current_user.id).execute(:all)
Rémy Coutable's avatar
Rémy Coutable committed
19

20
    source_type = membershipable.class.to_s.humanize(capitalize: false)
21
22
23
    notice =
      if @member.request?
        "Your access request to the #{source_type} has been withdrawn."
24
      else
25
        "You left the \"#{membershipable.human_name}\" #{source_type}."
26
      end
27
    redirect_path = @member.request? ? @member.source : [:dashboard, membershipable.class.to_s.tableize]
28
29

    redirect_to redirect_path, notice: notice
30
31
32
33
34
35
36
37
  end

  protected

  def membershipable
    raise NotImplementedError
  end
end