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

65 lines
1.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module API
# Projects API
class Services < Grape::API
before { authenticate! }
before { authorize_admin_project }
2015-09-25 12:07:36 +05:30
2014-09-02 18:07:02 +05:30
resource :projects do
2015-09-25 12:07:36 +05:30
# Set <service_slug> service for project
2014-09-02 18:07:02 +05:30
#
# Example Request:
2015-09-25 12:07:36 +05:30
#
2014-09-02 18:07:02 +05:30
# PUT /projects/:id/services/gitlab-ci
2015-09-25 12:07:36 +05:30
#
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
required_attributes! validators.map(&:attributes).flatten.uniq
attrs = attributes_for_keys service_attributes
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
if project_service.update_attributes(attrs.merge(active: true))
true
else
not_found!
end
2014-09-02 18:07:02 +05:30
end
end
2015-09-25 12:07:36 +05:30
# Delete <service_slug> service for project
2014-09-02 18:07:02 +05:30
#
# Example Request:
2015-04-26 12:48:37 +05:30
#
2015-09-25 12:07:36 +05:30
# DELETE /project/:id/services/gitlab-ci
2015-04-26 12:48:37 +05:30
#
2015-09-25 12:07:36 +05:30
delete ':id/services/:service_slug' do
if project_service
attrs = service_attributes.inject({}) do |hash, key|
hash.merge!(key => nil)
end
2015-04-26 12:48:37 +05:30
2015-09-25 12:07:36 +05:30
if project_service.update_attributes(attrs.merge(active: false))
true
else
not_found!
end
2015-04-26 12:48:37 +05:30
end
end
2015-09-25 12:07:36 +05:30
# Get <service_slug> service settings for project
2015-04-26 12:48:37 +05:30
#
# Example Request:
2015-09-25 12:07:36 +05:30
#
# GET /project/:id/services/gitlab-ci
#
get ':id/services/:service_slug' do
2015-10-24 18:46:33 +05:30
present project_service, with: Entities::ProjectService, include_passwords: current_user.is_admin?
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
end