gitlab-org--gitlab-foss/lib/api/services.rb

55 lines
1.4 KiB
Ruby
Raw Normal View History

2013-10-29 14:39:46 +00:00
module API
# Projects API
class Services < Grape::API
before { authenticate! }
before { authorize_admin_project }
2015-08-26 23:58:49 +00:00
2013-10-29 14:39:46 +00:00
resource :projects do
2015-08-26 23:58:49 +00:00
# Set <service_slug> service for project
2013-10-29 14:39:46 +00:00
#
# Example Request:
2015-08-26 23:58:49 +00:00
#
2013-10-29 14:39:46 +00:00
# PUT /projects/:id/services/gitlab-ci
#
2015-08-26 23:58:49 +00:00
put ':id/services/:service_slug' do
if project_service
validators = project_service.class.validators.select do |s|
s.class == ActiveRecord::Validations::PresenceValidator &&
s.attributes != [:project_id]
end
2014-10-14 17:07:34 +00:00
2015-08-26 23:58:49 +00:00
required_attributes! validators.map(&:attributes).flatten.uniq
attrs = attributes_for_keys service_attributes
2014-10-14 17:07:34 +00:00
2015-08-26 23:58:49 +00:00
if project_service.update_attributes(attrs.merge(active: true))
true
else
not_found!
end
2014-10-14 17:07:34 +00:00
end
end
2015-08-26 23:58:49 +00:00
# Delete <service_slug> service for project
2014-10-14 17:07:34 +00:00
#
# Example Request:
2015-08-26 23:58:49 +00:00
#
# DELETE /project/:id/services/gitlab-ci
#
delete ':id/services/:service_slug' do
if project_service
attrs = service_attributes.inject({}) do |hash, key|
hash.merge!(key => nil)
end
if project_service.update_attributes(attrs.merge(active: false))
true
else
not_found!
end
2014-10-14 17:07:34 +00:00
end
end
2013-10-29 14:39:46 +00:00
end
end
end