summaryrefslogtreecommitdiff
path: root/app/controllers/concerns
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-22 10:47:48 -0300
committerFelipe Artur <felipefac@gmail.com>2016-06-22 10:47:48 -0300
commit2674b548601b279ada46d4b218a9def6fd5b9f6d (patch)
treeca1f09225e4d5b80c800af521735bf34f04e16d0 /app/controllers/concerns
parent8447c6b180297840d835a609d95808834f498d87 (diff)
parent6f6c6f68ea7cb976b6c1598e705ba8b2bdaf05a1 (diff)
downloadgitlab-ce-2674b548601b279ada46d4b218a9def6fd5b9f6d.tar.gz
merge master into issue_3359_3
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r--app/controllers/concerns/membership_actions.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb
new file mode 100644
index 00000000000..52dc396af6a
--- /dev/null
+++ b/app/controllers/concerns/membership_actions.rb
@@ -0,0 +1,43 @@
+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
+ @member = membershipable.members.request.find(params[:id])
+
+ 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
+ @member = membershipable.members.find_by(user_id: current_user)
+ Members::DestroyService.new(@member, current_user).execute
+
+ source_type = @member.real_source_type.humanize(capitalize: false)
+ notice =
+ if @member.request?
+ "Your access request to the #{source_type} has been withdrawn."
+ else
+ "You left the \"#{@member.source.human_name}\" #{source_type}."
+ end
+ redirect_path = @member.request? ? @member.source : [:dashboard, @member.real_source_type.tableize]
+
+ redirect_to redirect_path, notice: notice
+ end
+
+ protected
+
+ def membershipable
+ raise NotImplementedError
+ end
+end