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

Start with copying over membership specs

Klaus Zandersce273b52def7
diff --git a/lib/api/v3/shares/shares_api.rb b/lib/api/v3/shares/shares_api.rb
index 58cf1b7490e..cceafa57821 100644
--- a/lib/api/v3/shares/shares_api.rb
+++ b/lib/api/v3/shares/shares_api.rb
@@ -33,8 +33,6 @@ module API
helpers ::API::Utilities::UrlPropsParsingHelper
resources :shares do
- # TODO: filtering by entity_id and type?
-
get &::API::V3::Utilities::Endpoints::Index
.new(model: Member,
scope: -> { Member.visible(User.current).where.not(entity: nil).includes(ShareRepresenter.to_eager_load) },
diff --git a/spec/lib/api/v3/shares/share_collection_representer_spec.rb b/spec/lib/api/v3/shares/share_collection_representer_spec.rb
new file mode 100644
index 00000000000..76f425eef7b
--- /dev/null
+++ b/spec/lib/api/v3/shares/share_collection_representer_spec.rb
@@ -0,0 +1,61 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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'
+
+RSpec.describe API::V3::Shares::ShareCollectionRepresenter do
+ let(:self_base_link) { '/api/v3/shares' }
+ let(:members) do
+ build_stubbed_list(:work_package_member, 3).tap do |members|
+ allow(members).to receive(:limit).with(page_size).and_return(members)
+ allow(members).to receive(:offset).with(page - 1).and_return(members)
+ allow(members).to receive(:count).and_return(3)
+ end
+ end
+ let(:current_user) { build_stubbed(:user) }
+ let(:representer) do
+ described_class.new(members,
+ self_link: self_base_link,
+ per_page: page_size,
+ page:,
+ current_user:)
+ end
+ let(:total) { 3 }
+ let(:page) { 1 }
+ let(:page_size) { 2 }
+ let(:actual_count) { 3 }
+ let(:collection_inner_type) { 'Share' }
+
+ include API::V3::Utilities::PathHelper
+
+ context 'generation' do
+ subject(:collection) { representer.to_json }
+
+ it_behaves_like 'offset-paginated APIv3 collection', 3, 'shares', 'Share'
+ end
+end
diff --git a/spec/lib/api/v3/shares/share_representer_rendering_spec.rb b/spec/lib/api/v3/shares/share_representer_rendering_spec.rb
new file mode 100644
index 00000000000..cf0b5d7ca4c
--- /dev/null
+++ b/spec/lib/api/v3/shares/share_representer_rendering_spec.rb
@@ -0,0 +1,234 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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'
+
+RSpec.describe API::V3::Shares::ShareRepresenter, 'rendering' do
+ include API::V3::Utilities::PathHelper
+
+ shared_let(:project) { create(:project_with_types) }
+ shared_let(:work_package) { create(:work_package, project:) }
+
+ let(:member) do
+ build_stubbed(:work_package_member,
+ member_roles: [member_role1, member_role2, member_role2, marked_member_role],
+ principal:,
+ project:,
+ entity: work_package)
+ end
+ let(:roles) { [role1, role2] }
+ let(:role1) { build_stubbed(:view_work_package_role) }
+ let(:member_role1) { build_stubbed(:member_role, role: role1) }
+ let(:role2) { build_stubbed(:comment_work_package_role) }
+ let(:member_role2) { build_stubbed(:member_role, role: role2) }
+ let(:marked_role) { build_stubbed(:work_package_role) }
+ let(:marked_member_role) do
+ build_stubbed(:member_role, role: marked_role).tap do |mr|
+ allow(mr)
+ .to receive(:marked_for_destruction?)
+ .and_return(true)
+ end
+ end
+ let(:principal) { user }
+ let(:user) { build_stubbed(:user) }
+ let(:group) { build_stubbed(:group) }
+ let(:current_user) { build_stubbed(:user) }
+ let(:permissions) do
+ [:manage_members]
+ end
+ let(:representer) do
+ described_class.create(member, current_user:, embed_links: true)
+ end
+
+ subject { representer.to_json }
+
+ before do
+ mock_permissions_for(current_user) do |mock|
+ mock.allow_in_project *permissions, project: project || build_stubbed(:project)
+ end
+ end
+
+ describe '_links' do
+ describe 'self' do
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'self' }
+ let(:href) { api_v3_paths.share member.id }
+ let(:title) { user.name }
+ end
+ end
+
+ describe 'project' do
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'project' }
+ let(:href) { api_v3_paths.project(project.id) }
+ let(:title) { project.name }
+ end
+ end
+
+ describe 'principal' do
+ context 'for a user principal' do
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'principal' }
+ let(:href) { api_v3_paths.user(user.id) }
+ let(:title) { user.name }
+ end
+ end
+
+ context 'for a group principal' do
+ let(:principal) { group }
+
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'principal' }
+ let(:href) { api_v3_paths.group(group.id) }
+ let(:title) { group.name }
+ end
+ end
+ end
+
+ describe 'roles' do
+ it_behaves_like 'has a link collection' do
+ let(:link) { 'roles' }
+ # excludes member_roles marked for destruction
+ # and duplicates
+ let(:hrefs) do
+ [
+ {
+ href: api_v3_paths.role(role1.id),
+ title: role1.name
+ },
+ {
+ href: api_v3_paths.role(role2.id),
+ title: role2.name
+ }
+ ]
+ end
+ end
+ end
+ end
+
+ describe 'properties' do
+ it_behaves_like 'property', :_type do
+ let(:value) { 'Share' }
+ end
+
+ it_behaves_like 'property', :id do
+ let(:value) { member.id }
+ end
+
+ describe 'createdAt' do
+ it_behaves_like 'has UTC ISO 8601 date and time' do
+ let(:date) { member.created_at }
+ let(:json_path) { 'createdAt' }
+ end
+ end
+
+ describe 'updatedAt' do
+ it_behaves_like 'has UTC ISO 8601 date and time' do
+ let(:date) { member.updated_at }
+ let(:json_path) { 'updatedAt' }
+ end
+ end
+ end
+
+ describe '_embedded' do
+ describe 'project' do
+ let(:embedded_path) { '_embedded/project' }
+
+ it 'has the project embedded' do
+ expect(subject)
+ .to be_json_eql('Project'.to_json)
+ .at_path("#{embedded_path}/_type")
+
+ expect(subject)
+ .to be_json_eql(project.name.to_json)
+ .at_path("#{embedded_path}/name")
+ end
+
+ context 'for a global member' do
+ let(:project) { nil }
+
+ it 'has no project embedded' do
+ expect(subject)
+ .not_to have_json_path(embedded_path)
+ end
+ end
+ end
+
+ describe 'principal' do
+ let(:embedded_path) { '_embedded/principal' }
+
+ context 'for a user principal' do
+ it 'has the user embedded' do
+ expect(subject)
+ .to be_json_eql('User'.to_json)
+ .at_path("#{embedded_path}/_type")
+
+ expect(subject)
+ .to be_json_eql(user.name.to_json)
+ .at_path("#{embedded_path}/name")
+ end
+ end
+
+ context 'for a group principal' do
+ let(:principal) { group }
+
+ it 'has the group embedded' do
+ expect(subject)
+ .to be_json_eql('Group'.to_json)
+ .at_path("#{embedded_path}/_type")
+
+ expect(subject)
+ .to be_json_eql(group.name.to_json)
+ .at_path("#{embedded_path}/name")
+ end
+ end
+ end
+
+ describe 'roles' do
+ let(:embedded_path) { '_embedded/roles' }
+
+ it 'has an array of roles embedded that excludes member_roles marked for destruction' do
+ expect(subject)
+ .to be_json_eql('Role'.to_json)
+ .at_path("#{embedded_path}/0/_type")
+
+ expect(subject)
+ .to be_json_eql(role1.name.to_json)
+ .at_path("#{embedded_path}/0/name")
+
+ expect(subject)
+ .to be_json_eql('Role'.to_json)
+ .at_path("#{embedded_path}/1/_type")
+
+ expect(subject)
+ .to be_json_eql(role2.name.to_json)
+ .at_path("#{embedded_path}/1/name")
+ end
+ end
+ end
+end