gitlab-org--gitlab-foss/app/services/members/request_access_service.rb
Rémy Coutable 94edafdf09 Inverse condition in Members::RequestAccessService
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-09-22 11:12:18 +02:00

25 lines
569 B
Ruby

module Members
class RequestAccessService < BaseService
attr_accessor :source
def initialize(source, current_user)
@source = source
@current_user = current_user
end
def execute
raise Gitlab::Access::AccessDeniedError unless can_request_access?(source)
source.members.create(
access_level: Gitlab::Access::DEVELOPER,
user: current_user,
requested_at: Time.now.utc)
end
private
def can_request_access?(source)
source && can?(current_user, :request_access, source)
end
end
end