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 Bulk Remove and Role Update behavior
Aaron Contrerasaff7aaebd3fe
diff --git a/app/components/work_packages/share/bulk_permission_button_component.html.erb b/app/components/work_packages/share/bulk_permission_button_component.html.erbnew file mode 100644index 00000000000..00ba386d711--- /dev/null+++ b/app/components/work_packages/share/bulk_permission_button_component.html.erb@@ -0,0 +1,27 @@+<%=+ render(Primer::Alpha::ActionMenu.new(select_variant: :single,+ dynamic_label: true,+ anchor_align: :end,+ color: :subtle,+ data: { test_selector: 'op-share-wp-bulk-update-role'})) do |menu|+ menu.with_show_button(data: { 'work-packages--share--bulk-selection-target': 'bulkUpdateRole' }) do |button|+ button.with_trailing_action_icon(icon: "triangle-down")+ 'Placeholder'+ end++ options.each do |option|+ menu.with_item(label: option[:label],+ href: update_path,+ method: :patch,+ active: false,+ form_arguments: {+ method: :patch,+ name: 'role_ids[]',+ value: option[:value],+ data: { 'work-packages--share--bulk-selection-target': 'bulkForm' }+ }) do |item|+ item.with_description.with_content(option[:description])+ end+ end+ end+%>diff --git a/app/components/work_packages/share/bulk_permission_button_component.rb b/app/components/work_packages/share/bulk_permission_button_component.rbnew file mode 100644index 00000000000..25382e33f07--- /dev/null+++ b/app/components/work_packages/share/bulk_permission_button_component.rb@@ -0,0 +1,59 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2023 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 WorkPackages+ module Share+ class BulkPermissionButtonComponent < ApplicationComponent+ def initialize(work_package:)+ super++ @work_package = work_package+ end++ def update_path+ work_package_shares_bulk_path(@work_package)+ end++ def options+ [+ { label: I18n.t('work_package.sharing.permissions.edit'),+ value: Role::BUILTIN_WORK_PACKAGE_EDITOR,+ description: I18n.t('work_package.sharing.permissions.edit_description') },+ { label: I18n.t('work_package.sharing.permissions.comment'),+ value: Role::BUILTIN_WORK_PACKAGE_COMMENTER,+ description: I18n.t('work_package.sharing.permissions.comment_description') },+ { label: I18n.t('work_package.sharing.permissions.view'),+ value: Role::BUILTIN_WORK_PACKAGE_VIEWER,+ description: I18n.t('work_package.sharing.permissions.view_description') }+ ]+ end+ end+ end+enddiff --git a/app/components/work_packages/share/counter_component.html.erb b/app/components/work_packages/share/counter_component.html.erbindex b2a11e6b01d..3b4013531a5 100644--- a/app/components/work_packages/share/counter_component.html.erb+++ b/app/components/work_packages/share/counter_component.html.erb@@ -1,7 +1,10 @@<%=component_wrapper(class: 'op-share-wp-modal-body--header--counter--container',data: { test_selector: 'op-share-wp-active-count'}) do- if sharing_manageable?+ # There's no point in rendering the BulkSelectionCounterComponent even if+ # I'm able to manage shares if the only user that the work package is+ # currently shared is myself, since I'm not able to manage my own share.+ if sharing_manageable? && shared_with_anyone_else_other_than_myself?render(WorkPackages::Share::BulkSelectionCounterComponent.new(count:))elserender(WorkPackages::Share::ShareCounterComponent.new(count:))diff --git a/app/components/work_packages/share/counter_component.rb b/app/components/work_packages/share/counter_component.rbindex 8fcb33b1d3a..ee2b0d786da 100644--- a/app/components/work_packages/share/counter_component.rb+++ b/app/components/work_packages/share/counter_component.rb@@ -46,6 +46,12 @@ module WorkPackagesprivateattr_reader :work_package, :count++ def shared_with_anyone_else_other_than_myself?+ Member.of_work_package(@work_package)+ .where.not(principal: User.current)+ .any?+ endendendenddiff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erbindex 01e95097557..a4b6f6cbbfb 100644--- a/app/components/work_packages/share/modal_body_component.html.erb+++ b/app/components/work_packages/share/modal_body_component.html.erb@@ -31,10 +31,22 @@render(WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: shared_principals.size))end- header_grid.with_area(:remove, tag: :div) do- form_with url: work_package_shares_bulk_path, method: :delete do- concat(content_tag(:div, {}, data: { 'work-packages--share--bulk-selection-target': 'hiddenShareIdsContainer' }))- concat(render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') })+ header_grid.with_area(:actions,+ tag: :div,+ hidden: true, # Prevent flicker on initial render+ data: { 'work-packages--share--bulk-selection-target': 'actions' }) do+ if sharing_manageable?+ concat(+ render(WorkPackages::Share::BulkPermissionButtonComponent.new(work_package: @work_package))+ )++ concat(+ form_with(url: work_package_shares_bulk_path,+ method: :delete,+ data: { 'work-packages--share--bulk-selection-target': 'bulkForm' }) do+ render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') }+ end+ )endendenddiff --git a/app/components/work_packages/share/modal_body_component.sass b/app/components/work_packages/share/modal_body_component.sassindex 3b0049d8431..11f74891dfd 100644--- a/app/components/work_packages/share/modal_body_component.sass+++ b/app/components/work_packages/share/modal_body_component.sass@@ -1,13 +1,22 @@.op-share-wp-modal-body&--user-rowdisplay: grid- grid-template-columns: 20px 1fr auto auto- grid-template-areas: "selection user button remove"- grid-gap: 10px+ grid-template-columns: 1fr+ grid-template-areas: "user"+ grid-column-gap: 10px++ &-manageable+ display: grid+ grid-template-columns: 20px 1fr auto auto+ grid-template-areas: "selection user button remove"+ grid-column-gap: 10px+&--headerdisplay: gridgrid-template-columns: 1fr auto- grid-template-areas: "counter remove"+ grid-template-areas: "counter actions"+ grid-column-gap: 10px&--counter&--containerdisplay: flex // Vertically align checkbox and counter+ align-items: centerdiff --git a/app/components/work_packages/share/permission_button_component.html.erb b/app/components/work_packages/share/permission_button_component.html.erbindex b3c898133fa..ee655861104 100644--- a/app/components/work_packages/share/permission_button_component.html.erb+++ b/app/components/work_packages/share/permission_button_component.html.erb@@ -1,25 +1,28 @@<%=- render(Primer::Alpha::ActionMenu.new(**{ select_variant: :single,- dynamic_label: true,- anchor_align: :end,- color: :subtle }- .deep_merge(@system_arguments))) do |menu|- menu.with_show_button do |button|- button.with_trailing_action_icon(icon: :"triangle-down")- permission_name(active_role.builtin)- end- options.each do |option|- menu.with_item(label: option[:label],- href: update_path,- method: :patch,- active: option_active?(option),- data: { value: option[:value] },- form_arguments: {+ component_wrapper do+ render(Primer::Alpha::ActionMenu.new(**{ select_variant: :single,+ dynamic_label: true,+ anchor_align: :end,+ color: :subtle }.deep_merge(@system_arguments))) do |menu|+ menu.with_show_button(data: { 'work-packages--share--bulk-selection-target': 'userRowRole',+ 'share-id': share.id,+ 'active-role-name': permission_name(active_role.builtin)}) do |button|+ button.with_trailing_action_icon(icon: :"triangle-down")+ permission_name(active_role.builtin)+ end+ options.each do |option|+ menu.with_item(label: option[:label],+ href: update_path,method: :patch,- name: 'role_ids[]',- value: option[:value]- }) do |item|- item.with_description.with_content(option[:description])+ active: option_active?(option),+ data: { value: option[:value] },+ form_arguments: {+ method: :patch,+ name: 'role_ids[]',+ value: option[:value]+ }) do |item|+ item.with_description.with_content(option[:description])+ endendendenddiff --git a/app/components/work_packages/share/permission_button_component.rb b/app/components/work_packages/share/permission_button_component.rbindex 5ebe929da43..c7da32b3d9b 100644--- a/app/components/work_packages/share/permission_button_component.rb+++ b/app/components/work_packages/share/permission_button_component.rb@@ -31,6 +31,7 @@ module WorkPackagesclass PermissionButtonComponent < ApplicationComponentinclude ApplicationHelperinclude OpPrimer::ComponentHelpers+ include OpTurbo::Streamabledef initialize(share:, **system_arguments)super@@ -51,6 +52,10 @@ module WorkPackagesoption[:value] == active_role.builtinend+ def wrapper_uniq_by+ share.id || @system_arguments.dig(:data, :'test-selector')+ end+privateattr_reader :sharediff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erbindex 97ac8ea9d03..2d5956ab896 100644--- a/app/components/work_packages/share/share_row_component.html.erb+++ b/app/components/work_packages/share/share_row_component.html.erb@@ -1,14 +1,14 @@<%=component_wrapper(:border_box_row, data: { 'test-selector': "op-share-wp-active-user-#{principal.id}" }) do- grid_layout('op-share-wp-modal-body--user-row', tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|+ grid_layout(grid_css_classes, tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|user_row_grid.with_area(:selection, tag: :div) doif share_editable?render(Primer::Alpha::CheckBox.new(name: "share_ids", value: share.id, label: "#{principal.name}",- visually_hide_label: true, scheme: :array,- data: {- 'work-packages--share--bulk-selection-target': 'shareCheckbox',- action: 'work-packages--share--bulk-selection#refresh'- }))+ visually_hide_label: true, scheme: :array,+ data: {+ 'work-packages--share--bulk-selection-target': 'shareCheckbox',+ action: 'work-packages--share--bulk-selection#refresh'+ }))endenddiff --git a/app/components/work_packages/share/share_row_component.rb b/app/components/work_packages/share/share_row_component.rbindex 3ef9de12159..35f2a503210 100644--- a/app/components/work_packages/share/share_row_component.rb+++ b/app/components/work_packages/share/share_row_component.rb@@ -70,6 +70,14 @@ module WorkPackages@share_editable ||= User.current != share.principal && sharing_manageable?end+ def grid_css_classes+ if sharing_manageable?+ 'op-share-wp-modal-body--user-row-manageable'+ else+ 'op-share-wp-modal-body--user-row'+ end+ end+def select_share_checkbox_options{name: "share_ids",diff --git a/app/controllers/work_packages/shares/bulk_controller.rb b/app/controllers/work_packages/shares/bulk_controller.rbindex f38e76e5ec0..d5607809981 100644--- a/app/controllers/work_packages/shares/bulk_controller.rb+++ b/app/controllers/work_packages/shares/bulk_controller.rb@@ -33,10 +33,21 @@ class WorkPackages::Shares::BulkController < ApplicationControllerbefore_action :find_work_packagebefore_action :find_shares+ before_action :find_role_ids, only: :updatebefore_action :find_projectbefore_action :authorize- def update; end+ def update+ @shares.each do |share|+ WorkPackageMembers::CreateOrUpdateService+ .new(user: current_user)+ .call(entity: @work_package,+ user_id: share.principal.id,+ role_ids: @role_ids).result+ end++ respond_with_update_permission_buttons+ enddef destroy@shares.each do |share|@@ -54,6 +65,17 @@ class WorkPackages::Shares::BulkController < ApplicationControllerprivate+ def respond_with_update_permission_buttons+ @shares.each do |share|+ replace_via_turbo_stream(+ component: WorkPackages::Share::PermissionButtonComponent.new(share:,+ data: { 'test-selector': 'op-share-wp-update-role' })+ )+ end++ respond_with_turbo_streams+ end+def respond_with_replace_modalreplace_via_turbo_stream(component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package)@@ -85,7 +107,15 @@ class WorkPackages::Shares::BulkController < ApplicationControllerenddef find_shares- @shares = Member.of_work_package(@work_package).where(id: params[:share_ids])+ @shares = Member.includes(:principal)+ .of_work_package(@work_package)+ .where(id: params[:share_ids])+ end++ def find_role_ids+ @role_ids = WorkPackageRole.unscoped+ .where(builtin: params[:role_ids])+ .pluck(:id)enddef current_visible_member_countdiff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rbindex bc406bcea44..074f88ee22b 100644--- a/app/controllers/work_packages/shares_controller.rb+++ b/app/controllers/work_packages/shares_controller.rb@@ -58,7 +58,7 @@ class WorkPackages::SharesController < ApplicationController.new(user: current_user, model: @share).call(role_ids: find_role_ids(params[:role_ids]))- head :no_content+ respond_with_update_permission_buttonenddef destroy@@ -100,6 +100,15 @@ class WorkPackages::SharesController < ApplicationControllerrespond_with_turbo_streamsend+ def respond_with_update_permission_button+ replace_via_turbo_stream(+ component: WorkPackages::Share::PermissionButtonComponent.new(share: @share,+ data: { 'test-selector': 'op-share-wp-update-role' })+ )++ respond_with_turbo_streams+ end+def respond_with_remove_shareremove_via_turbo_stream(component: WorkPackages::Share::ShareRowComponent.new(share: @share)diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 2c60874208b..2130b94c757 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -1099,6 +1099,8 @@ en:share: 'Share'title: "Share work package"selected_count: "%{count} selected"+ selection:+ mixed: "Mixed"table:configure_button: 'Configure work package table'summary: "Table with rows of work package and columns of work package attributes."diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/share/bulk-selection.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/share/bulk-selection.controller.tsindex a047d14c171..b982794638c 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/share/bulk-selection.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/share/bulk-selection.controller.ts@@ -31,32 +31,74 @@import { Controller } from '@hotwired/stimulus';export default class BulkSelectionController extends Controller {+ static values = {+ bulkUpdateRoleLabel: { type: String, default: I18n.t('js.work_packages.sharing.selection.mixed') },+ };++ declare bulkUpdateRoleLabelValue:string;+static targets = ['toggleAll',+ 'shareCheckbox','sharedCounter','selectedCounter',- 'shareCheckbox',- 'hiddenShareIdsContainer',+ 'actions',+ 'bulkForm',+ 'hiddenShare',+ 'userRowRole',+ 'bulkUpdateRole',];+ // Checkboxesdeclare readonly toggleAllTarget:HTMLInputElement;+ declare readonly shareCheckboxTargets:HTMLInputElement[];++ // Countersdeclare readonly sharedCounterTarget:HTMLElement;declare readonly selectedCounterTarget:HTMLElement;- declare readonly shareCheckboxTargets:HTMLInputElement[];- declare readonly hiddenShareIdsContainerTargets:HTMLElement[];- toggleAllTargetConnected() {- this.refresh();- }+ // Bulk Forms+ declare readonly bulkFormTargets:HTMLFormElement[];+ declare readonly hiddenShareTargets:HTMLInputElement[];+ declare readonly actionsTarget:HTMLElement;++ // Permission Buttons+ declare readonly userRowRoleTargets:HTMLButtonElement[];+ declare readonly bulkUpdateRoleTarget:HTMLButtonElement;+ // Refresh when a user is invitedshareCheckboxTargetConnected() {this.refresh();}+ // Refresh when a user is uninvitedshareCheckboxTargetDisconnected() {this.refresh();}+ /*+ This allows for the Rails controller to be oblivious of the order in which the+ turbo stream actions must be declared. If all shares are selected and subsequently+ one is individually removed, the "Toggle All" checkbox should remain selected. If+ we only listen on the shares being added or removed, the event could fire before+ the new counter connects, making it appear not toggled.+ */+ toggleAllTargetConnected() {+ this.refresh();+ }++ // Refresh Bulk Update Label when a Role is updated inline+ // as the updated share might have been selected and the label+ // may no longer be correct+ userRowRoleTargetConnected() {+ this.updateBulkUpdateRoleLabelValue();+ }++ bulkUpdateRoleLabelValueChanged(current:string, _old:string) {+ const label = this.bulkUpdateRoleTarget.querySelector('.Button-label') as HTMLElement;+ label.textContent = current;+ }+toggle(e:Event) {e.preventDefault();@@ -71,51 +113,97 @@ export default class BulkSelectionController extends Controller {this.updateCounter();}- triggerInputEvent(checkbox:HTMLInputElement) {- const event = new Event('input', { bubbles: false, cancelable: true });- checkbox.dispatchEvent(event);- }-refresh() {const checkedSharesCount = this.checked.length;const sharesCount = this.shareCheckboxTargets.length;-this.toggleAllTarget.checked = checkedSharesCount === sharesCount;++ if (this.checked.length === 0) {+ this.actionsTarget.setAttribute('hidden', 'true');+ } else {+ this.actionsTarget.removeAttribute('hidden');+ }++ this.updateBulkUpdateRoleLabelValue();this.updateCounter();}- updateCounter() {+ // Private Methods++ private triggerInputEvent(checkbox:HTMLInputElement) {+ const event = new Event('input', { bubbles: false, cancelable: true });+ checkbox.dispatchEvent(event);+ }++ private updateBulkUpdateRoleLabelValue() {+ if (new Set(this.selectedPermissions).size > 1) {+ this.bulkUpdateRoleLabelValue = I18n.t('js.work_packages.sharing.selection.mixed');+ } else {+ this.bulkUpdateRoleLabelValue = this.selectedPermissions[0];+ }+ }++ private updateCounter() {if (this.checked.length === 0) {- this.sharedCounterTarget.removeAttribute('hidden');- this.selectedCounterTarget.setAttribute('hidden', 'true');+ this.showSharedCounter();} else {- this.sharedCounterTarget.setAttribute('hidden', 'true');- this.selectedCounterTarget.removeAttribute('hidden');- this.selectedCounterTarget.textContent = I18n.t('js.work_packages.sharing.selected_count', { count: this.checked.length });+ this.showSelectedCounter();}- this.hiddenShareIdsContainerTargets.forEach((checkboxIdsContainer) => {- checkboxIdsContainer.innerHTML = '';- const hiddenShareIds = this.createHiddenShareIds();- hiddenShareIds.forEach((hiddenShare) => checkboxIdsContainer.appendChild(hiddenShare));+ this.repopulateHiddenShares();+ }++ private showSharedCounter() {+ this.sharedCounterTarget.removeAttribute('hidden');+ this.selectedCounterTarget.setAttribute('hidden', 'true');+ }++ private showSelectedCounter() {+ this.selectedCounterTarget.textContent = I18n.t('js.work_packages.sharing.selected_count', { count: this.checked.length });+ this.sharedCounterTarget.setAttribute('hidden', 'true');+ this.selectedCounterTarget.removeAttribute('hidden');+ }++ private repopulateHiddenShares() {+ this.hiddenShareTargets.forEach((hiddenInput) => hiddenInput.remove());++ this.bulkFormTargets.forEach((form) => {+ const hiddenShares = this.createHiddenShares();+ hiddenShares.forEach((hiddenShare) => form.appendChild(hiddenShare));});}- createHiddenShareIds() {+ private createHiddenShares() {return this.checked.map((checkbox) => {const hiddenInput = document.createElement('input');+hiddenInput.type = 'hidden';hiddenInput.name = 'share_ids[]';hiddenInput.value = checkbox.value;+ hiddenInput.setAttribute('data-work-packages--share--bulk-selection-target', 'hiddenShare');+return hiddenInput;});}- get checked() {- return this.shareCheckboxTargets.filter((checkbox) => checkbox.checked);+ private get selectedPermissions() {+ return this.selectedRoleButtons.map((button) => {+ const label = button.querySelector('.Button-label') as HTMLElement;++ return label.textContent;+ }) as string[];+ }++ private get selectedRoleButtons() {+ const checkedShareIds = this.checked.map((checkbox) => checkbox.value);++ return this.userRowRoleTargets.filter((button) => {+ const shareId = button.getAttribute('data-share-id') as string;+ return checkedShareIds.includes(shareId);+ });}- get unchecked() {- return this.shareCheckboxTargets.filter((checkbox) => !checkbox.checked);+ private get checked() {+ return this.shareCheckboxTargets.filter((checkbox) => checkbox.checked);}}diff --git a/spec/features/work_packages/share/bulk_sharing_spec.rb b/spec/features/work_packages/share/bulk_sharing_spec.rbindex 12cba0535c5..494977c4316 100644--- a/spec/features/work_packages/share/bulk_sharing_spec.rb+++ b/spec/features/work_packages/share/bulk_sharing_spec.rb@@ -43,8 +43,17 @@ RSpec.describe 'Work Packages', 'Bulk Sharing',share_work_packages])end- shared_let(:sharer) { create(:user, firstname: 'Sharer', lastname: 'User') }- shared_let(:project) { create(:project, members: { sharer => [sharer_role] }) }+ shared_let(:viewer_role) do+ create(:project_role, permissions: %i[view_work_packages+ view_shared_work_packages])+ end++ shared_let(:sharer) { create(:user, firstname: 'Sharer', lastname: 'User') }+ shared_let(:viewer) { create(:user, firstname: 'Viewer', lastname: 'User') }++ shared_let(:project) do+ create(:project, members: { sharer => [sharer_role], viewer => [viewer_role] })+ endshared_let(:dinesh) { create(:user, firstname: 'Dinesh', lastname: 'Chugtai') }shared_let(:gilfoyle) { create(:user, firstname: 'Bertram', lastname: 'Gilfoyle') }@@ -61,9 +70,9 @@ RSpec.describe 'Work Packages', 'Bulk Sharing',let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }- current_user { sharer }-context 'when having share permission' do+ current_user { sharer }+it 'allows administrating shares in bulk' dowork_package_page.visit!@@ -72,52 +81,72 @@ RSpec.describe 'Work Packages', 'Bulk Sharing',share_modal.expect_shared_count_of(3)aggregate_failures "Selection behavior" do+ # Bulk actions hidden until at least one selection+ share_modal.expect_bulk_actions_not_available+# Selecting one individuallyshare_modal.select_shares(richard)share_modal.expect_selected(richard)share_modal.expect_selected_count_of(1)share_modal.expect_select_all_untoggled+ # Available now+ share_modal.expect_bulk_actions_available+ share_modal.expect_bulk_update_label('View')# Toggling all selects allshare_modal.toggle_select_allshare_modal.expect_selected(richard, dinesh, gilfoyle)share_modal.expect_selected_count_of(3)share_modal.expect_select_all_toggled+ share_modal.expect_bulk_actions_available+ share_modal.expect_bulk_update_label('Mixed')# Deselecting one individuallyshare_modal.deselect_shares(richard)share_modal.expect_selected(dinesh, gilfoyle)share_modal.expect_selected_count_of(2)share_modal.expect_select_all_untoggled+ share_modal.expect_bulk_actions_available+ share_modal.expect_bulk_update_label('Mixed')# Re-selecting the missing shareshare_modal.select_shares(richard)share_modal.expect_selected(richard, dinesh, gilfoyle)share_modal.expect_selected_count_of(3)share_modal.expect_select_all_toggled+ share_modal.expect_bulk_actions_available+ share_modal.expect_bulk_update_label('Mixed')# De-selecting allshare_modal.toggle_select_allshare_modal.expect_deselected(richard, dinesh, gilfoyle)share_modal.expect_shared_count_of(3)share_modal.expect_select_all_untoggled+ # No longer available+ share_modal.expect_bulk_actions_not_available# Re-selecting allshare_modal.toggle_select_allshare_modal.expect_selected(richard, dinesh, gilfoyle)share_modal.expect_selected_count_of(3)share_modal.expect_select_all_toggled+ # Available again+ share_modal.expect_bulk_actions_available+ share_modal.expect_bulk_update_label('Mixed')# De-selecting all individuallyshare_modal.deselect_shares(richard, dinesh, gilfoyle)share_modal.expect_shared_count_of(3)share_modal.expect_select_all_untoggled+ # No longer available+ share_modal.expect_bulk_actions_not_availableend- aggregate_failures "Preserving selected states when performing individual updates" do+ aggregate_failures "Preserving selected states when performing individual deletions" doshare_modal.select_shares(richard, dinesh)share_modal.expect_selected_count_of(2)share_modal.expect_select_all_untoggled+ share_modal.expect_bulk_update_label('Mixed')share_modal.remove_user(gilfoyle)share_modal.expect_not_shared_with(gilfoyle)@@ -125,16 +154,47 @@ RSpec.describe 'Work Packages', 'Bulk Sharing',share_modal.expect_selected(richard, dinesh)share_modal.expect_selected_count_of(2)share_modal.expect_select_all_toggled+ share_modal.expect_bulk_update_label('Mixed')share_modal.invite_user(gilfoyle, 'Comment')share_modal.expect_shared_with(gilfoyle)share_modal.expect_selected(richard, dinesh)share_modal.expect_selected_count_of(2)share_modal.expect_select_all_untoggled+ share_modal.expect_bulk_update_label('Mixed')end+ aggregate_failures "Preserving selected states when performing individual updates" do+ share_modal.change_role(gilfoyle, 'View')+ share_modal.expect_shared_with(gilfoyle, 'View')++ share_modal.expect_selected(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_select_all_untoggled+ share_modal.expect_bulk_update_label('Mixed')++ share_modal.toggle_select_all+ share_modal.expect_selected_count_of(3)+ share_modal.expect_select_all_toggled+ share_modal.expect_bulk_update_label('Mixed')++ share_modal.change_role(gilfoyle, 'Edit')+ share_modal.expect_shared_with(gilfoyle, 'Edit')+ share_modal.expect_selected_count_of(3)+ share_modal.expect_select_all_toggled+ share_modal.expect_bulk_update_label('Mixed')+ end++ # Reset+ share_modal.toggle_select_all+ share_modal.expect_select_all_untoggled+aggregate_failures "Bulk deletion" do- # Richard and Dinesh already selected from above+ share_modal.select_shares(richard, dinesh)+ share_modal.expect_selected(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_select_all_untoggled+share_modal.bulk_removeshare_modal.expect_not_shared_with(richard, dinesh)@@ -142,12 +202,101 @@ RSpec.describe 'Work Packages', 'Bulk Sharing',share_modal.expect_shared_count_of(1)share_modal.select_shares(gilfoyle)+ share_modal.expect_selected(gilfoyle)share_modal.expect_selected_count_of(1)share_modal.expect_select_all_toggledshare_modal.bulk_removeshare_modal.expect_blankslateend++ # Re-populate+ share_modal.invite_user(richard, 'View')+ share_modal.expect_shared_with(richard)+ share_modal.invite_user(dinesh, 'Comment')+ share_modal.expect_shared_with(dinesh)++ aggregate_failures 'Bulk updating' do+ share_modal.select_shares(richard)+ share_modal.expect_selected(richard)+ share_modal.expect_selected_count_of(1)+ share_modal.expect_bulk_update_label('View')++ share_modal.bulk_update('Edit')++ share_modal.expect_shared_with(richard, 'Edit')+ share_modal.expect_shared_with(dinesh, 'Comment')+ share_modal.expect_selected(richard)+ share_modal.expect_selected_count_of(1)+ share_modal.expect_bulk_update_label('Edit')++ share_modal.select_shares(richard, dinesh)+ share_modal.expect_selected(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_bulk_update_label('Mixed')++ share_modal.bulk_update('View')++ share_modal.expect_shared_with(richard, 'View')+ share_modal.expect_shared_with(dinesh, 'View')+ share_modal.expect_selected(richard, dinesh)+ share_modal.expect_selected_count_of(2)+ share_modal.expect_bulk_update_label('View')++ share_modal.toggle_select_all+ share_modal.expect_deselected(richard, dinesh)+ share_modal.expect_shared_count_of(2)+ end++ aggregate_failures "Bulk selection disabled when current user is the only shared with user" do+ create(:work_package_member,+ principal: current_user,+ entity: work_package,+ roles: [comment_work_package_role])++ share_modal.close+ share_modal.expect_closed+ click_button 'Share'+ share_modal.expect_open++ share_modal.expect_shared_count_of(3)+ share_modal.expect_select_all_available++ share_modal.remove_user(richard)+ share_modal.expect_not_shared_with(richard)+ share_modal.remove_user(dinesh)+ share_modal.expect_not_shared_with(dinesh)++ share_modal.expect_shared_count_of(1)+ share_modal.expect_select_all_not_available+ share_modal.expect_bulk_actions_not_available++ share_modal.invite_user(richard, 'View')+ share_modal.expect_shared_with(richard, 'View')+ share_modal.expect_shared_count_of(2)++ share_modal.expect_select_all_available+ end+ end+ end++ context 'without share permission' do+ current_user { viewer }++ it 'does not allow bulk sharing' do+ work_package_page.visit!++ click_button 'Share'+ share_modal.expect_open++ share_modal.expect_shared_count_of(3)+ share_modal.expect_shared_with(richard, editable: false)+ share_modal.expect_shared_with(dinesh, editable: false)+ share_modal.expect_shared_with(gilfoyle, editable: false)++ share_modal.expect_select_all_not_available+ share_modal.expect_bulk_actions_not_available+ share_modal.expect_not_selectable(richard, dinesh, gilfoyle)endendenddiff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rbindex 697a38482d8..11a0436d307 100644--- a/spec/support/components/work_packages/share_modal.rb+++ b/spec/support/components/work_packages/share_modal.rb@@ -61,6 +61,14 @@ module Componentsendend+ def expect_not_selectable(*principals)+ principals.each do |principal|+ within user_row(principal) do+ expect(page).not_to have_field(principal.name)+ end+ end+ end+def toggle_select_allwithin shares_header doif page.find_field('toggle_all').checked?@@ -92,6 +100,16 @@ module Components.to have_text("#{count} selected")end+ def expect_select_all_available+ expect(shares_header)+ .to have_field('toggle_all')+ end++ def expect_select_all_not_available+ expect(shares_header)+ .not_to have_field('toggle_all', wait: 0)+ end+def expect_select_all_toggledwithin shares_header doexpect(page).to have_checked_field('toggle_all')@@ -104,12 +122,42 @@ module Componentsendend+ def expect_bulk_actions_available+ within shares_header do+ expect(page).to have_button 'Remove'+ expect(page).to have_test_selector('op-share-wp-bulk-update-role')+ end+ end++ def expect_bulk_actions_not_available+ within shares_header do+ expect(page).not_to have_button 'Remove'+ expect(page).not_to have_test_selector('op-share-wp-bulk-update-role')+ end+ end+def bulk_removewithin shares_header doclick_button 'Remove'endend+ def bulk_update(role_name)+ within shares_header do+ find('[data-test-selector="op-share-wp-bulk-update-role"]').click++ find('.ActionListContent', text: role_name).click+ end+ end++ def expect_bulk_update_label(label_text)+ within shares_header do+ expect(page)+ .to have_css('[data-test-selector="op-share-wp-bulk-update-role"] .Button-label',+ text: label_text)+ end+ end+def expect_blankslatewithin_modal doexpect(page).to have_text(I18n.t('work_package.sharing.text_empty_state_description'))