debian-mirror-gitlab/app/controllers/concerns/membership_actions.rb

39 lines
1.1 KiB
Ruby
Raw Normal View History

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-11-03 12:29:30 +05:30
Members::ApproveAccessRequestService.new(membershipable, current_user, params).execute
redirect_to polymorphic_url([membershipable, :members])
end
def leave
2016-11-03 12:29:30 +05:30
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id).
execute(:all)
2016-11-03 12:29:30 +05:30
source_type = membershipable.class.to_s.humanize(capitalize: false)
2016-08-24 12:49:21 +05:30
notice =
2016-11-03 12:29:30 +05:30
if member.request?
2016-08-24 12:49:21 +05:30
"Your access request to the #{source_type} has been withdrawn."
else
2016-11-03 12:29:30 +05:30
"You left the \"#{membershipable.human_name}\" #{source_type}."
end
2016-11-03 12:29:30 +05:30
redirect_path = member.request? ? member.source : [:dashboard, membershipable.class.to_s.tableize]
2016-08-24 12:49:21 +05:30
redirect_to redirect_path, notice: notice
end
protected
def membershipable
raise NotImplementedError
end
end