2016-07-28 13:28:56 -04:00
|
|
|
module Members
|
|
|
|
class RequestAccessService < BaseService
|
|
|
|
attr_accessor :source
|
|
|
|
|
|
|
|
def initialize(source, current_user)
|
|
|
|
@source = source
|
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-09-22 05:11:33 -04:00
|
|
|
raise Gitlab::Access::AccessDeniedError unless can_request_access?(source)
|
2016-07-28 13:28:56 -04:00
|
|
|
|
|
|
|
source.members.create(
|
|
|
|
access_level: Gitlab::Access::DEVELOPER,
|
|
|
|
user: current_user,
|
|
|
|
requested_at: Time.now.utc)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-22 05:11:33 -04:00
|
|
|
def can_request_access?(source)
|
|
|
|
source && can?(current_user, :request_access, source)
|
2016-07-28 13:28:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|