debian-mirror-gitlab/lib/api/access_requests.rb

73 lines
2.7 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
module API
class AccessRequests < Grape::API
before { authenticate! }
helpers ::API::Helpers::MembersHelpers
%w[group project].each do |source_type|
2016-11-03 12:29:30 +05:30
params do
requires :id, type: String, desc: "The #{source_type} ID"
end
2016-09-13 17:45:13 +05:30
resource source_type.pluralize do
2016-11-03 12:29:30 +05:30
desc "Gets a list of access requests for a #{source_type}." do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::AccessRequester
end
2016-09-13 17:45:13 +05:30
get ":id/access_requests" do
source = find_source(source_type, params[:id])
2016-11-03 12:29:30 +05:30
access_requesters = AccessRequestsFinder.new(source).execute!(current_user)
access_requesters = paginate(access_requesters.includes(:user))
2016-09-13 17:45:13 +05:30
2016-09-29 09:46:39 +05:30
present access_requesters.map(&:user), with: Entities::AccessRequester, source: source
2016-09-13 17:45:13 +05:30
end
2016-11-03 12:29:30 +05:30
desc "Requests access for the authenticated user to a #{source_type}." do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::AccessRequester
end
2016-09-13 17:45:13 +05:30
post ":id/access_requests" do
source = find_source(source_type, params[:id])
access_requester = source.request_access(current_user)
if access_requester.persisted?
present access_requester.user, with: Entities::AccessRequester, access_requester: access_requester
else
render_validation_error!(access_requester)
end
end
2016-11-03 12:29:30 +05:30
desc 'Approves an access request for the given user.' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities::Member
end
params do
requires :user_id, type: Integer, desc: 'The user ID of the access requester'
optional :access_level, type: Integer, desc: 'A valid access level (defaults: `30`, developer access level)'
end
2016-09-13 17:45:13 +05:30
put ':id/access_requests/:user_id/approve' do
source = find_source(source_type, params[:id])
2016-11-03 12:29:30 +05:30
member = ::Members::ApproveAccessRequestService.new(source, current_user, declared(params)).execute
2016-09-13 17:45:13 +05:30
status :created
present member.user, with: Entities::Member, member: member
end
2016-11-03 12:29:30 +05:30
desc 'Denies an access request for the given user.' do
detail 'This feature was introduced in GitLab 8.11.'
end
params do
requires :user_id, type: Integer, desc: 'The user ID of the access requester'
end
2016-09-13 17:45:13 +05:30
delete ":id/access_requests/:user_id" do
source = find_source(source_type, params[:id])
2016-11-03 12:29:30 +05:30
::Members::DestroyService.new(source, current_user, params).
execute(:requesters)
2016-09-13 17:45:13 +05:30
end
end
end
end
end