-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[58520] added first atempts to fetch full tree
- Loading branch information
Showing
9 changed files
with
293 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 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-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 COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module Queries | ||
module CustomFields | ||
module Hierarchy | ||
class ItemQuery | ||
include ::Queries::BaseQuery | ||
include ::Queries::UnpersistedQuery | ||
|
||
def self.model | ||
CustomField::Hierarchy::Item | ||
end | ||
|
||
def default_scope | ||
super | ||
end | ||
Check warning on line 42 in app/models/queries/custom_fields/hierarchy/item_query.rb GitHub Actions / rubocop[rubocop] app/models/queries/custom_fields/hierarchy/item_query.rb#L40-L42 <Lint/UselessMethodDefinition>
Raw output
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 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-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 COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module API | ||
module V3 | ||
module CustomFields | ||
class CustomFieldsAPI < ::API::OpenProjectAPI | ||
resource :custom_fields do | ||
route_param :id, type: Integer, desc: "Custom Field ID" do | ||
after_validation do | ||
authorize_logged_in | ||
|
||
@custom_field = CustomField.find(params[:id]) | ||
end | ||
|
||
mount API::V3::CustomFields::Hierarchy::ItemsAPI | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
lib/api/v3/custom_fields/hierarchy/hierarchy_item_collection_representer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 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-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 COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module API | ||
module V3 | ||
module CustomFields | ||
module Hierarchy | ||
class HierarchyItemCollectionRepresenter < ::API::Decorators::UnpaginatedCollection | ||
property :count, getter: ->(*) { count.size } | ||
|
||
def model_count(models) | ||
super.size | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 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-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 COPYRIGHT and LICENSE files for more details. | ||
#++ | ||
|
||
module API | ||
module V3 | ||
module CustomFields | ||
module Hierarchy | ||
class ItemsAPI < ::API::OpenProjectAPI | ||
helpers do | ||
def start_item(root, parent) | ||
return root if parent.nil? | ||
|
||
start = ::CustomField::Hierarchy::Item.find_by(id: parent) | ||
raise ::API::Errors::NotFound if start.nil? | ||
raise ::API::Errors::NotImplemented unless start.descendant_of?(root) | ||
|
||
start | ||
end | ||
|
||
def item_list(item, depth) | ||
return item.self_and_descendants_preordered if depth.nil? | ||
|
||
d = parse_int(depth) | ||
raise ::API::Errors::InvalidQuery.new("Depth must be a natural number.") if d.nil? || d < 0 | ||
|
||
t = flatten_tree_hash item.hash_tree(limit_depth: d + 1) | ||
Check warning on line 51 in lib/api/v3/custom_fields/hierarchy/items_api.rb GitHub Actions / rubocop[rubocop] lib/api/v3/custom_fields/hierarchy/items_api.rb#L51 <Lint/UselessAssignment>
Raw output
|
||
|
||
item.self_and_descendants_preordered | ||
end | ||
|
||
def flatten_tree_hash(hash) | ||
flat_list = hash.keys | ||
|
||
queue = hash.values | ||
|
||
# {:a => {:b => {:c1 => {:d1 => {}}, :c2 => {:d2 => {}}}, :b2 => {}}} | ||
|
||
while queue.any? | ||
current = queue.shift | ||
flat_list += current.keys | ||
queue.unshift(current.values) | ||
end | ||
|
||
flat_list | ||
end | ||
|
||
def parse_int(str) | ||
Integer(str) | ||
rescue ArgumentError | ||
nil | ||
end | ||
end | ||
|
||
resource :items do | ||
after_validation do | ||
unless @custom_field.field_format_hierarchy? | ||
message = "Hierarchy items do only exists for custom fields of type hierarchy." | ||
raise ::API::Errors::UnprocessableContent.new(message) | ||
end | ||
end | ||
|
||
get do | ||
query = ParamsToQueryService.new(::CustomField::Hierarchy::Item, | ||
current_user, | ||
query_class: ::Queries::CustomFields::Hierarchy::ItemQuery) | ||
.call(params) | ||
|
||
unless query.valid? | ||
raise ::API::Errors::NotImplemented | ||
end | ||
|
||
root_item = query.results.where(custom_field: @custom_field) | ||
raise ::API::Errors::NotImplemented if root_item.count != 1 | ||
|
||
self_link = api_v3_paths.custom_field_items(@custom_field.id, params[:parent], params[:depth]) | ||
start = start_item(root_item.first, params[:parent]) | ||
models = item_list(start, params[:depth]) | ||
HierarchyItemCollectionRepresenter.new(models, self_link:, current_user:) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.