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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
stub for group sql representer
ulferts0afacc9f75b3
diff --git a/lib/api/v3/groups/group_sql_collection_representer.rb b/lib/api/v3/groups/group_sql_collection_representer.rbnew file mode 100644index 00000000000..76b310c4a9e--- /dev/null+++ b/lib/api/v3/groups/group_sql_collection_representer.rb@@ -0,0 +1,37 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-2022 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 Groups+ class GroupSqlCollectionRepresenter < API::Decorators::SqlCollectionRepresenter+ self.embed_map = {+ elements: GroupSqlRepresenter+ }.with_indifferent_access+ end+ end+ end+enddiff --git a/lib/api/v3/groups/group_sql_representer.rb b/lib/api/v3/groups/group_sql_representer.rbnew file mode 100644index 00000000000..372a5da4729--- /dev/null+++ b/lib/api/v3/groups/group_sql_representer.rb@@ -0,0 +1,48 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-2022 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 Groups+ class GroupSqlRepresenter+ include API::Decorators::Sql::Hal++ link :self,+ path: { api: :group, params: %w(id) },+ column: -> { :id },+ title: -> { 'lastname' }++ property :_type,+ representation: ->(*) { "'Group'" }++ property :id++ property :name,+ column: :lastname+ end+ end+ end+enddiff --git a/lib/api/v3/groups/groups_api.rb b/lib/api/v3/groups/groups_api.rbindex f6cfe8da168..35341f1dfeb 100644--- a/lib/api/v3/groups/groups_api.rb+++ b/lib/api/v3/groups/groups_api.rb@@ -35,7 +35,7 @@ module APIauthorize_any %i[view_members manage_members], global: trueend- get &::API::V3::Utilities::Endpoints::Index+ get &::API::V3::Utilities::Endpoints::SqlFallbackedIndex.new(model: Group).mountpost &::API::V3::Utilities::Endpoints::Creatediff --git a/spec/lib/api/v3/groups/group_sql_representer_rendering_spec.rb b/spec/lib/api/v3/groups/group_sql_representer_rendering_spec.rbnew file mode 100644index 00000000000..81ec34116d7--- /dev/null+++ b/spec/lib/api/v3/groups/group_sql_representer_rendering_spec.rb@@ -0,0 +1,74 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-2022 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.++require 'spec_helper'++describe ::API::V3::Groups::GroupSqlRepresenter, 'rendering' do+ include ::API::V3::Utilities::PathHelper++ subject(:json) do+ ::API::V3::Utilities::SqlRepresenterWalker+ .new(scope,+ current_user: current_user,+ url_query: { select: select })+ .walk(described_class)+ .to_json+ end++ let(:scope) do+ Group+ .where(id: group.id)+ end++ let(:group) { create(:group) }++ let(:select) { { '*' => {} } }++ current_user do+ create(:user)+ end++ context 'when rendering all supported properties' do+ let(:expected) do+ {+ _type: "Group",+ id: group.id,+ name: group.name,+ _links: {+ self: {+ href: api_v3_paths.group(group.id),+ title: group.name+ }+ }+ }+ end++ it 'renders as expected' do+ expect(json)+ .to be_json_eql(expected.to_json)+ end+ end+enddiff --git a/spec/requests/api/v3/groups/group_resource_spec.rb b/spec/requests/api/v3/groups/group_resource_spec.rbindex 05dffe17b78..d5dde82a0b9 100644--- a/spec/requests/api/v3/groups/group_resource_spec.rb+++ b/spec/requests/api/v3/groups/group_resource_spec.rb@@ -406,32 +406,53 @@ describe 'API v3 Group resource', type: :request, content_type: :json doget get_pathend- context 'having the necessary permission' do- it 'responds with 200 OK' do- expect(subject.status)- .to eq(200)- end-- it 'responds with a collection of groups' do- expect(subject.body)- .to be_json_eql('Collection'.to_json)- .at_path('_type')+ it_behaves_like 'API V3 collection response', 2, 2, 'Group' do+ let(:elements) { [other_group, group] }+ end- expect(subject.body)- .to be_json_eql('2')- .at_path('total')+ context 'when signaling' do+ let(:get_path) { api_v3_paths.path_for :groups, select: 'total,count,elements/*' }- expect(subject.body)- .to be_json_eql(other_group.id.to_json)- .at_path('_embedded/elements/0/id')+ let(:expected) do+ {+ total: 2,+ count: 2,+ _embedded: {+ elements: [+ {+ _type: 'Group',+ id: other_group.id,+ name: other_group.name,+ _links: {+ self: {+ href: api_v3_paths.group(other_group.id),+ title: other_group.name+ }+ }+ },+ {+ _type: 'Group',+ id: group.id,+ name: group.name,+ _links: {+ self: {+ href: api_v3_paths.group(group.id),+ title: group.name+ }+ }+ }+ ]+ }+ }+ end- expect(subject.body)- .to be_json_eql(group.id.to_json)- .at_path('_embedded/elements/1/id')+ it 'is the reduced set of properties of the embedded elements' do+ expect(last_response.body)+ .to be_json_eql(expected.to_json)endend- context 'not having the necessary permission' do+ context 'when not having the necessary permission' dolet(:permissions) { [] }it_behaves_like 'unauthorized access'