2016-06-16 23:09:34 +05:30
|
|
|
module MembershipActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include MembersHelper
|
|
|
|
|
|
|
|
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-08-24 12:49:21 +05:30
|
|
|
@member = membershipable.requesters.find(params[:id])
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
return render_403 unless can?(current_user, action_member_permission(:update, @member), @member)
|
|
|
|
|
|
|
|
@member.accept_request
|
|
|
|
|
|
|
|
redirect_to polymorphic_url([membershipable, :members])
|
|
|
|
end
|
|
|
|
|
|
|
|
def leave
|
2016-08-24 12:49:21 +05:30
|
|
|
@member = membershipable.members.find_by(user_id: current_user) ||
|
|
|
|
membershipable.requesters.find_by(user_id: current_user)
|
|
|
|
Members::DestroyService.new(@member, current_user).execute
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
source_type = @member.real_source_type.humanize(capitalize: false)
|
2016-08-24 12:49:21 +05:30
|
|
|
notice =
|
|
|
|
if @member.request?
|
|
|
|
"Your access request to the #{source_type} has been withdrawn."
|
2016-06-16 23:09:34 +05:30
|
|
|
else
|
2016-08-24 12:49:21 +05:30
|
|
|
"You left the \"#{@member.source.human_name}\" #{source_type}."
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
redirect_path = @member.request? ? @member.source : [:dashboard, @member.real_source_type.tableize]
|
|
|
|
|
|
|
|
redirect_to redirect_path, notice: notice
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def membershipable
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|