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
Kepp currently selected role filter when filtering the type (and the other way around). Further, the test has been adapted to it.
Henriette Darge5f5eacf75540
diff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erbindex 95336057902..c7de0443bff 100644--- a/app/components/work_packages/share/modal_body_component.html.erb+++ b/app/components/work_packages/share/modal_body_component.html.erb@@ -5,7 +5,7 @@render(WorkPackages::Share::InviteUserFormComponent.new(work_package: @work_package))end- if @shared_principals.none?+ if @shares.none?modal_content.with_row(mt: 3) dorender(Primer::Beta::Blankslate.new(border: true)) do |component|component.with_visual_icon(icon: :people, size: :medium)@@ -28,7 +28,7 @@border_box.with_header(color: :subtle, pt: 2, pb: 2, data: { 'test-selector': 'op-share-wp-header' }) dogrid_layout('op-share-wp-modal-body--header', tag: :div, align_items: :center) do |header_grid|header_grid.with_area(:counter, tag: :div) do- render(WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: @shared_principals.size))+ render(WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: @shares.size))endheader_grid.with_area(:actions,@@ -98,7 +98,7 @@endend- @shared_principals.each do |principal|+ @shares.each do |principal|render(WorkPackages::Share::ShareRowComponent.new(share: principal, container: border_box))endenddiff --git a/app/components/work_packages/share/modal_body_component.rb b/app/components/work_packages/share/modal_body_component.rbindex d9c4145a696..ee41091d349 100644--- a/app/components/work_packages/share/modal_body_component.rb+++ b/app/components/work_packages/share/modal_body_component.rb@@ -40,7 +40,7 @@ module WorkPackagessuper@work_package = work_package- @shared_principals = shares+ @shares = sharesenddef self.wrapper_key@@ -112,28 +112,65 @@ module WorkPackagesenddef filter_url(type_option: nil, role_option: nil)+ return work_package_shares_path if type_option.nil? && role_option.nil?+args = {}filter = []- unless type_option.nil? || type_filter_option_active?(type_option)- if type_option[:value][:project_member]- filter.push({ also_project_member: { operator: "=", values: [OpenProject::Database::DB_VALUE_TRUE] } })- else- filter.push({ also_project_member: { operator: "=", values: [OpenProject::Database::DB_VALUE_FALSE] } })- end+ filter += apply_role_filter(role_option)+ filter += apply_type_filter(type_option)++ args[:filters] = filter.to_json unless filter.empty?++ work_package_shares_path(args)+ end++ def apply_role_filter(_option)+ current_role_filter_value = current_filter_value(params[:filters], 'role_id')+ filter = []- filter.push({ principal_type: { operator: "=", values: [type_option[:value][:principal_type]] } })+ if _option.nil? && current_role_filter_value.present?+ # When there is already a role filter set and no new value passed, we want to keep that filter+ filter = role_filter_for({ value: current_role_filter_value }, builtin_role: false)+ elsif _option.present? && !role_filter_option_active?(_option)+ # Only when the passed filter option is not the currently selected one, we apply the filter+ filter = role_filter_for(_option)end- unless role_option.nil? || role_filter_option_active?(role_option)- filter.push({ role_id: { operator: "=", values: find_role_ids(role_option[:value]) } })+ filter+ end++ def role_filter_for(_option, builtin_role: true)+ [{ role_id: { operator: "=", values: builtin_role ? find_role_ids(_option[:value]) : [_option[:value]] } }]+ end++ def apply_type_filter(_option)+ current_type_filter_value = current_filter_value(params[:filters], 'principal_type')+ current_member_filter_value = current_filter_value(params[:filters], 'also_project_member')+ filter = []++ if _option.nil? && current_type_filter_value.present? && current_member_filter_value.present?+ # When there is already a type filter set and no new value passed, we want to keep that filter+ value = { value: { principal_type: current_type_filter_value, project_member: current_member_filter_value } }+ filter = type_filter_for(value)+ elsif _option.present? && !type_filter_option_active?(_option)+ # Only when the passed filter option is not the currently selected one, we apply the filter+ filter = type_filter_for(_option)end- # Todo: Keep options of the other filter defined in params+ filter+ end- args[:filters] = filter.to_json unless filter.empty?+ def type_filter_for(_option)+ filter = []+ if ActiveRecord::Type::Boolean.new.cast(_option[:value][:project_member])+ filter.push({ also_project_member: { operator: "=", values: [OpenProject::Database::DB_VALUE_TRUE] } })+ else+ filter.push({ also_project_member: { operator: "=", values: [OpenProject::Database::DB_VALUE_FALSE] } })+ end- work_package_shares_path(args)+ filter.push({ principal_type: { operator: "=", values: [_option[:value][:principal_type]] } })+ filterenddef current_filter_value(filters, filter_key)diff --git a/spec/features/work_packages/share/filter_spec.rb b/spec/features/work_packages/share/filter_spec.rbindex 2ab0b789f99..253d3f5470e 100644--- a/spec/features/work_packages/share/filter_spec.rb+++ b/spec/features/work_packages/share/filter_spec.rb@@ -40,11 +40,11 @@ RSpec.describe 'Work package sharing',shared_let(:project_user) { create(:user, firstname: 'Anton') }shared_let(:project_user2) { create(:user, firstname: 'Bertha') }- shared_let(:non_project_user) { create(:user, firstname: 'Caesar') }- shared_let(:non_project_user2) { create(:user, firstname: 'Dora') }+ shared_let(:inherited_project_user) { create(:user, firstname: 'Caesar') }+ shared_let(:non_project_user) { create(:user, firstname: 'Dora') }- shared_let(:shared_project_group) { create(:group, members: [project_user, non_project_user]) }- shared_let(:shared_non_project_group) { create(:group, members: [project_user2, non_project_user2]) }+ shared_let(:shared_project_group) { create(:group, members: [project_user, inherited_project_user]) }+ shared_let(:shared_non_project_group) { create(:group, members: [project_user2, non_project_user]) }let(:project) docreate(:project,@@ -64,9 +64,9 @@ RSpec.describe 'Work package sharing',create(:work_package, project:) do |wp|create(:work_package_member, entity: wp, user: project_user, roles: [view_work_package_role])create(:work_package_member, entity: wp, user: project_user2, roles: [comment_work_package_role])+ create(:work_package_member, entity: wp, user: inherited_project_user, roles: [edit_work_package_role])create(:work_package_member, entity: wp, user: non_project_user, roles: [edit_work_package_role])- create(:work_package_member, entity: wp, user: non_project_user2, roles: [edit_work_package_role])- create(:work_package_member, entity: wp, user: shared_project_group, roles: [view_work_package_role])+ create(:work_package_member, entity: wp, user: shared_project_group, roles: [edit_work_package_role])create(:work_package_member, entity: wp, user: shared_non_project_group, roles: [view_work_package_role])endend@@ -88,21 +88,22 @@ RSpec.describe 'Work package sharing',# Filter for: project members (users only)share_modal.filter('type', I18n.t('work_package.sharing.filter.project_member'))- share_modal.expect_shared_count_of(2)+ share_modal.expect_shared_count_of(3)share_modal.expect_shared_with(project_user, 'View')share_modal.expect_shared_with(project_user2, 'Comment')+ # The non-project user is listed because it is part of the project group and thus the membership is inherited.+ share_modal.expect_shared_with(inherited_project_user, 'Edit')share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)share_modal.expect_not_shared_with(shared_project_group)share_modal.expect_not_shared_with(shared_non_project_group)# Filter for: non-project members (users only)share_modal.filter('type', I18n.t('work_package.sharing.filter.not_project_member'))- share_modal.expect_shared_count_of(2)+ share_modal.expect_shared_count_of(1)share_modal.expect_shared_with(non_project_user, 'Edit')- share_modal.expect_shared_with(non_project_user2, 'Edit')+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(project_user)share_modal.expect_not_shared_with(project_user2)share_modal.expect_not_shared_with(shared_project_group)@@ -112,11 +113,11 @@ RSpec.describe 'Work package sharing',share_modal.filter('type', I18n.t('work_package.sharing.filter.project_group'))share_modal.expect_shared_count_of(1)- share_modal.expect_shared_with(shared_project_group, 'View')+ share_modal.expect_shared_with(shared_project_group, 'Edit')share_modal.expect_not_shared_with(project_user)share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)share_modal.expect_not_shared_with(shared_non_project_group)# Filter for: non-project members (groups only)@@ -126,8 +127,8 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(shared_non_project_group, 'View')share_modal.expect_not_shared_with(project_user)share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)share_modal.expect_not_shared_with(shared_project_group)# Clicking again on the filter will reset it@@ -136,9 +137,9 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(project_user, 'View')share_modal.expect_shared_with(project_user2, 'Comment')+ share_modal.expect_shared_with(inherited_project_user, 'Edit')share_modal.expect_shared_with(non_project_user, 'Edit')- share_modal.expect_shared_with(non_project_user2, 'Edit')- share_modal.expect_shared_with(shared_project_group, 'View')+ share_modal.expect_shared_with(shared_project_group, 'Edit')share_modal.expect_shared_with(shared_non_project_group, 'View')end@@ -148,25 +149,25 @@ RSpec.describe 'Work package sharing',# Filter for: all principals with Edit permissionshare_modal.filter('role', I18n.t('work_package.sharing.permissions.edit'))- share_modal.expect_shared_count_of(2)+ share_modal.expect_shared_count_of(3)+ share_modal.expect_shared_with(inherited_project_user, 'Edit')share_modal.expect_shared_with(non_project_user, 'Edit')- share_modal.expect_shared_with(non_project_user2, 'Edit')+ share_modal.expect_shared_with(shared_project_group, 'Edit')share_modal.expect_not_shared_with(project_user)share_modal.expect_not_shared_with(project_user2)- share_modal.expect_not_shared_with(shared_project_group)share_modal.expect_not_shared_with(shared_non_project_group)# Filter for: all principals with View permissionshare_modal.filter('role', I18n.t('work_package.sharing.permissions.view'))- share_modal.expect_shared_count_of(3)+ share_modal.expect_shared_count_of(2)share_modal.expect_shared_with(project_user, 'View')- share_modal.expect_shared_with(shared_project_group, 'View')share_modal.expect_shared_with(shared_non_project_group, 'View')share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)+ share_modal.expect_not_shared_with(shared_project_group)# Filter for: all principals with Comment permissionshare_modal.filter('role', I18n.t('work_package.sharing.permissions.comment'))@@ -174,8 +175,8 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(project_user2, 'Comment')share_modal.expect_not_shared_with(project_user)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)share_modal.expect_not_shared_with(shared_project_group)share_modal.expect_not_shared_with(shared_non_project_group)@@ -185,9 +186,9 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(project_user, 'View')share_modal.expect_shared_with(project_user2, 'Comment')+ share_modal.expect_shared_with(inherited_project_user, 'Edit')share_modal.expect_shared_with(non_project_user, 'Edit')- share_modal.expect_shared_with(non_project_user2, 'Edit')- share_modal.expect_shared_with(shared_project_group, 'View')+ share_modal.expect_shared_with(shared_project_group, 'Edit')share_modal.expect_shared_with(shared_non_project_group, 'View')end@@ -199,14 +200,16 @@ RSpec.describe 'Work package sharing',# role: view# type: noneshare_modal.filter('role', I18n.t('work_package.sharing.permissions.view'))- share_modal.expect_shared_count_of(3)+ share_modal.expect_shared_count_of(2)share_modal.expect_shared_with(project_user, 'View')- share_modal.expect_shared_with(shared_project_group, 'View')share_modal.expect_shared_with(shared_non_project_group, 'View')share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)+ share_modal.expect_not_shared_with(shared_project_group)++ sleep 1# Additional filter for: project members (users only)# role: view@@ -216,48 +219,54 @@ RSpec.describe 'Work package sharing',share_modal.expect_shared_with(project_user, 'View')share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)share_modal.expect_not_shared_with(shared_project_group)share_modal.expect_not_shared_with(shared_non_project_group)+ sleep 1+# Change type filter to: project members (groups only)# role: view- # type: project members (groups only)- share_modal.filter('type', I18n.t('work_package.sharing.filter.project_member'))+ # type: non-project members (groups only)+ share_modal.filter('type', I18n.t('work_package.sharing.filter.not_project_group'))share_modal.expect_shared_count_of(1)- share_modal.expect_shared_with(shared_project_group, 'View')+ share_modal.expect_shared_with(shared_non_project_group, 'View')share_modal.expect_not_shared_with(project_user)share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)- share_modal.expect_not_shared_with(shared_non_project_group)+ share_modal.expect_not_shared_with(shared_project_group)++ sleep 1# Reset role filter# role: none- # type: project members (groups only)+ # type: non-project members (groups only)share_modal.filter('role', I18n.t('work_package.sharing.permissions.view'))share_modal.expect_shared_count_of(1)- share_modal.expect_shared_with(shared_project_group, 'View')+ share_modal.expect_shared_with(shared_non_project_group, 'View')share_modal.expect_not_shared_with(project_user)share_modal.expect_not_shared_with(project_user2)+ share_modal.expect_not_shared_with(inherited_project_user)share_modal.expect_not_shared_with(non_project_user)- share_modal.expect_not_shared_with(non_project_user2)- share_modal.expect_not_shared_with(shared_non_project_group)+ share_modal.expect_not_shared_with(shared_project_group)++ sleep 1# Reset type filter# role: none# type: none- share_modal.filter('type', I18n.t('work_package.sharing.filter.project_member'))+ share_modal.filter('type', I18n.t('work_package.sharing.filter.not_project_group'))share_modal.expect_shared_count_of(6)share_modal.expect_shared_with(project_user, 'View')share_modal.expect_shared_with(project_user2, 'Comment')+ share_modal.expect_shared_with(inherited_project_user, 'Edit')share_modal.expect_shared_with(non_project_user, 'Edit')- share_modal.expect_shared_with(non_project_user2, 'Edit')- share_modal.expect_shared_with(shared_project_group, 'View')+ share_modal.expect_shared_with(shared_project_group, 'Edit')share_modal.expect_shared_with(shared_non_project_group, 'View')endend