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

Test access granted by sharing in feature spec

Aaron Contrerasa8204feab746
diff --git a/app/components/projects/index_page_header_component.html.erb b/app/components/projects/index_page_header_component.html.erb
index e9a98772215..b6c1db69689 100644
--- a/app/components/projects/index_page_header_component.html.erb
+++ b/app/components/projects/index_page_header_component.html.erb
@@ -28,7 +28,7 @@
icon: "share-android",
mobile_icon: "share-android",
label: t(:label_share),
- data: { controller: "async-dialog" }
+ data: { controller: "async-dialog", test_selector: "toggle-share-dialog-button" }
)
end
diff --git a/spec/features/projects/persisted_lists_sharing_spec.rb b/spec/features/projects/persisted_lists_sharing_spec.rb
new file mode 100644
index 00000000000..7004aae2a1a
--- /dev/null
+++ b/spec/features/projects/persisted_lists_sharing_spec.rb
@@ -0,0 +1,113 @@
+#-- 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 "Project list sharing",
+ :js,
+ :with_cuprite,
+ with_flag: { project_list_sharing_active?: true } do
+ shared_let(:view_project_query_role) { create(:view_project_query_role) }
+ shared_let(:edit_project_query_role) { create(:edit_project_query_role) }
+
+ shared_let(:sharer) do
+ create(:user,
+ firstname: "Han",
+ lastname: "Solo",
+ member_with_permissions: { project_where_both_are_members => %i[view_work_packages edit_work_packages] })
+ end
+ shared_let(:shared_user) do
+ create(:user,
+ firstname: "Jabba",
+ lastname: "The Hutt",
+ member_with_permissions: { project_where_both_are_members => %i[view_work_packages edit_work_packages] })
+ end
+
+ shared_let(:project_role) { create(:project_role, permissions: %i[view_work_packages edit_work_packages]) }
+ shared_let(:project_where_both_are_members) do
+ create(:project,
+ name: "Shared project",
+ identifier: "shared-project") do |project|
+ create(:member, project:, user: sharer, roles: [project_role])
+ create(:member, project:, user: shared_user, roles: [project_role])
+ end
+ end
+
+ shared_let(:shared_projects_list) do
+ create(:project_query,
+ name: "Member-of list",
+ user: sharer,
+ select: %w[name]) do |query|
+ query.where("member_of", "=", OpenProject::Database::DB_VALUE_TRUE)
+ query.save!
+ end
+ end
+
+ let(:projects_index_page) { Pages::Projects::Index.new }
+ let(:share_dialog) { Components::Sharing::ProjectQueries::ShareModal.new(shared_projects_list) }
+
+ describe "Sharing a project list with View permissions with a user " \
+ "and accessing the list as the shared user" do
+ it "allows the shared user to view the project list but not edit it" do
+ using_session "shared user" do
+ login_as(shared_user)
+
+ projects_index_page.visit!
+ projects_index_page.expect_no_sidebar_filter("Member-of list")
+ end
+
+ using_session "sharer" do
+ login_as(sharer)
+
+ projects_index_page.visit!
+ projects_index_page.set_sidebar_filter "Member-of list"
+ projects_index_page.open_share_dialog
+
+ share_dialog.expect_open
+ share_dialog.invite_user!(shared_user, "View")
+ end
+
+ using_session "shared user" do
+ login_as(shared_user)
+ projects_index_page.visit!
+ projects_index_page.expect_sidebar_filter("Member-of list")
+ projects_index_page.set_sidebar_filter("Member-of list")
+ projects_index_page.open_share_dialog
+
+ share_dialog.expect_sharing_forbidden_banner
+ share_dialog.close
+
+ projects_index_page.open_filters
+ projects_index_page.filter_by_active("yes")
+ projects_index_page.expect_can_only_save_as_label
+ projects_index_page.save_query_as("Member-of and active list")
+
+ projects_index_page.expect_sidebar_filter("Member-of and active list", selected: true)
+ end
+ end
+ end
+end
diff --git a/spec/features/work_packages/share/access_spec.rb b/spec/features/work_packages/share/access_spec.rb
index d4f00be01dc..a219cc762c7 100644
--- a/spec/features/work_packages/share/access_spec.rb
+++ b/spec/features/work_packages/share/access_spec.rb
@@ -47,7 +47,7 @@ RSpec.describe "Shared Work Package Access",
let(:global_work_packages_page) { Pages::WorkPackagesTable.new }
let(:work_packages_page) { Pages::WorkPackagesTable.new(project) }
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
let(:add_comment_button_selector) { ".work-packages--activity--add-comment" }
let(:attach_files_button_selector) { "op-attachments--upload-button" }
diff --git a/spec/features/work_packages/share/bulk_sharing_spec.rb b/spec/features/work_packages/share/bulk_sharing_spec.rb
index d57b066274d..9293597a790 100644
--- a/spec/features/work_packages/share/bulk_sharing_spec.rb
+++ b/spec/features/work_packages/share/bulk_sharing_spec.rb
@@ -67,8 +67,8 @@ RSpec.describe "Work Packages", "Bulk Sharing",
end
end
- let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
context "when having share permission" do
current_user { sharer }
diff --git a/spec/features/work_packages/share/enterprise_restriction_spec.rb b/spec/features/work_packages/share/enterprise_restriction_spec.rb
index 8bede4e0c1b..fe6109fa617 100644
--- a/spec/features/work_packages/share/enterprise_restriction_spec.rb
+++ b/spec/features/work_packages/share/enterprise_restriction_spec.rb
@@ -46,8 +46,8 @@ RSpec.describe "Work Package Sharing Enterprise Restriction", :js, :with_cuprite
shared_let(:project) { create(:project, members: { sharer => [sharer_role] }) }
shared_let(:work_package) { create(:work_package, project:) }
- let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
current_user { sharer }
diff --git a/spec/features/work_packages/share/filter_spec.rb b/spec/features/work_packages/share/filter_spec.rb
index cd69ca2bb89..7df02f0c049 100644
--- a/spec/features/work_packages/share/filter_spec.rb
+++ b/spec/features/work_packages/share/filter_spec.rb
@@ -71,7 +71,7 @@ RSpec.describe "Work package sharing",
end
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
current_user { create(:admin, firstname: "Signed in", lastname: "User") }
diff --git a/spec/features/work_packages/share/multi_invite_spec.rb b/spec/features/work_packages/share/multi_invite_spec.rb
index e45317dfe51..4c77b06ca5e 100644
--- a/spec/features/work_packages/share/multi_invite_spec.rb
+++ b/spec/features/work_packages/share/multi_invite_spec.rb
@@ -62,7 +62,7 @@ RSpec.describe "Work package sharing",
end
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
current_user { create(:user, firstname: "Signed in", lastname: "User") }
diff --git a/spec/features/work_packages/share/share_account_activation_spec.rb b/spec/features/work_packages/share/share_account_activation_spec.rb
index 1c857ee9551..cb010406215 100644
--- a/spec/features/work_packages/share/share_account_activation_spec.rb
+++ b/spec/features/work_packages/share/share_account_activation_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe "Work package sharing invited users",
create(:work_package, project:)
end
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
it "allows to invite and activate the account" do
login_with(editor.login, "adminADMIN!")
diff --git a/spec/features/work_packages/share/share_spec.rb b/spec/features/work_packages/share/share_spec.rb
index 1fa38bb2d47..a74519f786b 100644
--- a/spec/features/work_packages/share/share_spec.rb
+++ b/spec/features/work_packages/share/share_spec.rb
@@ -75,7 +75,7 @@ RSpec.describe "Work package sharing",
end
end
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
- let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
+ let(:share_modal) { Components::Sharing::WorkPackages::ShareModal.new(work_package) }
let(:members_page) { Pages::Members.new project.identifier }
let(:wp_table) { Pages::WorkPackagesTable.new(project) }
let(:columns) { Components::WorkPackages::Columns.new }
diff --git a/spec/support/components/sharing/project_queries/share_modal.rb b/spec/support/components/sharing/project_queries/share_modal.rb
new file mode 100644
index 00000000000..9aaac143bf7
--- /dev/null
+++ b/spec/support/components/sharing/project_queries/share_modal.rb
@@ -0,0 +1,52 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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_relative "../../sharing/share_modal"
+
+module Components
+ module Sharing
+ module ProjectQueries
+ class ShareModal < Components::Sharing::ShareModal
+ # rubocop:disable Lint/MissingSuper
+ def initialize(project_query)
+ @entity = project_query
+ @title = I18n.t(:label_share_project_list)
+ end
+ # rubocop:enable Lint/MissingSuper
+
+ def expect_sharing_forbidden_banner
+ expect(page).to have_text("You don't have permissions to share Custom query.")
+ end
+
+ def close
+ click_on(class: "Overlay-closeButton")
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/sharing/share_modal.rb
similarity index 98%
rename from spec/support/components/work_packages/share_modal.rb
rename to spec/support/components/sharing/share_modal.rb
index 6f7956df8e5..0b8bedefcea 100644
--- a/spec/support/components/work_packages/share_modal.rb
+++ b/spec/support/components/sharing/share_modal.rb
@@ -30,17 +30,16 @@ require "support/components/common/modal"
require "support/components/autocompleter/ng_select_autocomplete_helpers"
module Components
- module WorkPackages
+ module Sharing
class ShareModal < Components::Common::Modal
include Components::Autocompleter::NgSelectAutocompleteHelpers
- attr_reader :work_package, :title
+ attr_reader :entity, :title
- def initialize(work_package)
+ def initialize(_entity)
super()
- @work_package = work_package
- @title = I18n.t("js.work_packages.sharing.title")
+ raise "Implement me and set @entity and @title"
end
def expect_open
diff --git a/spec/support/components/sharing/work_packages/share_modal.rb b/spec/support/components/sharing/work_packages/share_modal.rb
new file mode 100644
index 00000000000..d52d11d7349
--- /dev/null
+++ b/spec/support/components/sharing/work_packages/share_modal.rb
@@ -0,0 +1,42 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-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.
+# ++
+
+module Components
+ module Sharing
+ module WorkPackages
+ class ShareModal < Components::Sharing::ShareModal
+ # rubocop:disable Lint/MissingSuper
+ def initialize(work_package)
+ @entity = work_package
+ @title = I18n.t("js.work_packages.sharing.title")
+ end
+ # rubocop:enable Lint/MissingSuper
+ end
+ end
+ end
+end
diff --git a/spec/support/pages/page.rb b/spec/support/pages/page.rb
index 150ecd08785..9adae4ce497 100644
--- a/spec/support/pages/page.rb
+++ b/spec/support/pages/page.rb
@@ -32,6 +32,7 @@ module Pages
class Page
include Capybara::DSL
include Capybara::RSpecMatchers
+ include TestSelectorFinders
include RSpec::Matchers
include OpenProject::StaticRouting::UrlHelpers
include Toasts::Expectations
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index 181b69e5243..1abfde32d4b 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -352,6 +352,10 @@ module Pages
click_on "Save"
end
+ def expect_can_only_save_as_label
+ expect(page).to have_text(I18n.t("lists.can_be_saved_as"))
+ end
+
def fill_in_the_name(name)
within '[data-test-selector="project-query-name"]' do
fill_in "Name", with: name
@@ -448,6 +452,10 @@ module Pages
end
end
+ def open_share_dialog
+ find_test_selector("toggle-share-dialog-button").click
+ end
+
private
def boolean_filter?(filter)