Add revisions API and linked property for work packages

This commit adds the following items to the APIv3:

- `WorkPackageRepresenter`: Added linked property `revisions` for
revisions that are linked to this commit (by commit references).
- `RevisionsAPI, RevisionRepresenter`: Browse revision information by ID
pull/3285/head
Oliver Günther 9 years ago
parent bbe0f7a897
commit da9771ae1b
  1. 76
      lib/api/v3/repositories/revision_representer.rb
  2. 61
      lib/api/v3/repositories/revisions_api.rb
  3. 1
      lib/api/v3/root.rb
  4. 4
      lib/api/v3/utilities/path_helper.rb
  5. 14
      lib/api/v3/work_packages/work_package_representer.rb

@ -0,0 +1,76 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# 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-2013 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 doc/COPYRIGHT.rdoc for more details.
#++
API::V3::Utilities::DateTimeFormatter
module API
module V3
module Repositories
class RevisionRepresenter < ::API::Decorators::Single
include API::V3::Utilities
self_link path: :revision,
title_getter: -> (*) { nil }
link :project do
{
href: api_v3_paths.project(represented.project.id),
title: "#{represented.project.name}"
}
end
link :author do
{
href: api_v3_paths.user(represented.user.id),
title: "#{represented.user.name} - #{represented.user.login}"
} unless represented.user.nil?
end
property :id
property :identifier
property :author, as: :authorName
property :message,
exec_context: :decorator,
getter: -> (*) {
::API::Decorators::Formattable.new(represented.comments, format: 'plain')
},
render_nil: true
property :created_at,
getter: -> (*) {
DateTimeFormatter::format_datetime(committed_on)
}
def _type
'Revision'
end
end
end
end
end

@ -0,0 +1,61 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# 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-2013 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 doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module Repositories
class RevisionsAPI < ::API::OpenProjectAPI
resources :revisions do
params do
requires :id, desc: 'Revision id'
end
route_param :id do
helpers do
attr_reader :revision
def revision_representer
RevisionRepresenter.new(@revision)
end
end
before do
@revision = Changeset.find(params[:id])
authorize(:view_changesets, context: @revision.project) do
raise API::Errors::NotFound.new
end
end
get do
revision_representer
end
end
end
end
end
end
end

@ -42,6 +42,7 @@ module API
mount ::API::V3::Projects::ProjectsAPI
mount ::API::V3::Queries::QueriesAPI
mount ::API::V3::Render::RenderAPI
mount ::API::V3::Repositories::RevisionsAPI
mount ::API::V3::Statuses::StatusesAPI
mount ::API::V3::StringObjects::StringObjectsAPI
mount ::API::V3::Types::TypesAPI

@ -114,6 +114,10 @@ module API
"#{root}/relations/#{id}"
end
def self.revision(id)
"#{root}/revisions/#{id}"
end
def self.render_markup(format: nil, link: nil)
format = format || Setting.text_formatting
format = 'plain' if format == '' # Setting will return '' for plain

@ -284,6 +284,14 @@ module API
property :activities, embedded: true, exec_context: :decorator
property :revisions,
embedded: true,
exec_context: :decorator,
if: -> (*) {
current_user_allowed_to(:view_changesets,
context: represented.project)
}
property :version,
embedded: true,
exec_context: :decorator,
@ -312,6 +320,12 @@ module API
end
end
def revisions
represented.changesets.map do |revision|
::API::V3::Repositories::RevisionRepresenter.new(revision, current_user: current_user)
end
end
def watchers
# TODO/LEGACY: why do we need to ensure a specific order here?
watchers = represented.watcher_users.order(User::USER_FORMATS_STRUCTURE[Setting.user_format])

Loading…
Cancel
Save