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
Use Strategy in all components
Klaus Zanders2c9a97554440
diff --git a/app/components/shares/bulk_permission_button_component.rb b/app/components/shares/bulk_permission_button_component.rbindex f9a89e18673..b42c5de1dad 100644--- a/app/components/shares/bulk_permission_button_component.rb+++ b/app/components/shares/bulk_permission_button_component.rb@@ -30,11 +30,11 @@module Sharesclass BulkPermissionButtonComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent- def initialize(entity:, available_roles:)+ def initialize(strategy:)super- @entity = entity- @available_roles = available_roles+ @entity = strategy.entity+ @available_roles = strategy.available_rolesenddef update_pathdiff --git a/app/components/shares/counter_component.html.erb b/app/components/shares/counter_component.html.erbindex e9281848a58..2e58b8d310d 100644--- a/app/components/shares/counter_component.html.erb+++ b/app/components/shares/counter_component.html.erb@@ -4,7 +4,7 @@# 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?+ if strategy.manageable? && shared_with_anyone_else_other_than_myself?render(Shares::BulkSelectionCounterComponent.new(count:))elserender(Shares::ShareCounterComponent.new(count:))diff --git a/app/components/shares/counter_component.rb b/app/components/shares/counter_component.rbindex 145ee3b8c53..c2581bfb5db 100644--- a/app/components/shares/counter_component.rb+++ b/app/components/shares/counter_component.rb@@ -34,26 +34,22 @@ module Sharesinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(entity:,- count:,- sharing_manageable:)+ def initialize(strategy:, count:)super- @entity = entity+ @strategy = strategy+ @entity = strategy.entity@count = count- @sharing_manageable = sharing_manageableendprivate- attr_reader :entity, :count-- def sharing_manageable? = @sharing_manageable+ attr_reader :entity, :count, :strategydef shared_with_anyone_else_other_than_myself?Member.of_entity(@entity).where.not(principal: User.current)- .any?+ .exists?endendenddiff --git a/app/components/shares/modal_body_component.html.erb b/app/components/shares/modal_body_component.html.erbindex 05cde3aef1d..789054fb45f 100644--- a/app/components/shares/modal_body_component.html.erb+++ b/app/components/shares/modal_body_component.html.erb@@ -2,7 +2,7 @@component_wrapper(tag: 'turbo-frame') doflex_layout(data: { turbo: true }) do |modal_content|modal_content.with_row do- render(Shares::InviteUserFormComponent.new(strategy: strategy, errors: errors))+ render(Shares::InviteUserFormComponent.new(strategy:, errors: errors))endmodal_content.with_row(mt: 3,@@ -13,9 +13,7 @@border_box.with_header(color: :muted, data: { 'test-selector': 'op-share-dialog-header' }) dogrid_layout('op-share-dialog-modal-body--header', tag: :div, align_items: :center) do |header_grid|header_grid.with_area(:counter, tag: :div) do- render(Shares::CounterComponent.new(entity: @entity,- count: @shares.size,- sharing_manageable: @sharing_manageable))+ render(Shares::CounterComponent.new(strategy:, count: @shares.size))endheader_grid.with_area(:actions,@@ -57,7 +55,7 @@button.with_trailing_action_icon(icon: "triangle-down")I18n.t('sharing.filter.role')end- @available_roles.each do |role_hash|+ strategy.available_roles.each do |role_hash|menu.with_item(label: role_hash[:label],href: filter_url(role_option: role_hash),method: :get,@@ -74,13 +72,11 @@tag: :div,hidden: true, # Prevent flicker on initial renderdata: { 'shares--bulk-selection-target': 'bulkActions' }) do- if @sharing_manageable- concat(- render(Shares::BulkPermissionButtonComponent.new(entity: @entity, available_roles: @available_roles))- )+ if strategy.manageable?+ concat(render(Shares::BulkPermissionButtonComponent.new(strategy:)))concat(- form_with(url: url_for([:bulk, @entity, Member]),+ form_with(url: url_for([:bulk, entity, Member]),method: :delete,data: { 'shares--bulk-selection-target': 'bulkForm' }) dorender(Primer::Beta::IconButton.new(icon: "trash",@@ -95,7 +91,7 @@endend- if @shares.blank?+ if @shares.none?border_box.with_row dorender(Primer::Beta::Blankslate.new) do |component|component.with_visual_icon(icon: blankslate_config[:icon], size: :medium)@@ -111,10 +107,7 @@endelse@shares.each do |share|- render(Shares::ShareRowComponent.new(share: share,- available_roles: @available_roles,- sharing_manageable: @sharing_manageable,- container: border_box))+ render(Shares::ShareRowComponent.new(share:, strategy:, container: border_box))endendenddiff --git a/app/components/shares/modal_body_component.rb b/app/components/shares/modal_body_component.rbindex 82755950de6..de3a761b140 100644--- a/app/components/shares/modal_body_component.rb+++ b/app/components/shares/modal_body_component.rb@@ -36,8 +36,6 @@ module Sharesattr_reader :strategy,:entity,:shares,- :available_roles,- :sharing_manageable,:errorsdef initialize(strategy:, shares:, errors: nil)@@ -46,8 +44,6 @@ module Shares@strategy = strategy@entity = strategy.entity@shares = shares- @available_roles = strategy.available_roles- @sharing_manageable = strategy.manageable?@errors = errorsend@@ -104,15 +100,15 @@ module Sharesendend- def type_filter_option_active?(option)+ def type_filter_option_active?(option) # rubocop:disable Metrics/AbcSizeprincipal_type_filter_value = current_filter_value(params[:filters], "principal_type")project_member_filter_value = current_filter_value(params[:filters], "also_project_member")- return false if principal_type_filter_value.nil? || project_member_filter_value.nil?+ return false if principal_type_filter_value.nil? || (project_scoped_entity? && project_member_filter_value.nil?)principal_type_checked =option[:value][:principal_type] == principal_type_filter_value- membership_selected =+ membership_selected = !project_scoped_entity? ||option[:value][:project_member] == ActiveRecord::Type::Boolean.new.cast(project_member_filter_value)principal_type_checked && membership_selected@@ -123,7 +119,7 @@ module Sharesreturn false if role_filter_value.nil?- selected_role = @available_roles.find { _1[:value] == option[:value] }+ selected_role = strategy.available_roles.find { _1[:value] == option[:value] }selected_role[:value] == role_filter_value.to_iend@@ -181,14 +177,18 @@ module Sharesenddef 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] } })+ filter = [+ { principal_type: { operator: "=", values: [option[:value][:principal_type]] } }+ ]++ if project_scoped_entity?+ 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] } })+ endend- filter.push({ principal_type: { operator: "=", values: [option[:value][:principal_type]] } })filterenddiff --git a/app/components/shares/share_row_component.rb b/app/components/shares/share_row_component.rbindex 8f9a1dd6e53..b047f143529 100644--- a/app/components/shares/share_row_component.rb+++ b/app/components/shares/share_row_component.rb@@ -34,17 +34,14 @@ module Sharesinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(share:,- available_roles:,- sharing_manageable:,- container: nil)+ def initialize(share:, strategy:, container: nil)super+ @strategy = strategy@share = share- @entity = share.entity+ @entity = strategy.entity@principal = share.principal- @available_roles = available_roles- @sharing_manageable = sharing_manageable+ @available_roles = strategy.available_roles@container = containerend@@ -54,13 +51,15 @@ module Sharesprivate- attr_reader :share, :entity, :principal, :container, :available_roles+ attr_reader :share, :entity, :principal, :container, :available_roles, :strategydef share_editable?@share_editable ||= User.current != share.principal && sharing_manageable?end- def sharing_manageable? = @sharing_manageable+ def sharing_manageable?+ strategy.manageable?+ enddef grid_css_classesif sharing_manageable?diff --git a/app/models/members/scopes/of_entity.rb b/app/models/members/scopes/of_entity.rbindex b9178a06045..b8413a4d7bd 100644--- a/app/models/members/scopes/of_entity.rb+++ b/app/models/members/scopes/of_entity.rb@@ -33,8 +33,11 @@ module Members::Scopesclass_methods do# Find all members of a specific Work Packagedef of_entity(entity)- of_any_entity- .where(entity:)+ if entity.respond_to?(:project)+ where(project: entity.project, entity:)+ else+ where(project: nil, entity:)+ endendendend