2016-06-02 12:05:06 -04:00
|
|
|
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
|
2016-09-09 12:06:36 -04:00
|
|
|
Members::ApproveAccessRequestService.new(membershipable, current_user, params).execute
|
2016-06-02 12:05:06 -04:00
|
|
|
|
|
|
|
redirect_to polymorphic_url([membershipable, :members])
|
|
|
|
end
|
|
|
|
|
|
|
|
def leave
|
2016-09-09 12:51:31 -04:00
|
|
|
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id).
|
|
|
|
execute(:all)
|
2016-06-17 08:06:55 -04:00
|
|
|
|
2016-07-28 13:31:17 -04:00
|
|
|
source_type = membershipable.class.to_s.humanize(capitalize: false)
|
2016-06-17 12:59:33 -04:00
|
|
|
notice =
|
2016-09-09 12:51:31 -04:00
|
|
|
if member.request?
|
2016-06-17 12:59:33 -04:00
|
|
|
"Your access request to the #{source_type} has been withdrawn."
|
2016-06-02 12:05:06 -04:00
|
|
|
else
|
2016-07-28 13:31:17 -04:00
|
|
|
"You left the \"#{membershipable.human_name}\" #{source_type}."
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
2016-09-09 12:51:31 -04:00
|
|
|
redirect_path = member.request? ? member.source : [:dashboard, membershipable.class.to_s.tableize]
|
2016-06-17 12:59:33 -04:00
|
|
|
|
|
|
|
redirect_to redirect_path, notice: notice
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def membershipable
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|