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

Ensure selected Bulk Update Permission matches current selection mix

Aaron Contreras836363006653
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.erb
index 00ba386d711..8a706b4cb4c 100644
--- a/app/components/work_packages/share/bulk_permission_button_component.html.erb
+++ b/app/components/work_packages/share/bulk_permission_button_component.html.erb
@@ -4,7 +4,7 @@
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|
+ menu.with_show_button(data: { 'work-packages--share--bulk-selection-target': 'bulkUpdateRoleLabel' }) do |button|
button.with_trailing_action_icon(icon: "triangle-down")
'Placeholder'
end
@@ -18,7 +18,9 @@
method: :patch,
name: 'role_ids[]',
value: option[:value],
- data: { 'work-packages--share--bulk-selection-target': 'bulkForm' }
+ data: { 'work-packages--share--bulk-selection-target': 'bulkForm bulkUpdateRoleForm',
+ 'role-name': option[:label],
+ 'test-selector': "op-share-wp-bulk-update-role-permission-#{option[:label]}" }
}) do |item|
item.with_description.with_content(option[:description])
end
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.ts
index b982794638c..dc5ea28be21 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
@@ -46,7 +46,8 @@ export default class BulkSelectionController extends Controller {
'bulkForm',
'hiddenShare',
'userRowRole',
- 'bulkUpdateRole',
+ 'bulkUpdateRoleLabel',
+ 'bulkUpdateRoleForm',
];
// Checkboxes
@@ -59,12 +60,14 @@ export default class BulkSelectionController extends Controller {
// Bulk Forms
declare readonly bulkFormTargets:HTMLFormElement[];
+ // Specific target for bulk update permission forms
+ declare readonly bulkUpdateRoleFormTargets:HTMLFormElement[];
declare readonly hiddenShareTargets:HTMLInputElement[];
declare readonly actionsTarget:HTMLElement;
// Permission Buttons
declare readonly userRowRoleTargets:HTMLButtonElement[];
- declare readonly bulkUpdateRoleTarget:HTMLButtonElement;
+ declare readonly bulkUpdateRoleLabelTarget:HTMLButtonElement;
// Refresh when a user is invited
shareCheckboxTargetConnected() {
@@ -91,11 +94,15 @@ export default class BulkSelectionController extends Controller {
// as the updated share might have been selected and the label
// may no longer be correct
userRowRoleTargetConnected() {
+ if (this.checked.length === 0) {
+ return;
+ }
+
this.updateBulkUpdateRoleLabelValue();
}
bulkUpdateRoleLabelValueChanged(current:string, _old:string) {
- const label = this.bulkUpdateRoleTarget.querySelector('.Button-label') as HTMLElement;
+ const label = this.bulkUpdateRoleLabelTarget.querySelector('.Button-label') as HTMLElement;
label.textContent = current;
}
@@ -122,9 +129,9 @@ export default class BulkSelectionController extends Controller {
this.actionsTarget.setAttribute('hidden', 'true');
} else {
this.actionsTarget.removeAttribute('hidden');
+ this.updateBulkUpdateRoleLabelValue();
}
- this.updateBulkUpdateRoleLabelValue();
this.updateCounter();
}
@@ -138,8 +145,14 @@ export default class BulkSelectionController extends Controller {
private updateBulkUpdateRoleLabelValue() {
if (new Set(this.selectedPermissions).size > 1) {
this.bulkUpdateRoleLabelValue = I18n.t('js.work_packages.sharing.selection.mixed');
+ this.bulkPermissionButtons.forEach((button) => button.setAttribute('aria-checked', 'false'));
} else {
this.bulkUpdateRoleLabelValue = this.selectedPermissions[0];
+ const bulkUpdateRoleForm = this.bulkUpdateRoleFormTargets.find((form) => {
+ return form.getAttribute('data-role-name') === this.bulkUpdateRoleLabelValue.trim();
+ }) as HTMLFormElement;
+ const button = bulkUpdateRoleForm.querySelector('button[type=submit]') as HTMLButtonElement;
+ button.setAttribute('aria-checked', 'true');
}
}
@@ -186,6 +199,12 @@ export default class BulkSelectionController extends Controller {
});
}
+ private get bulkPermissionButtons():HTMLButtonElement[] {
+ return this.bulkUpdateRoleFormTargets.map((bulkUpdateForm) => {
+ return bulkUpdateForm.querySelector('button[type=submit]') as HTMLButtonElement;
+ });
+ }
+
private get selectedPermissions() {
return this.selectedRoleButtons.map((button) => {
const label = button.querySelector('.Button-label') as HTMLElement;
diff --git a/spec/support/components/work_packages/share_modal.rb b/spec/support/components/work_packages/share_modal.rb
index 11a0436d307..0101d9fdcd6 100644
--- a/spec/support/components/work_packages/share_modal.rb
+++ b/spec/support/components/work_packages/share_modal.rb
@@ -155,9 +155,34 @@ module Components
expect(page)
.to have_css('[data-test-selector="op-share-wp-bulk-update-role"] .Button-label',
text: label_text)
+ if label_text == 'Mixed'
+ %w[View Comment Edit].each do |permission_name|
+ within bulk_update_form(permission_name) do
+ expect(page)
+ .to have_css(unchecked_permission, visible: :all)
+ end
+ end
+ else
+ within bulk_update_form(label_text) do
+ expect(page)
+ .to have_css(checked_permission, visible: :all)
+ end
+ end
end
end
+ def bulk_update_form(permission_name)
+ find("[data-test-selector='op-share-wp-bulk-update-role-permission-#{permission_name}']", visible: :all)
+ end
+
+ def checked_permission
+ 'button[type=submit][aria-checked=true]'
+ end
+
+ def unchecked_permission
+ 'button[type=submit][aria-checked="false"]'
+ end
+
def expect_blankslate
within_modal do
expect(page).to have_text(I18n.t('work_package.sharing.text_empty_state_description'))