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
Add permission check for inline creation of users and basic test cases
Henriette Darge29a2c9298619
diff --git a/app/forms/work_packages/share/invitee.rb b/app/forms/work_packages/share/invitee.rbindex 50f9a9eb627..8c93ae6995c 100644--- a/app/forms/work_packages/share/invitee.rb+++ b/app/forms/work_packages/share/invitee.rb@@ -42,7 +42,7 @@ module WorkPackages::Sharefilters: [{ name: 'type', operator: '=', values: %w[User Group] },{ name: 'id', operator: '!', values: [::Queries::Filters::MeValue::KEY] }],searchKey: 'any_name_attribute',- addTag: true,+ addTag: User.current.allowed_to_globally?(:create_user),addTagText: I18n.t('members.send_invite_to'),focusDirectly: true,appendTo: 'body',diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 6e038521e9b..05e2f22955c 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -303,6 +303,7 @@ en:no_results_title_text: There are currently no members part of this project.no_results_content_text: Add a member to the projectinvite_by_mail: "Send invite to %{mail}"+ send_invite_to: "Send invite to"my:access_token:diff --git a/spec/features/work_packages/share_spec.rb b/spec/features/work_packages/share_spec.rbindex 6b7de23d113..b22d16d1958 100644--- a/spec/features/work_packages/share_spec.rb+++ b/spec/features/work_packages/share_spec.rb@@ -282,4 +282,46 @@ RSpec.describe 'Work package sharing',share_modal.expect_no_invite_optionendend++ context 'when having global invite permission' do+ shared_let(:global_manage_user) { create(:user, global_permissions: %i[manage_user create_user]) }+ let(:current_user) { global_manage_user }++ it 'allows inviting and directly sharing with a user who is not part of the instance yet' do+ work_package_page.visit!+ click_button 'Share'++ share_modal.expect_open+ share_modal.expect_shared_count_of(6)++ share_modal.create_and_invite_user('[email protected]', 'View')++ share_modal.expect_shared_count_of(7)++ new_user = User.last+ share_modal.expect_shared_with(new_user, 'View', position: 1)++ # perform_enqueued_jobs+ # Only one combined email for create and share should be send out+ # expect(ActionMailer::Base.deliveries.size).to eq(1)+ end+ end++ context 'when lacking global invite permission' do+ shared_let(:global_manage_user) { create(:user, global_permissions: %i[]) }+ let(:current_user) { global_manage_user }++ it 'does not allow creating a user who is not part of the instance yet' do+ work_package_page.visit!+ click_button 'Share'++ share_modal.expect_open+ share_modal.expect_shared_count_of(6)++ share_modal.search_user('[email protected]')++ share_modal.expect_no_ng_option("", "Send invite to\"[email protected]\"", results_selector: "body")+ share_modal.expect_ng_option("", "No items found", results_selector: "body")+ end+ endenddiff --git a/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb b/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rbindex 14ebfb7460d..54c04323275 100644--- a/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb+++ b/spec/support/components/autocompleter/ng_select_autocomplete_helpers.rb@@ -40,14 +40,14 @@ module Components::Autocompleterendend- def expect_ng_option(element, option)- within(ng_find_dropdown(element)) do+ def expect_ng_option(element, option, results_selector: nil)+ within(ng_find_dropdown(element, results_selector:)) doexpect(page).to have_selector('.ng-option', text: option)endend- def expect_no_ng_option(element, option)- within(ng_find_dropdown(element)) do+ def expect_no_ng_option(element, option, results_selector: nil)+ within(ng_find_dropdown(element, results_selector:)) doexpect(page).not_to have_selector('.ng-option', text: option)endenddiff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rbindex 216dba6d78e..55e06a76d46 100644--- a/spec/support/components/work_packages/share_modal.rb+++ b/spec/support/components/work_packages/share_modal.rb@@ -52,19 +52,34 @@ module Componentsselect_text: user.name,results_selector: 'body'- within modal_element.find('[data-test-selector="op-share-wp-invite-role"]') do- # Open the ActionMenu- click_button 'View'+ select_invite_role(role_name)- find('.ActionListContent', text: role_name).click+ within modal_element do+ click_button 'Invite'end+ end++ alias_method :invite_group, :invite_user++ def create_and_invite_user(email, role_name)+ # Adding a user to the list of shared users+ select_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),+ query: email,+ select_text: "Send invite to\"#{email}\"",+ results_selector: 'body'++ select_invite_role(role_name)within modal_element doclick_button 'Invite'endend- alias_method :invite_group, :invite_user+ def search_user(search_string)+ search_autocomplete page.find('[data-test-selector="op-share-wp-invite-autocomplete"]'),+ query: search_string,+ results_selector: 'body'+ enddef remove_user(user)within user_row(user) do@@ -72,6 +87,15 @@ module Componentsendend+ def select_invite_role(role_name)+ within modal_element.find('[data-test-selector="op-share-wp-invite-role"]') do+ # Open the ActionMenu+ click_button 'View'++ find('.ActionListContent', text: role_name).click+ end+ end+def change_role(user, role_name)within user_row(user) dofind('[data-test-selector="op-share-wp-update-role"]').click