Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add API endpoint for job status

Oliver Günther8649280ce1e8
diff --git a/modules/job_status/lib/api/v3/job_status/job_status_api.rb b/modules/job_status/lib/api/v3/job_status/job_status_api.rb
index e69de29bb2d..d1e931726b5 100644
--- a/modules/job_status/lib/api/v3/job_status/job_status_api.rb
+++ b/modules/job_status/lib/api/v3/job_status/job_status_api.rb
@@ -0,0 +1,57 @@
+#-- encoding: UTF-8
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module API
+ module V3
+ module JobStatus
+ class JobStatusAPI < ::API::OpenProjectAPI
+ resources :job_statuses do
+ after_validation do
+ authorize_any([:view_cost_entries, :view_own_cost_entries],
+ global: true,
+ user: current_user)
+ end
+
+ route_param :job_id, type: String, desc: 'Job UUID' do
+ after_validation do
+ @job = ::JobStatus::Status
+ .find_by(job_id: params[:job_id], user_id: current_user.id)
+
+ raise API::Errors::NotFound unless @job
+ end
+
+ get do
+ JobStatusRepresenter.new(@job, current_user: current_user)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/modules/job_status/lib/api/v3/job_status/job_status_representer.rb b/modules/job_status/lib/api/v3/job_status/job_status_representer.rb
index 6bc21e5b892..cf4743bd4b4 100644
--- a/modules/job_status/lib/api/v3/job_status/job_status_representer.rb
+++ b/modules/job_status/lib/api/v3/job_status/job_status_representer.rb
@@ -28,20 +28,23 @@
module API
module V3
- module CostTypes
- class CostTypeRepresenter < ::API::Decorators::Single
- self_link
- property :id, render_nil: true
- property :name, render_nil: true
- property :unit,
+ module JobStatus
+ class JobStatusRepresenter < ::API::Decorators::Single
+ self_link id_attribute: :job_id,
+ title_getter: ->(*) { nil }
+
+ property :job_id
+
+ property :status
+
+ property :message,
render_nil: true
- property :unit_plural,
+
+ property :payload,
render_nil: true
- property :is_default,
- getter: ->(*) { default }
def _type
- 'CostType'
+ 'JobStatus'
end
end
end
diff --git a/modules/job_status/lib/open_project/job_status/engine.rb b/modules/job_status/lib/open_project/job_status/engine.rb
index 13db172cd03..ee54ff1b2d9 100644
--- a/modules/job_status/lib/open_project/job_status/engine.rb
+++ b/modules/job_status/lib/open_project/job_status/engine.rb
@@ -39,6 +39,14 @@ module OpenProject::JobStatus
author_url: 'https://www.openproject.com',
bundled: true
+ add_api_endpoint 'API::V3::Root' do
+ mount ::API::V3::JobStatus::JobStatusAPI
+ end
+
+ add_api_path :job_status do |uuid|
+ "#{root}/job_statuses/#{uuid}"
+ end
+
config.to_prepare do
# Extends the ActiveJob adapter in use (DelayedJob) by a Status which lives
# indenpendently from the job itself (which is deleted once successful or after max attempts).