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

first assignee spec

Tobias Dillmanna4a7ee168290
diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb
index 382116ed6a1..d5eada94fe7 100644
--- a/spec/features/work_packages/edit_work_package_spec.rb
+++ b/spec/features/work_packages/edit_work_package_spec.rb
@@ -70,6 +70,7 @@ RSpec.describe "edit work package", :js do
let(:category) { create(:category, project:) }
let(:visit_before) { true }
+ let(:logged_in_user) { manager }
def visit!
wp_page.visit!
@@ -77,7 +78,7 @@ RSpec.describe "edit work package", :js do
end
before do
- login_as(manager)
+ login_as(logged_in_user)
manager
dev
@@ -262,4 +263,63 @@ RSpec.describe "edit work package", :js do
wp_page.expect_no_toaster(type: :success, message: "Successful update", wait: 1)
end
end
+
+ context "when using the user auto completer" do
+ let(:dev_role) do
+ create(:project_role,
+ permissions: %i[view_work_packages
+ edit_work_packages
+ work_package_assigned])
+ end
+
+ let(:logged_in_user) { dev }
+
+ context "when assigning" do
+ it "does not show you the email of other users" do
+ # Click on assignee
+ wp_page.open_user_auto_completer
+ options = wp_page.visible_user_auto_completer_options
+
+ expected_options = [
+ # The current user lacks permission to see other users email address
+ { name: manager.name,
+ email: nil },
+ # The current user can always see their own email
+ { name: dev.name,
+ email: dev.mail }
+ ]
+
+ expect(options).to eq(expected_options)
+ end
+ end
+
+ context "with permission to see emails" do
+ let(:dev_role) do
+ create(:project_role,
+ permissions: %i[view_work_packages
+ edit_work_packages
+ view_user_email
+ work_package_assigned])
+ end
+
+ context "when assigning" do
+ it "does show you the email of other users" do
+ # Click on assignee
+ wp_page.open_user_auto_completer
+ options = wp_page.visible_user_auto_completer_options
+
+ expected_options = [
+ # With the right permissions, you can see other users email address
+ { name: manager.name,
+ email: manager.mail },
+ # The current user can always see their own email
+ { name: dev.name,
+ email: dev.mail }
+ ]
+
+ expect(options).to eq(expected_options)
+ end
+ end
+ end
+ end
end
diff --git a/spec/support/pages/work_packages/abstract_work_package.rb b/spec/support/pages/work_packages/abstract_work_package.rb
index c79bdef2d03..ca017ac3646 100644
--- a/spec/support/pages/work_packages/abstract_work_package.rb
+++ b/spec/support/pages/work_packages/abstract_work_package.rb
@@ -330,6 +330,32 @@ module Pages
find('[data-test-selector="mark-notification-read-button"]').click
end
+ def open_user_auto_completer(field = "assignee")
+ find("op-editable-attribute-field[ng-reflect-field-name='#{field}'] [role='button']", wait: 10).click
+ end
+
+ # Finds the currently visible, expanded user auto completer and returns its dropdown menu options.
+ # A user always has a name, but their email is only visible in certain circumstances, so that value
+ # might be nil.
+ #
+ # The options are returned as an Array of Hashes, like this example with two users:
+ #
+ # [
+ # { name: "Bob", email: nil },
+ # { name: "Alice", email: "[email protected]" }
+ # ]
+ #
+ # The order of elements in the Array is equal to the visible order on the website.
+ def visible_user_auto_completer_options
+ find(".ng-dropdown-panel [role='listbox']").all(".ng-option[role='option']").map do |opt|
+ name = opt.find(".op-user-autocompleter--name").text
+ email_element = opt.all(".op-autocompleter__option-principal-email").first
+ email = email_element&.text
+
+ { name:, email: }
+ end
+ end
+
private
def create_page(_args)